distroquery: add 'required by' entries in package page

This commit is contained in:
Silvan Calarco 2013-10-20 01:03:47 +02:00
parent 95d368a12a
commit 80dfdb190c

View File

@ -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><![CDATA[", reply_xmltag);
int query_arch_num = find_query_arch(query_arch);
snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->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);
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><![CDATA[", reply_xmltag);
snprintf(sql, PATH_MAX, "SELECT * FROM packages WHERE name = '%s'", query_package);
if (db &&
(sqlite3_prepare_v2(db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) {
@ -704,6 +716,7 @@ void printPackageData() {
printf("<br>%s: %s", _("Build date"),
simpleTimeToHuman(sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildtime")), (humanDate *) & strdate));
/* obsoletes */
printf("<br><br>%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("<br><br>%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("<br><br>%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("<br><br>%s %s %s:",_("Required in"),ct->repository[i]->tag,_("by"));
printf(" <a href=#reply onclick='distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s</a>",
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)) {