sqlite-backend, distroquery: use relations to provided in requires and provides tables

This commit is contained in:
Silvan Calarco 2013-10-13 02:17:31 +02:00
parent e23954abf5
commit e41fc038c7
2 changed files with 97 additions and 82 deletions

View File

@ -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;
}

View File

@ -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("<hr><br><div style='display:inline;color:white;background-color:green'> %s </div>&nbsp;"
"<div style='display:inline;color:black;background-color:yellow'> %s </div>&nbsp;"
"<div style='display:inline;color:black;background-color:lightblue'>&nbsp%s&nbsp;</div><br>"
"<b>%s</b> %s-%s<br>%s<br>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("<br>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(" <a href='javascript:distroquery_request(\"repository=%s&package=%s\")'>%s</a>",
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("<br>Obsoletes:");
printf("<hr><br><div style='display:inline;color:white;background-color:green'> %s </div>&nbsp;"
"<div style='display:inline;color:black;background-color:yellow'> %s </div>&nbsp;"
"<div style='display:inline;color:black;background-color:lightblue'>&nbsp%s&nbsp;</div>&nbsp;"
"<div style='display:inline;color:black;background-color:orange'>&nbsp%s&nbsp;</div><br><br>"
"<h1>%s - %s</h1>Version: %s-%s<br>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("<br><br><div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")));
printf("<hr><b>Developers details:</b>");
printf("<br>Source package:");
printf(" <a href='javascript:distroquery_request(\"repository=%s&package=%s\")'>%s</a>",
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("<br><br>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("<br>Provides:");
snprintf(sql, PATH_MAX, "SELECT * FROM provides WHERE id_package=%d",
printf("<br><br>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("<br>Requires:");
snprintf(sql, PATH_MAX, "SELECT * FROM requires WHERE id_package=%d",
printf("<br><br>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("<br><br><div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")));
sqlite3_close(dbs);
}
}
printf("]]></queryreply>");
@ -487,42 +495,19 @@ void printSourcePackageData() {
numresults++;
printf("<hr><br><div style='display:inline;color:white;background-color:red'> Source </div>&nbsp;"
"<div style='display:inline;color:black;background-color:yellow'> %s </div>&nbsp;"
"<div style='display:inline;color:black;background-color:lightblue'>&nbsp%s&nbsp;</div><br>"
"<b>%s</b> %s-%s<br>%s<br>Maintainer: %s<br>License: %s<br>URL: <a href=\"%s\" target=_new>%s</a><br>Size: %s"
"<br><br><div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>",
"<div style='display:inline;color:black;background-color:lightblue'>&nbsp%s&nbsp;</div>&nbsp;"
"<div style='display:inline;color:black;background-color:orange'>&nbsp%s&nbsp;</div><br><br>"
"<h1>%s - %s</h1>Version: %s-%s<br>URL: <a href=\"%s\" target=_new>%s</a><br>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("<br>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("<br>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("<br>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("<br>Built packages:");
for (a = 0; a < ARCHS_MAX && ct->arch[a]; a++) {
@ -542,7 +527,34 @@ void printSourcePackageData() {
}
}
printf("<br>Build requirements:");
printf("<br><br><div style='text-align:justify;text-justify:inter-word;font-style:italic'>%s</div><br>",
sqlite3_column_text(statement,sqlite3_find_column_id(statement, NULL, "description")));
printf("<hr><b>Developers details:</b>");
printf("<br><br>Maintainer: %s", sqlite3_column_text(statement,sqlite3_find_column_id(statement, "packagers", "name")));
printf("<br>Build date: %s",
simpleTimeToHuman(sqlite3_column_int(statement,sqlite3_find_column_id(statement, NULL, "buildtime")), (humanDate *) & strdate));
printf("<br><br>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("<br><br>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("<br><br>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)