|
|
@ -23,10 +23,11 @@ bool sql3::close() { |
|
|
|
return operationStatus != SQLITE_OK; |
|
|
|
return operationStatus != SQLITE_OK; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool sql3::run(const string sql_command) { |
|
|
|
map<string, vector<string>> sql3::query(const string sql_command) { |
|
|
|
|
|
|
|
io.lock(); |
|
|
|
if (!keepOpen) { |
|
|
|
if (!keepOpen) { |
|
|
|
if (open()) { |
|
|
|
if (open()) { |
|
|
|
|
|
|
|
io.unlock(); |
|
|
|
throw string("[ERROR] Unable to open database "); |
|
|
|
throw string("[ERROR] Unable to open database "); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -37,7 +38,6 @@ bool sql3::run(const string sql_command) { |
|
|
|
exec_stuts = sqlite3_exec(db, sql_command.c_str(), callback, NULL, &messaggeError); |
|
|
|
exec_stuts = sqlite3_exec(db, sql_command.c_str(), callback, NULL, &messaggeError); |
|
|
|
|
|
|
|
|
|
|
|
if (exec_stuts != SQLITE_OK) { |
|
|
|
if (exec_stuts != SQLITE_OK) { |
|
|
|
// printf("[ERROR] Ne mogu čitati bazu podataka!");
|
|
|
|
|
|
|
|
sqlite3_free(messaggeError); |
|
|
|
sqlite3_free(messaggeError); |
|
|
|
r = false; |
|
|
|
r = false; |
|
|
|
} |
|
|
|
} |
|
|
@ -48,40 +48,25 @@ bool sql3::run(const string sql_command) { |
|
|
|
|
|
|
|
|
|
|
|
if (!keepOpen) { |
|
|
|
if (!keepOpen) { |
|
|
|
if(close()) { |
|
|
|
if(close()) { |
|
|
|
|
|
|
|
io.unlock(); |
|
|
|
throw string("[ERROR] Unable to close database "); |
|
|
|
throw string("[ERROR] Unable to close database "); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return r; |
|
|
|
map<string, vector<string>> _parsed; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string sql3::answer() { |
|
|
|
if (!r) { |
|
|
|
string _Answer = Answer; |
|
|
|
io.unlock(); |
|
|
|
Answer.clear(); |
|
|
|
|
|
|
|
return _Answer; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
string sql3::ask(const string sql_command) { |
|
|
|
|
|
|
|
if (!run(sql_command)) { |
|
|
|
|
|
|
|
throw string("[ERROR] Unable to read database "); |
|
|
|
throw string("[ERROR] Unable to read database "); |
|
|
|
//return {};
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
return answer(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map<string, vector<string>> sql3::query(const string sql_command) { |
|
|
|
|
|
|
|
if (!run(sql_command)) { |
|
|
|
|
|
|
|
throw string("[ERROR] Unable to read database "); |
|
|
|
|
|
|
|
//return {};
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
else { |
|
|
|
mapit(); |
|
|
|
mapit(); |
|
|
|
map<string, vector<string>> _parsed = parsed; |
|
|
|
_parsed = parsed; |
|
|
|
parsed.clear(); |
|
|
|
parsed.clear(); |
|
|
|
return _parsed; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
io.unlock(); |
|
|
|
|
|
|
|
return _parsed; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void sql3::mapit() { |
|
|
|
void sql3::mapit() { |
|
|
|