Compare commits

...

3 Commits

5 changed files with 30 additions and 6 deletions

View File

@ -137,15 +137,31 @@ json DistroqueryAPI::getRepositoryPackages(string repository, int per_page, int
return j; return j;
} }
for (auto arch: ct->arch) {
if (arch == NULL) break;
attachRepositoryDatabases(ct, db, arch, 0);
}
string query_append; string query_append;
if (query != "") if (query != "")
query_append = "WHERE name LIKE '%" + query + "%' OR summary LIKE '%" + query + query_append = "WHERE name LIKE '%" + query + "%' OR summary LIKE '%" + query +
"%' OR description LIKE '%" + query + "%'"; "%' OR description LIKE '%" + query + "%'";
sql = "SELECT COUNT(*) OVER() AS total_count,* FROM sources " + query_append + sql = "SELECT u.*,COUNT(*) OVER() AS total_count FROM ("
" ORDER BY name COLLATE NOCASE ASC" "SELECT name,arch,version,release,summary,buildtime,0 AS sort FROM sources " + query_append;
int archorder = 1;
for (auto arch: ct->arch) {
if (arch == NULL) break;
sql += " UNION SELECT name,arch,version,release,summary,buildtime," + to_string(archorder) +
" AS sort FROM '" + repository + "_" + arch + "'.packages " + query_append;
archorder++;
}
sql += ") AS u ORDER BY name COLLATE NOCASE ASC,sort"
" LIMIT " + to_string(per_page) + " LIMIT " + to_string(per_page) +
" OFFSET " + to_string(per_page * (page -1)); " OFFSET " + to_string(per_page * (page -1));
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt, NULL) == SQLITE_OK) { if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt, NULL) == SQLITE_OK) {
json packages = json::array(); json packages = json::array();
long count = 0; long count = 0;
@ -160,6 +176,7 @@ json DistroqueryAPI::getRepositoryPackages(string repository, int per_page, int
} }
json package; json package;
package["name"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "name"))); package["name"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "name")));
package["arch"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "arch")));
package["version"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "version"))); package["version"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "version")));
package["release"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "release"))); package["release"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "release")));
package["summary"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "summary"))); package["summary"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt,sqlite3_find_column_id(stmt, NULL, "summary")));
@ -173,7 +190,7 @@ json DistroqueryAPI::getRepositoryPackages(string repository, int per_page, int
j["query"]["to"] = per_page * (page - 1) + count; j["query"]["to"] = per_page * (page - 1) + count;
j["packages"] = packages; j["packages"] = packages;
} else { } else {
j["error"] = "error preparing query '" + sql + "'"; j["error"] = "error preparing query '" + sql + "': " + sqlite3_errmsg(db);
return j; return j;
} }
return j; return j;

View File

@ -317,7 +317,7 @@ long generateSQLite_add_changelog(sqlite3 *db, struct changeLog* firstchangelog,
#define SQLITE_TABLE_packages "id INTEGER PRIMARY KEY, "\ #define SQLITE_TABLE_packages "id INTEGER PRIMARY KEY, "\
"name STRING, arch STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, "\ "name STRING, arch STRING, altrepository INTEGER, epoch INTEGER, version STRING, release STRING, summary STRING, "\
"groupdescr STRING, description STRING, size INTEGER, id_source INTEGER" "groupdescr STRING, description STRING, buildtime INTEGER, size INTEGER, id_source INTEGER"
#define SQLITE_TABLE_obsoletes "id INTEGER PRIMARY KEY, "\ #define SQLITE_TABLE_obsoletes "id INTEGER PRIMARY KEY, "\
"id_package INTEGER, obsoletename STRING, obsoleteflags INTEGER, obsoleteversion STRING" "id_package INTEGER, obsoletename STRING, obsoleteflags INTEGER, obsoleteversion STRING"
@ -343,9 +343,10 @@ generateSQLite_packages(struct configTag *ct, sqlite3 *db, int arch) {
currpackage = ct->headerlist[arch]; currpackage = ct->headerlist[arch];
while (currpackage) { while (currpackage) {
if (currpackage->altrepository == ct->repository_level) { if (currpackage->altrepository == ct->repository_level) {
snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages VALUES(NULL,?,?,%d,%ld,?,?,?,?,?,%ld,%ld);", snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages VALUES(NULL,?,?,%d,%ld,?,?,?,?,?,%ld,%ld,%ld);",
currpackage->altrepository, currpackage->altrepository,
currpackage->epoch, currpackage->epoch,
currpackage->buildtime,
currpackage->size, currpackage->size,
currpackage->sourceheader->id); currpackage->sourceheader->id);
if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) { if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {

View File

@ -97,7 +97,7 @@ void attachRepositoryDatabases(struct configTag* ct, sqlite3 *db, string arch, i
char *errmsg; char *errmsg;
dbname = string(ct->repository_dir) + ct->tag + "-" + arch + ".db"; dbname = string(ct->repository_dir) + ct->tag + "-" + arch + ".db";
sql = "ATTACH DATABASE '" + dbname + "' as '" + ct->tag + "_" + arch; sql = "ATTACH DATABASE '" + dbname + "' as '" + ct->tag + "_" + arch + "'";
if (sqlite3_exec(db, sql.c_str(), NULL, NULL, &errmsg)) { if (sqlite3_exec(db, sql.c_str(), NULL, NULL, &errmsg)) {
cerr << "ERROR: unable to exec statement for " << sql << ": " << errmsg << endl; cerr << "ERROR: unable to exec statement for " << sql << ": " << errmsg << endl;
} }

View File

@ -171,6 +171,7 @@ getPackageInfoIntoHeaderList(Header h, struct headerList *hl)
hl->description = headerGetStringEntry(h, RPMTAG_DESCRIPTION); hl->description = headerGetStringEntry(h, RPMTAG_DESCRIPTION);
hl->sourcename = headerGetStringEntry(h, RPMTAG_SOURCERPM); hl->sourcename = headerGetStringEntry(h, RPMTAG_SOURCERPM);
hl->group = headerGetStringEntry(h, RPMTAG_GROUP); hl->group = headerGetStringEntry(h, RPMTAG_GROUP);
hl->buildtime = headerGetUIntEntry(h, RPMTAG_BUILDTIME);
hl->size = headerGetUIntEntry(h, RPMTAG_SIZE); hl->size = headerGetUIntEntry(h, RPMTAG_SIZE);
return 0; return 0;
@ -1633,6 +1634,10 @@ char* advanceXMLPackageNode(xmlNode **primary_node, xmlNode **filelists_node) {
findXMLPropertyByName(format, "group")->children->content); findXMLPropertyByName(format, "group")->children->content);
newheaderlist->sourcename = strdup((char*) newheaderlist->sourcename = strdup((char*)
findXMLPropertyByName(format, "sourcerpm")->children->content); findXMLPropertyByName(format, "sourcerpm")->children->content);
xmlNode *ptime = findXMLPropertyByName(primary_node[altidx], "time");
tmp = (char*)findXMLAttributeByName(ptime, "build");
newheaderlist->buildtime = atoi(tmp);
free(tmp);
xmlNode *psize = findXMLPropertyByName(primary_node[altidx], "size"); xmlNode *psize = findXMLPropertyByName(primary_node[altidx], "size");
tmp = (char*)findXMLAttributeByName(psize, "package"); tmp = (char*)findXMLAttributeByName(psize, "package");
newheaderlist->size = atoi(tmp); newheaderlist->size = atoi(tmp);

View File

@ -79,6 +79,7 @@ struct headerList {
char *description; char *description;
char *sourcename; char *sourcename;
char *arch; char *arch;
long buildtime;
long size; long size;
char **obsoletename; char **obsoletename;
uint_32 *obsoleteflags; uint_32 *obsoleteflags;