DistroqueryAPI: advancements in getPackageDetails

This commit is contained in:
Silvan Calarco 2024-05-31 19:14:53 +02:00
parent ee5803e622
commit 1f0dcb118f
3 changed files with 49 additions and 1 deletions

View File

@ -166,8 +166,47 @@ json DistroqueryAPI::getPackageDetails(string repository, string package, string
// Obsoletes // Obsoletes
sql = "SELECT * FROM obsoletes WHERE id_package=" + to_string(id); sql = "SELECT * FROM obsoletes WHERE id_package=" + to_string(id);
j["obsoletesbrothers"] = json::array(); j["obsoletes"] = json::array();
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt2, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt2) == SQLITE_ROW) {
json obsolete = {};
obsolete["name"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "obsoletename")));
obsolete["flags"] = rpmSenseFlagsToString(sqlite3_column_int(stmt2,sqlite3_find_column_id(stmt2, NULL, "obsoleteflags")));
obsolete["version"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "obsoleteversion")));
j["obsoletes"].push_back(obsolete);
}
sqlite3_finalize(stmt2);
}
// Provides
sql = "SELECT * FROM provides,provided WHERE provides.id_package=" + to_string(id) +
" AND provided.id=provides.id_provided ORDER BY provided.name";
j["provides"] = json::array();
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt2, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt2) == SQLITE_ROW) {
json provide = {};
provide["name"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "name")));
provide["flags"] = rpmSenseFlagsToString(sqlite3_column_int(stmt2,sqlite3_find_column_id(stmt2, NULL, "provideflags")));
provide["version"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "provideversion")));
j["provides"].push_back(provide);
}
sqlite3_finalize(stmt2);
}
// Requires
sql = "SELECT * FROM requires,provided WHERE requires.id_package=" + to_string(id) +
" AND provided.id=requires.id_provided ORDER BY provided.name";
j["requires"] = json::array();
if (sqlite3_prepare_v2(db, sql.c_str(), sql.length(), &stmt2, NULL) == SQLITE_OK) {
while (sqlite3_step(stmt2) == SQLITE_ROW) {
json require = {};
require["name"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "name")));
require["flags"] = rpmSenseFlagsToString(sqlite3_column_int(stmt2,sqlite3_find_column_id(stmt2, NULL, "requireflags")));
require["version"] = reinterpret_cast<const char*>(sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "requireversion")));
j["requires"].push_back(require);
}
sqlite3_finalize(stmt2);
}
} else { } else {
j["error"] = "error preparing query '" + sql + "'"; j["error"] = "error preparing query '" + sql + "'";

View File

@ -37,6 +37,14 @@ vector<string> split(string str, string token) {
return result; return result;
} }
string rpmSenseFlagsToString(int flags) {
string ret;
if (flags & RPMSENSE_LESS) ret += "<";
if (flags & RPMSENSE_GREATER) ret += ">";
if (flags & RPMSENSE_EQUAL) ret += "=";
return ret;
}
sqlite3* openRepositoryDatabase(struct configTag* ct, string arch, string append) { sqlite3* openRepositoryDatabase(struct configTag* ct, string arch, string append) {
string dbname; string dbname;
sqlite3* db; sqlite3* db;

View File

@ -26,6 +26,7 @@
using namespace std; using namespace std;
string rpmSenseFlagsToString(int flags);
vector<string> split(string str, string token); vector<string> split(string str, string token);
sqlite3* openRepositoryDatabase(struct configTag* ct, string arch = "", string append = ""); sqlite3* openRepositoryDatabase(struct configTag* ct, string arch = "", string append = "");
int sqlite3_find_column_id(sqlite3_stmt *stmt, const char* table, const char* name); int sqlite3_find_column_id(sqlite3_stmt *stmt, const char* table, const char* name);