diff --git a/src/DistroqueryAPI.cpp b/src/DistroqueryAPI.cpp index 9198004..cb31848 100644 --- a/src/DistroqueryAPI.cpp +++ b/src/DistroqueryAPI.cpp @@ -166,8 +166,47 @@ json DistroqueryAPI::getPackageDetails(string repository, string package, string // Obsoletes 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(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(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(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(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(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(sqlite3_column_text(stmt2,sqlite3_find_column_id(stmt2, NULL, "requireversion"))); + j["requires"].push_back(require); + } + sqlite3_finalize(stmt2); + } } else { j["error"] = "error preparing query '" + sql + "'"; diff --git a/src/distroquery_functions.cpp b/src/distroquery_functions.cpp index bd6b19f..f11ff07 100644 --- a/src/distroquery_functions.cpp +++ b/src/distroquery_functions.cpp @@ -37,6 +37,14 @@ vector split(string str, string token) { 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) { string dbname; sqlite3* db; diff --git a/src/include/distroquery_functions.hpp b/src/include/distroquery_functions.hpp index c285101..8761ea8 100644 --- a/src/include/distroquery_functions.hpp +++ b/src/include/distroquery_functions.hpp @@ -26,6 +26,7 @@ using namespace std; +string rpmSenseFlagsToString(int flags); vector split(string str, string token); sqlite3* openRepositoryDatabase(struct configTag* ct, string arch = "", string append = ""); int sqlite3_find_column_id(sqlite3_stmt *stmt, const char* table, const char* name);