DistroqueryAPI: getRepositoryPackages: attach results for binary packages
This commit is contained in:
parent
35ec97e05e
commit
ec8b4088c0
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user