distroquery: search all repositories in same milestone for required by and buildrequired by sections

This commit is contained in:
Silvan Calarco 2013-10-22 17:37:37 +02:00
parent 7eb2118595
commit 43fb6825f8

View File

@ -250,6 +250,39 @@ void attachCtDatabases(struct configTag* ct, sqlite3 *db, char* arch) {
}
}
void attachRepositoryDatabases(struct configTag* ct, sqlite3 *db, char* arch) {
char dbname[PATH_MAX];
char sql[PATH_MAX];
char *errmsg;
snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->repository_dir, ct->tag, arch);
snprintf(sql, PATH_MAX, "ATTACH DATABASE '%s' as '%s'", dbname, ct->tag);
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
}
fprintf(stderr,"ATTACHED DATABASE %s\n", ct->tag);
snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag);
snprintf(sql, PATH_MAX, "ATTACH DATABASE '%s' as '%s_sources'", dbname, ct->tag);
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
}
fprintf(stderr,"ATTACHED DATABASE %s_sources\n", ct->tag);
}
void detachRepositoryDatabases(struct configTag* ct, sqlite3 *db, char* arch) {
char sql[PATH_MAX];
char *errmsg;
snprintf(sql, PATH_MAX, "DETACH DATABASE '%s'", ct->tag);
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
}
snprintf(sql, PATH_MAX, "DETACH DATABASE '%s_sources'", ct->tag);
if (sqlite3_exec(db, sql, NULL, NULL, &errmsg)) {
fprintf(stderr, "ERROR: unable to exec statement for %s: %s\n", sql, errmsg);
}
}
void printInputForm() {
struct configTag *ct = firstconfigtag;
@ -773,7 +806,6 @@ void printQueryResponse() {
}
}
void printPackageData() {
int i, j;
@ -786,6 +818,8 @@ void printPackageData() {
humanDate strdate;
sizeString strsize;
FILE *file;
int package_id;
char *package_name = NULL, *package_summary = NULL;
snprintf(dbname, PATH_MAX, "%s%s-%s.db", ct->repository_dir, ct->tag, query_arch);
if (sqlite3_open_v2(dbname, (sqlite3**)&db, SQLITE_OPEN_READONLY, NULL)) {
@ -794,14 +828,17 @@ void printPackageData() {
return;
}
attachCtDatabases(ct, db, query_arch);
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)) {
if (sqlite3_step(statement) == SQLITE_ROW) {
package_id = sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"));
package_name = strdup((const char*)sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")));
package_summary = strdup((const char*)sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")));
snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag);
if (sqlite3_open_v2(dbname, &dbs, SQLITE_OPEN_READONLY, NULL)) {
if (dbs) sqlite3_close(dbs);
@ -943,9 +980,10 @@ void printPackageData() {
sqlite3_finalize(stmt1);
}
sqlite3_finalize(statement); /* need to finalize all statements before detaching databases */
/* required by */
i=0;
while (ct->repository[i]) {
for (i = 0; query_repositories[i] != NULL; i++) {
attachRepositoryDatabases(query_repositories[i], db, query_arch);
snprintf(sql, PATH_MAX,
"SELECT packagesup.name AS requiredbyname, "
"requiresup.requireflags AS requiredflags, "
@ -959,14 +997,14 @@ void printPackageData() {
"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);
query_repositories[i]->tag, query_repositories[i]->tag, query_repositories[i]->tag,
package_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,
if (j++ == 0) printf("<br><br>%s %s %s:",_("Required in"),query_repositories[i]->tag,_("by"));
printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s&arch=%s\")'>%s</a>",
query_repositories[i]->tag,
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "requiredbyname")),
query_arch,
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "requiredbyname")));
@ -978,12 +1016,12 @@ void printPackageData() {
}
sqlite3_finalize(stmt1);
}
i++;
detachRepositoryDatabases(query_repositories[i], db, query_arch);
}
/* build required by */
i=0;
while (ct->repository[i]) {
for (i = 0; query_repositories[i] != NULL; i++) {
attachRepositoryDatabases(query_repositories[i], db, query_arch);
snprintf(sql, PATH_MAX,
"SELECT sourcesup.name as buildrequiredbyname, "
"buildrequiresup.buildrequireflags as buildrequireflags, "
@ -996,14 +1034,13 @@ void printPackageData() {
// "AND NOT packagesup.name='%s' "
// "GROUP BY packagesup.name "
"ORDER BY sourcesup.name",
ct->repository[i]->tag, ct->repository[i]->tag,
sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id")));
query_repositories[i]->tag, query_repositories[i]->tag, package_id);
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:",_("Build required in"),ct->repository[i]->tag,_("by"));
printf(" <a href=#reply onclick='distroquery_request(\"repository=%s&package=%s\")'>%s</a>",
ct->repository[i]->tag,
if (j++ == 0) printf("<br><br>%s %s %s:",_("Build required in"),query_repositories[i]->tag,_("by"));
printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s\")'>%s</a>",
query_repositories[i]->tag,
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequiredbyname")),
sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequiredbyname")));
if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequireversion"))) {
@ -1014,7 +1051,7 @@ void printPackageData() {
}
sqlite3_finalize(stmt1);
}
i++;
detachRepositoryDatabases(query_repositories[i], db, query_arch);
}
/* files list */
@ -1040,10 +1077,7 @@ void printPackageData() {
}
sqlite3_close(dbs);
}
snprintf(buffer, PATH_MAX, "%s - %s",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")),
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")));
sqlite3_finalize(statement);
snprintf(buffer, PATH_MAX, "%s - %s", package_name, package_summary);
}
if (!reply_plain) printf("]]></%s>", reply_xmltag);
if (!reply_plain) {
@ -1275,6 +1309,24 @@ void parse_request_variables(char *data) {
if (query_next[strlen(query_next)] == '&') query_next[strlen(query_next)] = '\0';
ct = firstconfigtag;
i = 0;
if (query_package) {
if (strstr(query_repository, "devel") == query_repository) {
search_devel = 1;
search_milestone2 = 0;
search_milestone1 = 0;
searchbox = 1;
} else if (strstr(query_repository, "milestone2") == query_repository) {
search_devel = 0;
search_milestone2 = 1;
search_milestone1 = 0;
searchbox = 1;
} else if (strstr(query_repository, "milestone1") == query_repository) {
search_devel = 0;
search_milestone2 = 0;
search_milestone1 = 1;
searchbox = 1;
}
}
while (ct) {
if ((strstr(ct->tag, "devel") == ct->tag) && search_devel) query_repositories[i++] = ct;
ct = ct->next;