Bug fixing

This commit is contained in:
Your Name
2025-05-25 13:21:59 +12:00
parent aef2f84ed7
commit 3ad9fc2afa
2 changed files with 17 additions and 15 deletions

View File

@@ -185,8 +185,8 @@ bool Database::remove_by_hash(const std::string& hash) {
bool Database::get(const std::string& key, dbEntry& entry) {
std::string sql;
if (key.find(':') != std::string::npos) {
// Query by label:tag
sql = "SELECT hash, labeltags, metadata FROM objects WHERE labeltags LIKE ?;";
// Query by label:tag - search for exact match in the JSON array
sql = "SELECT hash, labeltags, metadata FROM objects WHERE json_array_length(labeltags) > 0 AND EXISTS (SELECT 1 FROM json_each(labeltags) WHERE value = ?);";
} else {
// Query by hash
sql = "SELECT hash, labeltags, metadata FROM objects WHERE hash = ?;";
@@ -198,9 +198,8 @@ bool Database::get(const std::string& key, dbEntry& entry) {
}
if (key.find(':') != std::string::npos) {
// Create JSON array pattern for LIKE query
std::string labeltag_pattern = "%\"" + key + "\"%";
sqlite3_bind_text(stmt, 1, labeltag_pattern.c_str(), -1, SQLITE_STATIC);
// For label:tag queries, bind the exact label:tag string
sqlite3_bind_text(stmt, 1, key.c_str(), -1, SQLITE_STATIC);
} else {
sqlite3_bind_text(stmt, 1, key.c_str(), -1, SQLITE_STATIC);
}