diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-29 23:30:57 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-10-29 23:30:57 +0100 |
commit | 5c34847218e8d754447f5cf71ed595bbb412eee7 (patch) | |
tree | 2872948e6d2f566dd66cb1a9b2a5d9900db4c44f /frontend/DB.cpp | |
parent | a04cb74fee079e3ee43ae5fae32fc2674409822c (diff) |
more WIP
Diffstat (limited to 'frontend/DB.cpp')
-rw-r--r-- | frontend/DB.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/frontend/DB.cpp b/frontend/DB.cpp new file mode 100644 index 0000000..82933b8 --- /dev/null +++ b/frontend/DB.cpp @@ -0,0 +1,30 @@ +#include "DB.h" +#include "Exception.h" + +DB::DB(const std::string & path) { + sqlite3 * db = NULL; + int ret = sqlite3_open_v2(path.c_str(), &db, SQLITE_OPEN_READONLY, NULL); + this->db = { + db, + [] (sqlite3 * db) { + sqlite3_close_v2(db); + }, + }; + if (ret != SQLITE_OK) + throw Exception("sqlite3_open_v2"); +} + +DB::unique_sqlite3_stmt DB::prepare(const std::string & query) { + sqlite3_stmt * stmt = NULL; + int ret = sqlite3_prepare_v2(this->db.get(), query.c_str(), query.size(), &stmt, NULL); + unique_sqlite3_stmt uniq_stmt = { + stmt, + [] (sqlite3_stmt * stmt) { + sqlite3_finalize(stmt); + }, + }; + if (ret != SQLITE_OK) + throw Exception("sqlite3_prepare_v2"); + return uniq_stmt; +} + |