Add callback response string clear, and throw string

thread v0.2_beta
marcelb 1 year ago
parent 0b5ed3f47b
commit f6c8443c5d
  1. 1
      lib/sql3.hpp
  2. 13
      src/sql3.cpp
  3. BIN
      test/test.o

@ -22,7 +22,6 @@ class sql3 {
sqlite3* db; sqlite3* db;
string path; string path;
bool keepOpen; bool keepOpen;
// map<string, vector<string>> model;
string Answer; string Answer;
map<string, vector<string>> parsed; map<string, vector<string>> parsed;

@ -6,7 +6,7 @@ sql3::sql3(const string _path, bool _keepOpen) {
if (keepOpen) { if (keepOpen) {
if (open()) { if (open()) {
throw "[ERROR] Unable to open database "; throw string("[ERROR] Unable to open database ");
} }
} }
@ -27,7 +27,7 @@ bool sql3::run(const string sql_command) {
if (!keepOpen) { if (!keepOpen) {
if (open()) { if (open()) {
throw "[ERROR] Unable to open database "; throw string("[ERROR] Unable to open database ");
} }
} }
@ -47,7 +47,7 @@ bool sql3::run(const string sql_command) {
if (!keepOpen) { if (!keepOpen) {
if(close()) { if(close()) {
throw "[ERROR] Unable to close database "; throw string("[ERROR] Unable to close database ");
} }
} }
@ -62,7 +62,7 @@ string sql3::answer() {
string sql3::ask(const string sql_command) { string sql3::ask(const string sql_command) {
if (!run(sql_command)) { if (!run(sql_command)) {
throw "[ERROR] Unable to read database "; throw string("[ERROR] Unable to read database ");
//return {}; //return {};
} }
else { else {
@ -72,7 +72,7 @@ string sql3::ask(const string sql_command) {
map<string, vector<string>> sql3::query(const string sql_command) { map<string, vector<string>> sql3::query(const string sql_command) {
if (!run(sql_command)) { if (!run(sql_command)) {
throw "[ERROR] Unable to read database "; throw string("[ERROR] Unable to read database ");
//return {}; //return {};
} }
else { else {
@ -104,7 +104,7 @@ void sql3::mapit() {
sql3::~sql3() { sql3::~sql3() {
if(close()) { if(close()) {
throw "[ERROR] Unable to close database "; throw string("[ERROR] Unable to close database ");
} }
} }
@ -117,6 +117,7 @@ static int callback(void* data, int argc, char** argv, char** azColName) {
int i; int i;
fprintf(stderr, "%s: ", (const char*)data); fprintf(stderr, "%s: ", (const char*)data);
char res[1000]; char res[1000];
responseDatabase.clear();
for (i = 0; i < argc; i++) { for (i = 0; i < argc; i++) {
sprintf(res, "%s = %s", azColName[i], argv[i] ? argv[i] : "NULL"); sprintf(res, "%s = %s", azColName[i], argv[i] ? argv[i] : "NULL");
responseDatabase += res; responseDatabase += res;

Binary file not shown.
Loading…
Cancel
Save