diff --git a/src/distroquery.c b/src/distroquery.c index 2c2fc0f..cba17ba 100644 --- a/src/distroquery.c +++ b/src/distroquery.c @@ -597,21 +597,33 @@ void printPackageData() { sqlite3_stmt *statement, *stmt1, *stmt2; char sql[PATH_MAX]; char buffer[PATH_MAX]; + char *errmsg; struct configTag* ct = findRepositoryByTag(query_repository); humanDate strdate; sizeString strsize; FILE *file; - if (!reply_plain) printf("<%s>repository_dir, ct->tag, query_arch); - if (sqlite3_open_v2(dbname, &db, SQLITE_OPEN_READONLY, NULL)) { + if (sqlite3_open_v2(dbname, (sqlite3**)&db, SQLITE_OPEN_READONLY, NULL)) { if (db) sqlite3_close(db); - db = NULL; - fprintf(stderr, "ERROR: unable to open sqlite3 db %s; aborting.\n", dbname); - return; + fprintf(stderr, "ERROR: unable to open sqlite3 db %s\n", dbname); + return; } + i=0; + while (ct->repository[i]) { + snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->repository[i]->repository_dir, ct->repository[i]->tag, query_arch); + snprintf(sql, PATH_MAX, "ATTACH DATABASE '%s' as '%s'", dbname, ct->repository[i]->tag); + if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) { + fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg); + } + i++; + } + + if (!reply_plain) printf("<%s>%s: %s", _("Build date"), simpleTimeToHuman(sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildtime")), (humanDate *) & strdate)); + /* obsoletes */ printf("

%s:", _("Obsoletes")); snprintf(sql, PATH_MAX, "SELECT * FROM obsoletes WHERE id_package=%d", sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); @@ -718,6 +731,8 @@ void printPackageData() { } sqlite3_finalize(stmt1); } + + /* provides */ printf("

%s:",_("Provides")); snprintf(sql, PATH_MAX, "SELECT * FROM provides,provided " "WHERE provides.id_package=%d AND provided.id=provides.id_provided " @@ -733,6 +748,8 @@ void printPackageData() { } sqlite3_finalize(stmt1); } + + /* requires */ printf("

%s:", _("Requires")); snprintf(sql, PATH_MAX, "SELECT * FROM requires,provided " "WHERE requires.id_package=%d AND provided.id=requires.id_provided " @@ -749,6 +766,36 @@ void printPackageData() { sqlite3_finalize(stmt1); } + /* required by */ + i=0; + while (ct->repository[i]) { + snprintf(sql, PATH_MAX, + "SELECT * FROM '%s'.packages AS packagesup,'%s'.requires AS requiresup," + "'%s'.provided AS providedup,provided,provides " + "WHERE provides.id_package=%d AND provided.id=provides.id_provided " + "AND packagesup.id=requiresup.id_package " + "AND requiresup.id_provided=providedup.id " + "AND providedup.name=provided.name " + "AND NOT packagesup.name='%s' " + "GROUP BY packagesup.name " + "ORDER BY packagesup.name", + ct->repository[i]->tag, ct->repository[i]->tag, ct->repository[i]->tag, + sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")), query_package); + if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) { + j=0; + while (sqlite3_step(stmt1) == SQLITE_ROW) { + if (j++ == 0) printf("

%s %s %s:",_("Required in"),ct->repository[i]->tag,_("by")); + printf(" %s", + ct->repository[i]->tag, + sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")), + query_arch, + sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name"))); + } + sqlite3_finalize(stmt1); + } + i++; + } + /* files list */ snprintf(dbname, PATH_MAX, "%s%s-%s-files.db", ct->repository_dir, ct->tag, query_arch); if (!sqlite3_open_v2(dbname, &dbf, SQLITE_OPEN_READONLY, NULL)) {