From e41fc038c77c0fb364a91c5efc78972541674898 Mon Sep 17 00:00:00 2001 From: Silvan Calarco Date: Sun, 13 Oct 2013 02:17:31 +0200 Subject: [PATCH] sqlite-backend, distroquery: use relations to provided in requires and provides tables --- src/backend-sqlite3.c | 43 ++++++------- src/distroquery.c | 136 +++++++++++++++++++++++------------------- 2 files changed, 97 insertions(+), 82 deletions(-) diff --git a/src/backend-sqlite3.c b/src/backend-sqlite3.c index 02ea80d..1c64fb2 100644 --- a/src/backend-sqlite3.c +++ b/src/backend-sqlite3.c @@ -100,7 +100,7 @@ void SQLite_print_contents_subtree(sqlite3 *db, "name STRING, firstchild INTEGER, next INTEGER, parent INTEGER, numproviders INTEGER" /* struct headerList **provider; */ -#define SQLITE_TABLE_packages_files_rel "id INTEGER PRIMARY KEY, id_package INTEGER, id_source INTEGER" +#define SQLITE_TABLE_packages_files_rel "id INTEGER PRIMARY KEY, id_package INTEGER, id_file INTEGER" int generateSQLite_files(struct configTag* ct, sqlite3 *db, int arch) { @@ -251,10 +251,10 @@ long generateSQLite_add_changelog(sqlite3 *db, struct changeLog* firstchangelog, "id_package INTEGER, obsoletename STRING, obsoleteflags INTEGER, obsoleteversion STRING" #define SQLITE_TABLE_provides "id INTEGER PRIMARY KEY, "\ - "id_package INTEGER, providename STRING, provideflags INTEGER, provideversion STRING" + "id_package INTEGER, id_provided INTEGER, provideflags INTEGER, provideversion STRING" #define SQLITE_TABLE_requires "id INTEGER PRIMARY KEY, "\ - "id_package INTEGER, requirename STRING, requireflags INTEGER, requireversion STRING" + "id_package INTEGER, id_provided STRING, requireflags INTEGER, requireversion STRING" int generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) { @@ -314,15 +314,15 @@ generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) { /* provides */ for (i = 0; i < currpackage->providecount; i++) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provides VALUES(NULL,%d,?,%d,?);", + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provides VALUES(NULL,%d,%d,%d,?);", currpackage->id, + currpackage->provided[i]->id, currpackage->provideflags[i]); if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); } - sqlite3_bind_text(stmt, 1, currpackage->providename[i], -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, currpackage->provideversion[i], -1, SQLITE_STATIC); + sqlite3_bind_text(stmt, 1, currpackage->provideversion[i], -1, SQLITE_STATIC); if (sqlite3_step(stmt) != SQLITE_DONE) { fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); return 3; @@ -332,22 +332,25 @@ generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) { /* requires */ for (i = 0; i < currpackage->requirecount; i++) { - snprintf(sqlite3_query, PATH_MAX, "INSERT INTO requires VALUES(NULL,%d,?,%d,?);", - currpackage->id, - currpackage->require[i]->flags); + if (currpackage->require[i]->resolved) { + snprintf(sqlite3_query, PATH_MAX, "INSERT INTO requires VALUES(NULL,%d,%d,%d,?);", + currpackage->id, + currpackage->require[i]->resolved->id, + currpackage->require[i]->flags); - if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - } - sqlite3_bind_text(stmt, 1, currpackage->require[i]->name, -1, SQLITE_STATIC); - sqlite3_bind_text(stmt, 2, currpackage->require[i]->version, -1, SQLITE_STATIC); - if (sqlite3_step(stmt) != SQLITE_DONE) { - fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); - return 3; - } - sqlite3_finalize(stmt); + if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + } + sqlite3_bind_text(stmt, 1, currpackage->require[i]->version, -1, SQLITE_STATIC); + if (sqlite3_step(stmt) != SQLITE_DONE) { + fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); + return 3; + } + sqlite3_finalize(stmt); + } else if (strstr(currpackage->require[i]->name,"rpmlib(") != currpackage->require[i]->name) { + fprintf(stderr, "WARNING: package %s require %s not in provided list\n", currpackage->name, currpackage->require[i]->name); + } } - currpackage = currpackage->next; } diff --git a/src/distroquery.c b/src/distroquery.c index 04d943a..b20696a 100644 --- a/src/distroquery.c +++ b/src/distroquery.c @@ -361,7 +361,7 @@ void printRPMFlags(int flags) { void printPackageData() { - int a, i, j, k, numresults = 0; + int a, i, j, k; char dbname[PATH_MAX]; sqlite3 *db, *dbs; sqlite3_stmt *statement, *stmt1; @@ -383,35 +383,41 @@ void printPackageData() { if (db && (sqlite3_prepare_v2(db, sql, strlen(sql), &statement, NULL) == SQLITE_OK)) { while (sqlite3_step(statement) == SQLITE_ROW) { - numresults++; - printf("

%s
 " - "
%s
 " - "
 %s 

" - "%s %s-%s
%s
Size: %s", - query_arch, - ct->tag, - sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")), - sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), - sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")), - sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release")), - sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")), - humanSize(sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "size")), &strsize)); - printf("
Source package:"); snprintf(dbname, PATH_MAX, "%s%s-sources.db", ct->repository_dir, ct->tag); if (!sqlite3_open_v2(dbname, &dbs, SQLITE_OPEN_READONLY, NULL)) { snprintf(sql, PATH_MAX, "SELECT * FROM sources WHERE id=%d", sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id_source"))); - if (sqlite3_prepare_v2(dbs, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) - while (sqlite3_step(stmt1) == SQLITE_ROW) - printf(" %s", - ct->tag, - sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")), - sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name"))); - sqlite3_close(dbs); + if (sqlite3_prepare_v2(dbs, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) sqlite3_step(stmt1); } - printf("
Obsoletes:"); + printf("

%s
 " + "
%s
 " + "
 %s 
 " + "
 %s 


" + "

%s - %s

Version: %s-%s
Size: %s", + query_arch, + ct->tag, + sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")), + sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "license")), + sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), + sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")), + sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")), + sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release")), + humanSize(sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "size")), &strsize)); + + printf("

%s

", + sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description"))); + + printf("
Developers details:"); + + printf("
Source package:"); + printf(" %s", + ct->tag, + sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name")), + sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name"))); + + printf("

Obsoletes:"); snprintf(sql, PATH_MAX, "SELECT * FROM obsoletes WHERE id_package=%d", sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) @@ -423,33 +429,35 @@ void printPackageData() { } } - printf("
Provides:"); - snprintf(sql, PATH_MAX, "SELECT * FROM provides WHERE id_package=%d", + printf("

Provides:"); + snprintf(sql, PATH_MAX, "SELECT * FROM provides,provided " + "WHERE provides.id_package=%d AND provided.id=provides.id_provided " + "ORDER BY provided.name", sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) while (sqlite3_step(stmt1) == SQLITE_ROW) { - printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "providename"))); + printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name"))); if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "provideversion"))) { printRPMFlags(sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "provideflags"))); printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "provideversion"))); } } - printf("
Requires:"); - snprintf(sql, PATH_MAX, "SELECT * FROM requires WHERE id_package=%d", + printf("

Requires:"); + snprintf(sql, PATH_MAX, "SELECT * FROM requires,provided " + "WHERE requires.id_package=%d AND provided.id=requires.id_provided " + "ORDER BY provided.name", sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) while (sqlite3_step(stmt1) == SQLITE_ROW) { - printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "requirename"))); + printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "name"))); if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "requireversion"))) { printRPMFlags(sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "requireflags"))); printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "requireversion"))); } } - printf("

%s

", - sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description"))); - + sqlite3_close(dbs); } } printf("]]>"); @@ -487,42 +495,19 @@ void printSourcePackageData() { numresults++; printf("

Source
 " "
%s
 " - "
 %s 

" - "%s %s-%s
%s
Maintainer: %s
License: %s
URL: %s
Size: %s" - "

%s

", + "
 %s 
 " + "
 %s 


" + "

%s - %s

Version: %s-%s
URL: %s
Size: %s", ct->tag, sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "groupdescr")), + sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "license")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "name")), + sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "version")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "release")), - sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "summary")), - sqlite3_column_text(statement,sqlite3_find_column_id(statement, "packagers", "name")), - sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "license")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "url")), sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "url")), - humanSize(sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "size")), &strsize), - sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description"))); - - printf("
Sources:"); - snprintf(sql, PATH_MAX, - "SELECT * FROM sources_source WHERE id_source=%d", - sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); - if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) - while (sqlite3_step(stmt1) == SQLITE_ROW) { - printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "source"))); - } - - printf("
Patches:"); - snprintf(sql, PATH_MAX, - "SELECT * FROM sources_patch WHERE id_source=%d", - sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); - if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) - while (sqlite3_step(stmt1) == SQLITE_ROW) { - printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "patch"))); - } - - printf("
Build time: %s", - simpleTimeToHuman(sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "buildtime")), (humanDate *) & strdate)); + humanSize(sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "size")), &strsize)); printf("
Built packages:"); for (a = 0; a < ARCHS_MAX && ct->arch[a]; a++) { @@ -542,7 +527,34 @@ void printSourcePackageData() { } } - printf("
Build requirements:"); + printf("

%s

", + sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description"))); + + printf("
Developers details:"); + printf("

Maintainer: %s", sqlite3_column_text(statement,sqlite3_find_column_id(statement, "packagers", "name"))); + printf("
Build date: %s", + simpleTimeToHuman(sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "buildtime")), (humanDate *) & strdate)); + + printf("

Source files:"); + snprintf(sql, PATH_MAX, + "SELECT * FROM sources_source WHERE id_source=%d", + sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); + if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) + while (sqlite3_step(stmt1) == SQLITE_ROW) { + printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "source"))); + } + + printf("

Patches:"); + snprintf(sql, PATH_MAX, + "SELECT * FROM sources_patch WHERE id_source=%d", + sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); + if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK) + while (sqlite3_step(stmt1) == SQLITE_ROW) { + printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "patch"))); + } + + + printf("

Build requirements:"); snprintf(sql, PATH_MAX, "SELECT * FROM buildrequires WHERE id_source=%d", sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "id"))); if (sqlite3_prepare_v2(db, sql, strlen(sql), &stmt1, NULL) == SQLITE_OK)