diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 02:45:56 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-30 02:45:56 +0100 |
commit | 991c9aac53fa3562b0fdc03d74b398052b207d2c (patch) | |
tree | daf1d16ecac1de62093d9019e2b9b355f12d81f6 /frontend/DB.cpp | |
parent | b9e738502260b8f448289c9888203971c7749c76 (diff) |
load objects kinda working, going to bed
Diffstat (limited to 'frontend/DB.cpp')
-rw-r--r-- | frontend/DB.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/frontend/DB.cpp b/frontend/DB.cpp index d51601e..28fd164 100644 --- a/frontend/DB.cpp +++ b/frontend/DB.cpp @@ -20,9 +20,9 @@ DBStatement DB::prepare(const string & query) { return DBStatement(*this, query); } -DBStatement::DBStatement(DB & db, const string & query) : db(db) { +DBStatement::DBStatement(DB & parent, const string & query) : parent(parent) { sqlite3_stmt * stmt = NULL; - int ret = sqlite3_prepare_v2(this->db.db.get(), query.c_str(), query.size(), &stmt, NULL); + int ret = sqlite3_prepare_v2(this->parent.db.get(), query.c_str(), query.size(), &stmt, NULL); this->stmt = { stmt, [] (sqlite3_stmt * stmt) { @@ -62,3 +62,23 @@ void DBStatement::execute() { throw Exception("sqlite3_step: %d", ret); } +DBQueryRow DBStatement::row() { + int ret = sqlite3_step(this->stmt.get()); + if (ret != SQLITE_ROW) + throw Exception("sqlite3_step: %d", ret); + + return { *this }; +} + +DBQueryRow::DBQueryRow(DBStatement & parent) : parent(parent) { } + +template <> +const char * DBQueryRow::col<const char*>(int index) { + return reinterpret_cast<const char *>(sqlite3_column_text(this->parent.stmt.get(), index)); +} + +template <> +int DBQueryRow::col<int>(int index) { + return sqlite3_column_int(this->parent.stmt.get(), index); +} + |