This commit is contained in:
@@ -1,9 +1,11 @@
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <set>
|
||||
#include <iostream>
|
||||
|
||||
#include "database.hpp"
|
||||
#include "sqlite3/sqlite3.h"
|
||||
#include "utils.hpp"
|
||||
|
||||
namespace simple_object_storage {
|
||||
|
||||
@@ -206,14 +208,34 @@ bool Database::run_sql_text(const std::string& sql, const std::string& bind_text
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool is_dec_uint64(const std::string& s) {
|
||||
if (s.empty()) return false;
|
||||
for (char c : s) {
|
||||
if (!std::isdigit(static_cast<unsigned char>(c))) return false;
|
||||
}
|
||||
try {
|
||||
uint64_t x = std::stoull(s, nullptr, 10);
|
||||
std::string s2=std::to_string(x);
|
||||
return s2 == s;
|
||||
} catch (...) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool Database::get(const std::string& hash_or_labeltag, dbEntry& entry) {
|
||||
std::string key=trim(hash_or_labeltag);
|
||||
|
||||
if (hash_or_labeltag.find(':') != std::string::npos)
|
||||
if (hash_or_labeltag.find(':') != std::string::npos) {
|
||||
return (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE json_array_length(labeltags) > 0 AND EXISTS (SELECT 1 FROM json_each(labeltags) WHERE value = ?);", hash_or_labeltag, entry));
|
||||
}
|
||||
|
||||
if (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE hash = ?;", hash_or_labeltag, entry))
|
||||
return true;
|
||||
if (is_dec_uint64(hash_or_labeltag)) {
|
||||
if (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE hash = ?;", hash_or_labeltag, entry))
|
||||
return true;
|
||||
}
|
||||
|
||||
// try with a :latest tag
|
||||
std::string with_latest = hash_or_labeltag + ":latest";
|
||||
return (run_sql_text("SELECT hash, labeltags, metadata FROM objects WHERE hash = ?;", with_latest, entry));
|
||||
}
|
||||
|
Reference in New Issue
Block a user