#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; }