backend-sqlite3, distroquery: support for requires, provides, obsoletes and buildrequires

This commit is contained in:
Silvan Calarco 2013-10-12 23:50:08 +02:00
parent 78e98aa262
commit efd1fe2dcc
2 changed files with 240 additions and 140 deletions

View File

@ -24,77 +24,6 @@
#include "backend-sqlite3.h"
#include "functions.h"
#define SQLITE_TABLE_files "id INTEGER PRIMARY KEY, "\
"name STRING, firstchild INTEGER, next INTEGER, parent INTEGER, numproviders INTEGER"
/* struct headerList **provider; */
#define SQLITE_TABLE_provided "id INTEGER PRIMARY KEY, "\
"name STRING, flags INTEGER, numproviders INTEGER"
/*struct providedList {
struct headerList **provider;
int numbuildproviders;
struct headerList **buildprovider;
int numversions;
char **version;
int buildpriority;
struct providedList *next;
};*/
#define SQLITE_TABLE_packagers "id INTEGER PRIMARY KEY, "\
"name STRING, role INTEGER, changes_count INTEGER, packages_count INTEGER"
/* char *alias[PACKAGER_MAXALIASES]; */
#define SQLITE_TABLE_changelog "id INTEGER PRIMARY KEY, "\
"id_source INTEGER, time INTEGER, id_packager INTEGER, release STRING, text STRING"
#define SQLITE_TABLE_sources_source "id INTEGER PRIMARY KEY, id_source INTEGER, source STRING"
#define SQLITE_TABLE_sources_patch "id INTEGER PRIMARY KEY, id_source INTEGER, patch STRING"
//#define SQLITE_TABLE_sources_files_rel "id INTEGER PRIMARY KEY, id_source INTEGER, id_files INTEGER"
#define SQLITE_TABLE_sources_provided_rel "id INTEGER PRIMARY KEY, id_source INTEGER, id_provided INTEGER"
#define SQLITE_TABLE_sources "id INTEGER PRIMARY KEY, "\
"name STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, id_packager INTEGER, "\
"groupdescr STRING, description STRING, url STRING, license STRING, arch STRING, buildarchs STRING, " \
"excludearch STRING, buildtime INTEGER, size INTEGER, id_changelog INTEGER"
/* char **dirname;
char **basename;
int filenamecount;
int requirecount;
struct Require **require;
struct providedList **required;
int providecount;
struct requireList *requirelist;
struct headerSourceList *old;
struct headerList *firstchild[ARCHS_MAX];
struct warningList *firstwarning;
struct headerSourceList *updatingparent;
};*/
#define SQLITE_TABLE_packages_files_rel "id INTEGER PRIMARY KEY, id_package INTEGER, id_source INTEGER"
#define SQLITE_TABLE_packages "id INTEGER PRIMARY KEY, "\
"name STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, "\
"groupdescr STRING, description STRING, size INTEGER, id_source INTEGER"
// , url STRING, license STRING, arch STRING, buildarchs STRING, " \
// "excludearch STRING, buildtime INTEGER, size INTEGER, id_changelog INTEGER"
/*struct headerList {
char **obsoletename;
uint_32 *obsoleteflags;
char **obsoleteversion;
int obsoletecount;
char **providename;
uint_32 *provideflags;
char **provideversion;
int providecount;
int requirecount;
struct Require **require;
struct providedList **provided;
int recursed;
struct requireList *requirelist;
struct headerList *next, *nextbrother;
int obsoleted;
};*/
char sqlite3_query[PATH_MAX];
sqlite3_stmt *stmt;
long sqlite3_transaction_size;
@ -167,25 +96,56 @@ void SQLite_print_contents_subtree(sqlite3 *db,
}
}
int generateSQLite_files(struct configTag* ct, sqlite3 *db) {
#define SQLITE_TABLE_files "id INTEGER PRIMARY KEY, "\
"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"
int generateSQLite_files(struct configTag* ct, sqlite3 *db, int arch) {
int i;
struct headerList* currpackage;
for (i = 0; i < ARCHS_MAX && ct->arch[i]; i++) {
snprintf(sqlite3_query, PATH_MAX, "files_%s", ct->arch[i]);
snprintf(sqlite3_query, PATH_MAX, "packages_files_rel");
SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_packages_files_rel);
snprintf(sqlite3_query, PATH_MAX, "files");
SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_files);
SQLite_begin_transaction(db);
SQLite_print_contents_subtree(db, ct->filetree[i], ct, i);
SQLite_print_contents_subtree(db, ct->filetree[arch], ct, arch);
SQLite_commit_transaction(db);
/* if (sqlite3_finalize(stmt)) {
fprintf(stderr, "ERROR: SQLite: (%s) %s", sqlite3_query, sqlite3_errmsg(db));
}*/
currpackage = ct->headerlist[arch];
while (currpackage) {
/* packages <-> files relations */
for (i = 0; i < currpackage->filenamecount; i++) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages_files_rel VALUES(NULL,%d,%d);",
currpackage->id,
currpackage->file[arch]->id);
if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
}
if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
return 3;
}
sqlite3_finalize(stmt);
}
currpackage = currpackage->next;
}
return 0;
}
#define SQLITE_TABLE_provided "id INTEGER PRIMARY KEY, "\
"name STRING, flags INTEGER, numproviders INTEGER"
int generateSQLite_provided(struct configTag* ct, sqlite3 *db, int arch) {
@ -223,6 +183,10 @@ int generateSQLite_provided(struct configTag* ct, sqlite3 *db, int arch) {
return 0;
}
#define SQLITE_TABLE_packagers "id INTEGER PRIMARY KEY, "\
"name STRING, role INTEGER, changes_count INTEGER, packages_count INTEGER"
/* char *alias[PACKAGER_MAXALIASES]; */
int generateSQLite_packagers(sqlite3 *db) {
struct Packager* packager = firstPackager();
@ -279,6 +243,130 @@ long generateSQLite_add_changelog(sqlite3 *db, struct changeLog* firstchangelog,
return lastchangelogid;
}
#define SQLITE_TABLE_packages "id INTEGER PRIMARY KEY, "\
"name STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, "\
"groupdescr STRING, description STRING, size INTEGER, id_source INTEGER"
#define SQLITE_TABLE_obsoletes "id INTEGER PRIMARY KEY, "\
"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"
#define SQLITE_TABLE_requires "id INTEGER PRIMARY KEY, "\
"id_package INTEGER, requirename STRING, requireflags INTEGER, requireversion STRING"
int
generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) {
struct headerList* currpackage;
int i;
SQLite_init_table(db, "packages", SQLITE_TABLE_packages);
SQLite_init_table(db, "obsoletes", SQLITE_TABLE_obsoletes);
SQLite_init_table(db, "provides", SQLITE_TABLE_provides);
SQLite_init_table(db, "requires", SQLITE_TABLE_requires);
SQLite_begin_transaction(db);
currpackage = ct->headerlist[arch];
while (currpackage) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages VALUES(NULL,?,%d,%d,?,?,?,?,?,%d,%d);",
currpackage->altrepository,
currpackage->epoch,
currpackage->size,
currpackage->sourceheader->id);
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->name, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 4, currpackage->summary, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 5, currpackage->group, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 6, currpackage->description, -1, SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
return 3;
}
currpackage->id = sqlite3_last_insert_rowid(db);
sqlite3_finalize(stmt);
/* obsoletes */
for (i = 0; i < currpackage->obsoletecount; i++) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO obsoletes VALUES(NULL,%d,?,%d,?);",
currpackage->id,
currpackage->obsoleteflags[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->obsoletename[i], -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, currpackage->obsoleteversion[i], -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);
}
/* provides */
for (i = 0; i < currpackage->providecount; i++) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO provides VALUES(NULL,%d,?,%d,?);",
currpackage->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);
if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
return 3;
}
sqlite3_finalize(stmt);
}
/* 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 (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);
}
currpackage = currpackage->next;
}
SQLite_commit_transaction(db);
}
#define SQLITE_TABLE_sources_source "id INTEGER PRIMARY KEY, id_source INTEGER, source STRING"
#define SQLITE_TABLE_sources_patch "id INTEGER PRIMARY KEY, id_source INTEGER, patch STRING"
#define SQLITE_TABLE_sources "id INTEGER PRIMARY KEY, "\
"name STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, id_packager INTEGER, "\
"groupdescr STRING, description STRING, url STRING, license STRING, arch STRING, buildarchs STRING, " \
"excludearch STRING, buildtime INTEGER, size INTEGER, id_changelog INTEGER"
//#define SQLITE_TABLE_sources_files_rel "id INTEGER PRIMARY KEY, id_source INTEGER, id_files INTEGER"
//#define SQLITE_TABLE_sources_provided_rel "id INTEGER PRIMARY KEY, id_source INTEGER, id_provided INTEGER"
#define SQLITE_TABLE_changelog "id INTEGER PRIMARY KEY, "\
"id_source INTEGER, time INTEGER, id_packager INTEGER, release STRING, text STRING"
#define SQLITE_TABLE_buildrequires "id INTEGER PRIMARY KEY, "\
"id_source INTEGER, buildrequirename STRING, buildrequireflags INTEGER, buildrequireversion STRING"
int
generateSQLite_sources(struct configTag *ct, sqlite3 *db) {
@ -292,6 +380,7 @@ generateSQLite_sources(struct configTag *ct, sqlite3 *db) {
// SQLite_init_table(db, "sources_files_rel", SQLITE_TABLE_sources_files_rel);
// SQLite_init_table(db, "sources_provided_rel", SQLITE_TABLE_sources_provided_rel);
SQLite_init_table(db, "changelog", SQLITE_TABLE_changelog);
SQLite_init_table(db, "buildrequires", SQLITE_TABLE_buildrequires);
SQLite_begin_transaction(db);
currsource = ct->headersourcelist;
@ -368,6 +457,24 @@ generateSQLite_sources(struct configTag *ct, sqlite3 *db) {
}
}
/* buildrequires */
for (i = 0; i < currsource->requirecount; i++) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO buildrequires VALUES(NULL,%d,?,%d,?);",
currsource->id,
currsource->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, currsource->require[i]->name, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, currsource->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);
}
/* sources <-> provided relations (buildrequirements) */
/* for (i=0; i<currsource->providecount; i++) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources_provided_rel VALUES(NULL,%d,%d);",
@ -393,67 +500,6 @@ generateSQLite_sources(struct configTag *ct, sqlite3 *db) {
SQLite_commit_transaction(db);
}
int
generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) {
struct headerList* currpackage;
int i;
snprintf(sqlite3_query, PATH_MAX, "packages");
SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_packages);
snprintf(sqlite3_query, PATH_MAX, "packages_files_rel");
SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_packages_files_rel);
SQLite_begin_transaction(db);
currpackage = ct->headerlist[arch];
while (currpackage) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages VALUES(NULL,?,%d,%d,?,?,?,?,?,%d,%d);",
ct->arch[arch],
currpackage->altrepository,
currpackage->epoch,
currpackage->size,
currpackage->sourceheader->id);
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->name, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, currpackage->version, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 3, currpackage->release, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 4, currpackage->summary, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 5, currpackage->group, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 6, currpackage->description, -1, SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
return 3;
}
currpackage->id = sqlite3_last_insert_rowid(db);
sqlite3_finalize(stmt);
/* packages <-> files relations */
for (i = 0; i < currpackage->filenamecount; i++) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages_files_rel VALUES(NULL,%d,%d);",
ct->arch[arch],
currpackage->id,
currpackage->file[i]->id);
if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
}
if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
return 3;
}
sqlite3_finalize(stmt);
}
currpackage = currpackage->next;
}
SQLite_commit_transaction(db);
}
int
generateSQLite(struct configTag *ct)
{

View File

@ -353,6 +353,12 @@ void printQueryData() {
}
}
void printRPMFlags(int flags) {
if (flags & RPMSENSE_LESS) printf("<");
if (flags & RPMSENSE_GREATER) printf(">");
if (flags & RPMSENSE_EQUAL) printf("=");
}
void printPackageData() {
int a, i, j, k, numresults = 0;
@ -404,6 +410,42 @@ void printPackageData() {
sqlite3_close(dbs);
}
printf("<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)
while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoletename")));
if (sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoleteversion"))) {
printRPMFlags(sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoleteflags")));
printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "obsoleteversion")));
}
}
printf("<br>Provides:");
snprintf(sql, PATH_MAX, "SELECT * FROM provides 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)
while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "providename")));
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",
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")));
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")));
@ -498,6 +540,18 @@ void printSourcePackageData() {
}
}
printf("<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)
while (sqlite3_step(stmt1) == SQLITE_ROW) {
printf(" %s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequirename")));
if (strcmp("", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequireversion")))) {
printRPMFlags(sqlite3_column_int(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequireflags")));
printf("%s", sqlite3_column_text(stmt1,sqlite3_find_column_id(stmt1, NULL, "buildrequireversion")));
}
}
printf("<br><br>Changelog:<br>");
snprintf(sql, PATH_MAX,
"SELECT * FROM changelog,packagers WHERE id_source=%d AND changelog.id_packager=packagers.id",