diff --git a/plugin/integrated/sqlite/nvgt_sqlite.cpp b/plugin/integrated/sqlite/nvgt_sqlite.cpp index a39f0de..91163c5 100644 --- a/plugin/integrated/sqlite/nvgt_sqlite.cpp +++ b/plugin/integrated/sqlite/nvgt_sqlite.cpp @@ -31,7 +31,7 @@ void init_sqlite() { sqlite_started = true; } -sqlite3statement::sqlite3statement(sqlite3DB* p, sqlite3_stmt* s) : parent(p), statement(s), ref_count(1) {} +sqlite3statement::sqlite3statement(sqlite3_stmt* s) : statement(s), ref_count(1) {} void sqlite3statement::add_ref() { asAtomicInc(ref_count); } @@ -192,7 +192,7 @@ sqlite3statement* sqlite3DB::prepare(const std::string& statement, int* statemen if (err != SQLITE_OK) return nullptr; sqlite3statement* ret = NULL; if (st) - ret = new sqlite3statement(this, st); + ret = new sqlite3statement(st); if (tail && statement_tail) *statement_tail = (tail - statement.c_str()); return ret; diff --git a/plugin/integrated/sqlite/nvgt_sqlite.h b/plugin/integrated/sqlite/nvgt_sqlite.h index d070d31..560fe36 100644 --- a/plugin/integrated/sqlite/nvgt_sqlite.h +++ b/plugin/integrated/sqlite/nvgt_sqlite.h @@ -10,6 +10,7 @@ * 3. This notice may not be removed or altered from any source distribution. */ +#pragma once #include #include "../../src/nvgt_plugin.h" #include @@ -20,9 +21,8 @@ class sqlite3DB; class sqlite3statement { int ref_count; public: - sqlite3DB* parent; sqlite3_stmt* statement; - sqlite3statement(sqlite3DB* p, sqlite3_stmt* s); + sqlite3statement(sqlite3_stmt* s); void add_ref(); void release(); int step(); diff --git a/plugin/integrated/sqlite/pack.cpp b/plugin/integrated/sqlite/pack.cpp index fbf89cd..ef7acd4 100644 --- a/plugin/integrated/sqlite/pack.cpp +++ b/plugin/integrated/sqlite/pack.cpp @@ -768,6 +768,14 @@ void* pack::open_file(const std::string& file_name, const bool rw) { return nvgt_datastream_create(&stream, "", 1); } +sqlite3statement* pack::prepare(const string& statement, const bool persistant) { + sqlite3_stmt* stmt; + if (const auto rc = sqlite3_prepare_v3(db, statement.data(), statement.size(), persistant ? SQLITE_PREPARE_PERSISTENT : 0, &stmt, nullptr); rc != SQLITE_OK) { + throw runtime_error(Poco::format("Parse error: %s", string(sqlite3_errmsg(db)))); + } + return new sqlite3statement(stmt); +} + blob_stream_buf::blob_stream_buf(): Poco::BufferedBidirectionalStreamBuf(4096, ios::in) { } @@ -920,5 +928,6 @@ void RegisterScriptPack(asIScriptEngine* engine) { engine->RegisterObjectMethod("sqlite_pack", "void allocate_file(const string& file_name, const int64 size, const bool allow_replace = false)", asMETHODPR(pack, allocate_file, (const string&, const int64_t, const bool), void), asCALL_THISCALL); engine->RegisterObjectMethod("sqlite_pack", "bool rename_file(const string& old, const string& new_)", asMETHOD(pack, rename_file), asCALL_THISCALL); engine->RegisterObjectMethod("sqlite_pack", "void clear()", asMETHOD(pack, clear), asCALL_THISCALL); + engine->RegisterObjectMethod("sqlite_pack", "sqlite3statement@ prepare(const string& statement, const bool persistant = false)", asMETHOD(pack, prepare), asCALL_THISCALL); } diff --git a/plugin/integrated/sqlite/pack.h b/plugin/integrated/sqlite/pack.h index 86de897..a717254 100644 --- a/plugin/integrated/sqlite/pack.h +++ b/plugin/integrated/sqlite/pack.h @@ -22,6 +22,7 @@ #include #include #include +#include "nvgt_sqlite.h" class blob_stream; @@ -55,6 +56,7 @@ class pack : public Poco::RefCountedObject { void allocate_file(const std::string& file_name, const std::int64_t size, const bool allow_replace = false); bool rename_file(const std::string& old, const std::string& new_); void clear(); + sqlite3statement* prepare(const std::string& statement, const bool persistant = false); }; class blob_stream_buf: public Poco::BufferedBidirectionalStreamBuf {