Compare commits

..

No commits in common. "ec8b4088c000705f6e5eb92a89cea18ce4914e7a" and "f320087f124e437565dc69de4f43d2528fd75ca6" have entirely different histories.

5 changed files with 6 additions and 30 deletions

View File

@ -137,31 +137,15 @@ 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 u.*,COUNT(*) OVER() AS total_count FROM (" sql = "SELECT COUNT(*) OVER() AS total_count,* FROM sources " + query_append +
"SELECT name,arch,version,release,summary,buildtime,0 AS sort FROM sources " + query_append; " ORDER BY name COLLATE NOCASE ASC"
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;
@ -176,7 +160,6 @@ 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")));
@ -190,7 +173,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 + "': " + sqlite3_errmsg(db); j["error"] = "error preparing query '" + sql + "'";
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, buildtime INTEGER, size INTEGER, id_source INTEGER" "groupdescr STRING, description STRING, 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,10 +343,9 @@ 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,%ld);", snprintf(sqlite3_query, PATH_MAX, "INSERT INTO packages VALUES(NULL,?,?,%d,%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,7 +171,6 @@ 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;
@ -1634,10 +1633,6 @@ 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,7 +79,6 @@ 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;