Bug fixing
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
Reference in New Issue
Block a user