#include #include #include #include "backend/Dungeon.h" #include "generate_dungeon.h" #include "Exception.h" using namespace std; class DB { typedef unique_ptr> unique_sqlite3; typedef unique_ptr> unique_sqlite3_stmt; public: DB(const 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"); } unique_sqlite3_stmt prepare(const 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; } private: unique_sqlite3 db = NULL; }; unique_ptr generate_dungeon() { unique_ptr dungeon = make_unique(); DB db { "kerkersendraken.db" }; return dungeon; }