backend-sqlite3: added packages tables and more improvements

This commit is contained in:
Silvan Calarco 2013-03-05 11:42:54 +01:00
parent 944c8673ea
commit b8c5893106
4 changed files with 151 additions and 25 deletions

View File

@ -25,8 +25,7 @@
#define SQLITE_TABLE_files "id INTEGER PRIMARY KEY, "\ #define SQLITE_TABLE_files "id INTEGER PRIMARY KEY, "\
"name STRING, firstchild INTEGER, next INTEGER, parent INTEGER, numproviders INTEGER" "name STRING, firstchild INTEGER, next INTEGER, parent INTEGER, numproviders INTEGER"
/* struct headerList **provider; /* struct headerList **provider; */
};*/
#define SQLITE_TABLE_provided "id INTEGER PRIMARY KEY, "\ #define SQLITE_TABLE_provided "id INTEGER PRIMARY KEY, "\
"name STRING, flags INTEGER, numproviders INTEGER" "name STRING, flags INTEGER, numproviders INTEGER"
@ -40,23 +39,23 @@
struct providedList *next; struct providedList *next;
};*/ };*/
#define SQLITE_TABLE_packager "id INTEGER PRIMARY KEY, "\ #define SQLITE_TABLE_packagers "id INTEGER PRIMARY KEY, "\
"name STRING, role INTEGER, changes_count INTEGER, packages_count INTEGER" "name STRING, role INTEGER, changes_count INTEGER, packages_count INTEGER"
/*struct Packager { /* char *alias[PACKAGER_MAXALIASES]; */
char *alias[PACKAGER_MAXALIASES];
};*/
#define SQLITE_TABLE_sources_source "id INTEGER PRIMARY KEY, id_sources INTEGER, source STRING" #define SQLITE_TABLE_changelog "id INTEGER PRIMARY KEY, "\
#define SQLITE_TABLE_sources_patch "id INTEGER PRIMARY KEY, id_sources INTEGER, patch STRING" "id_source INTEGER, time INTEGER, id_packager INTEGER, release STRING, text STRING"
//#define SQLITE_TABLE_sources_files_rel "id INTEGER PRIMARY KEY, id_sources INTEGER, id_files INTEGER"
#define SQLITE_TABLE_sources_provided_rel "id INTEGER PRIMARY KEY, id_sources INTEGER, id_provided INTEGER" #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, "\ #define SQLITE_TABLE_sources "id INTEGER PRIMARY KEY, "\
"name STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, id_packager INTEGER, "\ "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, " \ "groupdescr STRING, description STRING, url STRING, license STRING, arch STRING, buildarchs STRING, " \
"excludearch STRING, buildtime INTEGER" "excludearch STRING, buildtime INTEGER, size INTEGER, id_changelog INTEGER"
/* long size; /* char **dirname;
char **dirname;
char **basename; char **basename;
int filenamecount; int filenamecount;
int requirecount; int requirecount;
@ -65,12 +64,35 @@
int providecount; int providecount;
struct requireList *requirelist; struct requireList *requirelist;
struct headerSourceList *old; struct headerSourceList *old;
struct changeLog *changelog;
struct headerList *firstchild[ARCHS_MAX]; struct headerList *firstchild[ARCHS_MAX];
struct warningList *firstwarning; struct warningList *firstwarning;
struct headerSourceList *updatingparent; 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]; char sqlite3_query[PATH_MAX];
sqlite3_stmt *stmt; sqlite3_stmt *stmt;
@ -201,15 +223,15 @@ int generateSQLite_provided(struct configTag* ct, sqlite3 *db) {
return 0; return 0;
} }
int generateSQLite_packager(sqlite3 *db) { int generateSQLite_packagers(sqlite3 *db) {
struct Packager* packager = firstPackager(); struct Packager* packager = firstPackager();
SQLite_init_table(db, "packager", SQLITE_TABLE_packager); SQLite_init_table(db, "packagers", SQLITE_TABLE_packagers);
SQLite_begin_transaction(db); SQLite_begin_transaction(db);
while (packager) { while (packager) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packager VALUES(NULL,?,%d,%d,%d);", snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packagers VALUES(NULL,?,%d,%d,%d);",
packager->role, packager->role,
packager->changes_count, packager->changes_count,
packager->packages_count); packager->packages_count);
@ -229,26 +251,60 @@ int generateSQLite_packager(sqlite3 *db) {
SQLite_commit_transaction(db); SQLite_commit_transaction(db);
} }
long generateSQLite_add_changelog(sqlite3 *db, struct changeLog* firstchangelog, long id_source) {
struct changeLog* changelog = firstchangelog;
long lastchangelogid = 0;
while (changelog) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO changelog VALUES(NULL,%d,%d,%d,?,?);",
id_source,
changelog->time,
changelog->pkg->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, changelog->release, -1, SQLITE_STATIC);
sqlite3_bind_text(stmt, 2, changelog->text, -1, SQLITE_STATIC);
if (sqlite3_step(stmt) != SQLITE_DONE) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
return 3;
}
changelog->id = sqlite3_last_insert_rowid(db);
lastchangelogid = changelog->id;
sqlite3_finalize(stmt);
changelog = changelog->next;
}
return lastchangelogid;
}
int int
generateSQLite_sources(struct configTag *ct, sqlite3 *db) { generateSQLite_sources(struct configTag *ct, sqlite3 *db) {
struct headerSourceList* currsource; struct headerSourceList* currsource;
int i; int i;
long nextchangelogid = 1;
SQLite_init_table(db, "sources", SQLITE_TABLE_sources); SQLite_init_table(db, "sources", SQLITE_TABLE_sources);
SQLite_init_table(db, "sources_source", SQLITE_TABLE_sources_source); SQLite_init_table(db, "sources_source", SQLITE_TABLE_sources_source);
SQLite_init_table(db, "sources_patch", SQLITE_TABLE_sources_patch); SQLite_init_table(db, "sources_patch", SQLITE_TABLE_sources_patch);
// SQLite_init_table(db, "sources_files_rel", SQLITE_TABLE_sources_files_rel); // 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, "sources_provided_rel", SQLITE_TABLE_sources_provided_rel);
SQLite_init_table(db, "changelog", SQLITE_TABLE_changelog);
SQLite_begin_transaction(db); SQLite_begin_transaction(db);
currsource = ct->headersourcelist; currsource = ct->headersourcelist;
while (currsource != NULL) { while (currsource != NULL) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources VALUES(NULL,?,%d,%d,?,?,?,%d,?,?,?,?,?,?,?,%d);",
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO sources VALUES(%d,?,%d,%d,?,?,?,%d,?,?,?,?,?,?,?,%d,%d,%d);",
currsource->id,
currsource->altrepository, currsource->altrepository,
currsource->epoch, currsource->epoch,
currsource->packager->id, currsource->packager->id,
currsource->buildtime); currsource->buildtime,
currsource->size,
(currsource->changelog?nextchangelogid:0));
if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db)); fprintf(stderr, "ERROR: SQLite: (%s) %s\n", sqlite3_query, sqlite3_errmsg(db));
} }
@ -328,15 +384,74 @@ generateSQLite_sources(struct configTag *ct, sqlite3 *db) {
sqlite3_finalize(stmt); sqlite3_finalize(stmt);
}*/ }*/
if (currsource->changelog) {
nextchangelogid = generateSQLite_add_changelog(db, currsource->changelog, currsource->id) + 1;
}
currsource = currsource->next; currsource = currsource->next;
} }
SQLite_commit_transaction(db); SQLite_commit_transaction(db);
}
/* if (sqlite3_finalize(stmt)) { int
fprintf(stderr, "ERROR: SQLite: (%s) %s", sqlite3_query, sqlite3_errmsg(db)); generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) {
return 4;
}*/ struct headerList* currpackage;
int i;
snprintf(sqlite3_query, PATH_MAX, "packages_%s", ct->arch[i]);
SQLite_init_table(db, sqlite3_query, SQLITE_TABLE_packages);
snprintf(sqlite3_query, PATH_MAX, "packages_files_rel_%s", ct->arch[i]);
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_%s 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_%s 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 int
@ -344,6 +459,7 @@ generateSQLite(struct configTag *ct)
{ {
sqlite3 *db = NULL; sqlite3 *db = NULL;
char dbname[PATH_MAX]; char dbname[PATH_MAX];
int i;
snprintf(dbname, PATH_MAX, "/tmp/%s.db", ct->tag); snprintf(dbname, PATH_MAX, "/tmp/%s.db", ct->tag);
unlink(dbname); unlink(dbname);
@ -353,9 +469,14 @@ generateSQLite(struct configTag *ct)
return 1; return 1;
} }
generateSQLite_packager(db); generateSQLite_packagers(db);
generateSQLite_files(ct, db); generateSQLite_files(ct, db);
generateSQLite_provided(ct, db); generateSQLite_provided(ct, db);
for (i = 0; i < ARCHS_MAX && ct->arch[i]; i++) {
generateSQLite_packages(ct, db, i);
}
generateSQLite_sources(ct, db); generateSQLite_sources(ct, db);
sqlite3_close(db); sqlite3_close(db);

View File

@ -534,6 +534,8 @@ findOrCreateFileTreeEntry(struct fileTree* *first,char* findname)
return currdir; return currdir;
} }
static long sourceid = 0;
int int
addToSourceHeaderList(struct headerSourceList **headersourcelist, struct configTag *ct, addToSourceHeaderList(struct headerSourceList **headersourcelist, struct configTag *ct,
int mode, int altrepository) int mode, int altrepository)
@ -602,6 +604,7 @@ addToSourceHeaderList(struct headerSourceList **headersourcelist, struct configT
newheadersourcelist->altrepository = altrepository; newheadersourcelist->altrepository = altrepository;
newheadersourcelist->firstwarning = NULL; newheadersourcelist->firstwarning = NULL;
newheadersourcelist->old = NULL; newheadersourcelist->old = NULL;
newheadersourcelist->id = ++sourceid;
getPackageInfoIntoHeaderSourceList(h, newheadersourcelist); getPackageInfoIntoHeaderSourceList(h, newheadersourcelist);

View File

@ -32,6 +32,7 @@ struct changeLog {
char *release; char *release;
char *text; char *text;
struct changeLog *next; struct changeLog *next;
long id;
}; };
struct changeLogFull { struct changeLogFull {

View File

@ -88,6 +88,7 @@ struct headerList {
struct headerList *next, *nextbrother; struct headerList *next, *nextbrother;
struct headerSourceList *sourceheader; struct headerSourceList *sourceheader;
int obsoleted; int obsoleted;
long id;
}; };
struct headerSourceList { struct headerSourceList {