|
|
@ -23,7 +23,7 @@ bool SQLite3::close() { |
|
|
|
db = NULL; |
|
|
|
db = NULL; |
|
|
|
return operationStatus != SQLITE_OK; |
|
|
|
return operationStatus != SQLITE_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/*
|
|
|
|
map<string, vector<string>> SQLite3::query(const string sql_command) { |
|
|
|
map<string, vector<string>> SQLite3::query(const string sql_command) { |
|
|
|
io.lock(); |
|
|
|
io.lock(); |
|
|
|
if (!keepOpen) { |
|
|
|
if (!keepOpen) { |
|
|
@ -68,7 +68,48 @@ map<string, vector<string>> SQLite3::query(const string sql_command) { |
|
|
|
io.unlock(); |
|
|
|
io.unlock(); |
|
|
|
return _parsed; |
|
|
|
return _parsed; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map<string, vector<string>> SQLite3::query(const string& sql_command, const vector<string>& values) { |
|
|
|
|
|
|
|
lock_guard<mutex> lock(io); |
|
|
|
|
|
|
|
map<string, vector<string>> results; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!keepOpen) { |
|
|
|
|
|
|
|
if (open()) { |
|
|
|
|
|
|
|
throw string("[ERROR] Unable to open database "); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sqlite3_stmt* stmt; |
|
|
|
|
|
|
|
if (sqlite3_prepare_v2(db, sql_command.c_str(), -1, &stmt, nullptr) != SQLITE_OK) { |
|
|
|
|
|
|
|
throw string("[ERROR] Failed to prepare statement: ") + sqlite3_errmsg(db); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Binduj parametre
|
|
|
|
|
|
|
|
for (size_t i = 0; i < values.size(); ++i) { |
|
|
|
|
|
|
|
sqlite3_bind_text(stmt, static_cast<int>(i + 1), values[i].c_str(), -1, SQLITE_TRANSIENT); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dohvati rezultate
|
|
|
|
|
|
|
|
int columnCount = sqlite3_column_count(stmt); |
|
|
|
|
|
|
|
while (sqlite3_step(stmt) == SQLITE_ROW) { |
|
|
|
|
|
|
|
for (int i = 0; i < columnCount; ++i) { |
|
|
|
|
|
|
|
const char* columnName = sqlite3_column_name(stmt, i); |
|
|
|
|
|
|
|
const char* columnValue = (const char*)sqlite3_column_text(stmt, i); |
|
|
|
|
|
|
|
results[columnName].push_back(columnValue ? columnValue : "NULL"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
sqlite3_finalize(stmt); // Oslobodi resurse vezane uz izjavu
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!keepOpen) { |
|
|
|
|
|
|
|
if (close()) { |
|
|
|
|
|
|
|
throw string("[ERROR] Unable to close database "); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return results; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
map<string, vector<string>> SQLite3::parse(const string& result) { |
|
|
|
map<string, vector<string>> SQLite3::parse(const string& result) { |
|
|
|
string a = result; |
|
|
|
string a = result; |
|
|
|