diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 12:24:43 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 12:24:43 +0100 |
commit | b1d5d7936bed17a684daff15b0294ef70754e8b9 (patch) | |
tree | 85ee543a15b42c7f854e4ce403bcff3dff5a3bd4 /frontend/DB.cpp | |
parent | 991c9aac53fa3562b0fdc03d74b398052b207d2c (diff) |
more more WIP
Diffstat (limited to 'frontend/DB.cpp')
-rw-r--r-- | frontend/DB.cpp | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/frontend/DB.cpp b/frontend/DB.cpp index 28fd164..d4527b8 100644 --- a/frontend/DB.cpp +++ b/frontend/DB.cpp @@ -51,7 +51,10 @@ DBStatement & DBStatement::bind(const int & number) { return *this; } -DBStatement & DBStatement::unbind() { +DBStatement & DBStatement::reset() { + int ret = sqlite3_reset(this->stmt.get()); + if (ret != SQLITE_OK) + throw Exception("sqlite3_reset: %d", ret); this->param_index = 1; return *this; } @@ -64,7 +67,7 @@ void DBStatement::execute() { DBQueryRow DBStatement::row() { int ret = sqlite3_step(this->stmt.get()); - if (ret != SQLITE_ROW) + if (ret != SQLITE_ROW && ret != SQLITE_DONE) throw Exception("sqlite3_step: %d", ret); return { *this }; @@ -72,13 +75,26 @@ DBQueryRow DBStatement::row() { DBQueryRow::DBQueryRow(DBStatement & parent) : parent(parent) { } + template <> -const char * DBQueryRow::col<const char*>(int index) { +const char * DBQueryRow::col<const char*>(int index, const char * const & default_value) { + int type = sqlite3_column_type(this->parent.stmt.get(), index); + if (type == SQLITE_NULL) return default_value; return reinterpret_cast<const char *>(sqlite3_column_text(this->parent.stmt.get(), index)); } +template <> +const char * DBQueryRow::col<const char*>(int index) { + return this->col<const char *>(index, ""); +} template <> -int DBQueryRow::col<int>(int index) { +int DBQueryRow::col<int>(int index, const int & default_value) { + int type = sqlite3_column_type(this->parent.stmt.get(), index); + if (type == SQLITE_NULL) return default_value; return sqlite3_column_int(this->parent.stmt.get(), index); } +template <> +int DBQueryRow::col<int>(int index) { + return this->col<int>(index, 0); +} |