Compare commits
3 Commits
f320087f12
...
ec8b4088c0
Author | SHA1 | Date | |
---|---|---|---|
ec8b4088c0 | |||
35ec97e05e | |||
af58277e8c |
@ -137,15 +137,31 @@ json DistroqueryAPI::getRepositoryPackages(string repository, int per_page, int
|
||||
return j;
|
||||
}
|
||||
|
||||
for (auto arch: ct->arch) {
|
||||
if (arch == NULL) break;
|
||||
attachRepositoryDatabases(ct, db, arch, 0);
|
||||
}
|
||||
|
||||
string query_append;
|
||||
if (query != "")
|
||||
query_append = "WHERE name LIKE '%" + query + "%' OR summary LIKE '%" + query +
|
||||
"%' OR description LIKE '%" + query + "%'";
|
||||
|
||||
sql = "SELECT COUNT(*) OVER() AS total_count,* FROM sources " + query_append +
|
||||
" ORDER BY name COLLATE NOCASE ASC"
|
||||
sql = "SELECT u.*,COUNT(*) OVER() AS total_count FROM ("
|
||||
"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) +
|
||||
" OFFSET " + to_string(per_page * (page -1));
|
||||
|
||||
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt, NULL) == SQLITE_OK) {
|
||||
json packages = json::array();
|
||||
long count = 0;
|
||||
@ -160,6 +176,7 @@ json DistroqueryAPI::getRepositoryPackages(string repository, int per_page, int
|
||||
}
|
||||
json package;
|
||||
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["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")));
|
||||
@ -173,7 +190,7 @@ json DistroqueryAPI::getRepositoryPackages(string repository, int per_page, int
|
||||
j["query"]["to"] = per_page * (page - 1) + count;
|
||||
j["packages"] = packages;
|
||||
} else {
|
||||
j["error"] = "error preparing query '" + sql + "'";
|
||||
j["error"] = "error preparing query '" + sql + "': " + sqlite3_errmsg(db);
|
||||
return j;
|
||||
}
|
||||
return j;
|
||||
|
@ -317,7 +317,7 @@ long generateSQLite_add_changelog(sqlite3 *db, struct changeLog* firstchangelog,
|
||||
|
||||
#define SQLITE_TABLE_packages "id INTEGER PRIMARY KEY, "\
|
||||
"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, "\
|
||||
"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];
|
||||
while (currpackage) {
|
||||
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->epoch,
|
||||
currpackage->buildtime,
|
||||
currpackage->size,
|
||||
currpackage->sourceheader->id);
|
||||
if (sqlite3_prepare_v2(db, sqlite3_query, -1, &stmt, NULL)) {
|
||||
|
@ -97,7 +97,7 @@ void attachRepositoryDatabases(struct configTag* ct, sqlite3 *db, string arch, i
|
||||
char *errmsg;
|
||||
|
||||
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)) {
|
||||
cerr << "ERROR: unable to exec statement for " << sql << ": " << errmsg << endl;
|
||||
}
|
||||
|
@ -171,6 +171,7 @@ getPackageInfoIntoHeaderList(Header h, struct headerList *hl)
|
||||
hl->description = headerGetStringEntry(h, RPMTAG_DESCRIPTION);
|
||||
hl->sourcename = headerGetStringEntry(h, RPMTAG_SOURCERPM);
|
||||
hl->group = headerGetStringEntry(h, RPMTAG_GROUP);
|
||||
hl->buildtime = headerGetUIntEntry(h, RPMTAG_BUILDTIME);
|
||||
hl->size = headerGetUIntEntry(h, RPMTAG_SIZE);
|
||||
|
||||
return 0;
|
||||
@ -1633,6 +1634,10 @@ char* advanceXMLPackageNode(xmlNode **primary_node, xmlNode **filelists_node) {
|
||||
findXMLPropertyByName(format, "group")->children->content);
|
||||
newheaderlist->sourcename = strdup((char*)
|
||||
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");
|
||||
tmp = (char*)findXMLAttributeByName(psize, "package");
|
||||
newheaderlist->size = atoi(tmp);
|
||||
|
@ -79,6 +79,7 @@ struct headerList {
|
||||
char *description;
|
||||
char *sourcename;
|
||||
char *arch;
|
||||
long buildtime;
|
||||
long size;
|
||||
char **obsoletename;
|
||||
uint_32 *obsoleteflags;
|
||||
|
Loading…
Reference in New Issue
Block a user