Skip to content

Commit

Permalink
db.d: finalize after query to output extended result codes (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
slook authored Aug 19, 2024
1 parent bf95d7a commit 5a9cbf4
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/db.d
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,14 @@ class Sdb
@trusted
string[][] query(string query)
{
debug(db) writeln("DB query : \"", query, "%s\"");
string[][] ret;

sqlite3_reset(stmt);

char* tail;
uint res;
uint fin;

sqlite3_prepare(db, query.toStringz(), cast(uint)query.length, &stmt, &tail);
debug(db) writeln("DB: Query [", query, "]");
sqlite3_prepare_v2(db, query.toStringz(), cast(uint)query.length, &stmt, &tail);

uint res;
res = sqlite3_step(stmt);

while(res == SQLITE_ROW) {
Expand All @@ -267,8 +265,13 @@ class Sdb
res = sqlite3_step(stmt);
}

if (res != SQLITE_DONE) {
throw new Exception(format("SQL Error nb %d, query was : \"%s\"", res, query));
fin = sqlite3_finalize(stmt);

if (res != SQLITE_DONE || fin != SQLITE_OK) {
// https://sqlite.org/rescode.html#extrc
debug(db) writeln(format("DB: Result Code %d (%s)", res, sqlite3_errstr(res).to!string));
debug(db) writeln(format(" >Final Code %d (%s)", fin, sqlite3_errstr(fin).to!string));
throw new Exception(sqlite3_errstr(fin).to!string);
return null;
}
return ret;
Expand Down

0 comments on commit 5a9cbf4

Please sign in to comment.