diff --git a/src/distroquery.c b/src/distroquery.c index 302a51e..4622127 100644 --- a/src/distroquery.c +++ b/src/distroquery.c @@ -107,8 +107,8 @@ void printQueryData(char* repository_tag, char* query) { snprintf(dbname, PATH_MAX, "%sdistromatic.db", configtag->repository[i]->repository_dir); if (sqlite3_open_v2(dbname, (sqlite3**)&configtag->repository[i]->db, SQLITE_OPEN_READONLY, NULL)) { if (configtag->repository[i]->db) sqlite3_close(configtag->repository[i]->db); + configtag->repository[i]->db = NULL; fprintf(stderr, "ERROR: unable to open sqlite3 db %s; aborting.\n", dbname); - return; } } @@ -117,16 +117,20 @@ void printQueryData(char* repository_tag, char* query) { int j; printf("Binaries:"); int a; for (a = 0; a < ARCHS_MAX && configtag->arch[a]; a++) { snprintf(sql, PATH_MAX, "SELECT * FROM packages_%s WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%'", configtag->arch[a], query, query, query); for (i = 0; i <= configtag->repository_level; i++) { - if (sqlite3_prepare_v2((sqlite3*)configtag->repository[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK) { + if (configtag->repository[i]->db && + (sqlite3_prepare_v2((sqlite3*)configtag->repository[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { while (sqlite3_step(statement) == SQLITE_ROW) { - printf("%s %s:%s-%s
%s
Group: %s

%s

", + printf("

%s
 " + "
%s

" + "%s %s-%s
%s
Group: %s

" + "
%s

", + configtag->arch[a], + configtag->repository[i]->tag, sqlite3_column_text(statement,1), - sqlite3_column_text(statement,3), sqlite3_column_text(statement,4), sqlite3_column_text(statement,5), sqlite3_column_text(statement,6), @@ -138,14 +142,17 @@ void printQueryData(char* repository_tag, char* query) { } } - printf("

Sources:

"); snprintf(sql, PATH_MAX, "SELECT * FROM sources WHERE name LIKE '%%%s%%' OR summary LIKE '%%%s%%' OR description LIKE '%%%s%%'", query, query, query); for (i = 0; i <= configtag->repository_level; i++) { - if (sqlite3_prepare_v2((sqlite3*)configtag->repository[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK) { + if (configtag->repository[i]->db && + (sqlite3_prepare_v2((sqlite3*)configtag->repository[i]->db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { while (sqlite3_step(statement) == SQLITE_ROW) { - printf("%s %s:%s-%s
%s
Group: %s
License: %s
URL: %s

%s

", + printf("

Source
 " + "
%s

" + "%s %s-%s
%s
Group: %s
License: %s
URL: %s

" + "
%s

", + configtag->repository[i]->tag, sqlite3_column_text(statement,1), - sqlite3_column_text(statement,3), sqlite3_column_text(statement,4), sqlite3_column_text(statement,5), sqlite3_column_text(statement,6),