From 8f11e08150ac41b38b32c04e2220e18f4fce87dc Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Mon, 4 Jul 2022 19:39:41 +0300 Subject: [PATCH] Allow session pool to be used with legacy database wrappers (experimental). --- module/Library/MySQL.cpp | 733 ++++++++++++++++++++------------------ module/Library/MySQL.hpp | 364 ++++++++++--------- module/Library/SQLite.cpp | 74 ++-- module/Library/SQLite.hpp | 94 ++--- module/PocoLib/Data.cpp | 28 ++ module/PocoLib/Data.hpp | 9 +- 6 files changed, 706 insertions(+), 596 deletions(-) diff --git a/module/Library/MySQL.cpp b/module/Library/MySQL.cpp index 285b5537..379b8a89 100644 --- a/module/Library/MySQL.cpp +++ b/module/Library/MySQL.cpp @@ -17,6 +17,15 @@ // ------------------------------------------------------------------------------------------------ namespace SqMod { +// ------------------------------------------------------------------------------------------------ +LightObj GteMySQLFromSession(Poco::Data::SessionImpl * session) +{ + // Create a reference counted connection handle instance + MySQLConnRef ref(new MySQLConnHnd(session)); + // Transform it into a connection instance and yield it as a script object + return LightObj(SqTypeIdentity< MySQLConnection >{}, SqVM(), ref); +} + // ------------------------------------------------------------------------------------------------ static inline bool IsDigitsOnly(const SQChar * str) { @@ -540,7 +549,7 @@ char DbConvTo< char >::From(const SQChar * value, unsigned long length, enum_fie } // ------------------------------------------------------------------------------------------------ -void ConnHnd::GrabCurrent() +void MySQLConnHnd::GrabCurrent() { mErrNo = mysql_errno(mPtr); mErrStr.assign(mysql_error(mPtr)); @@ -548,14 +557,14 @@ void ConnHnd::GrabCurrent() // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void ConnHnd::ThrowCurrent(const char * act, const char * file, int32_t line) +void MySQLConnHnd::ThrowCurrent(const char * act, const char * file, int32_t line) { GrabCurrent(); // Throw the exception with the resulted message throw Sqrat::Exception(fmt::format("{} ({}) : {} =>[{}:{}]", act, mErrNo, mErrStr, file, line)); } #else -void ConnHnd::ThrowCurrent(const char * act) +void MySQLConnHnd::ThrowCurrent(const char * act) { GrabCurrent(); // Throw the exception with the resulted message @@ -564,10 +573,11 @@ void ConnHnd::ThrowCurrent(const char * act) #endif // _DEBUG // ------------------------------------------------------------------------------------------------ -ConnHnd::ConnHnd() +MySQLConnHnd::MySQLConnHnd() : mPtr(nullptr) , mErrNo(0) , mErrStr() + , mSession() , mPort() , mHost() , mUser() @@ -588,13 +598,22 @@ ConnHnd::ConnHnd() } // ------------------------------------------------------------------------------------------------ -ConnHnd::~ConnHnd() +MySQLConnHnd::MySQLConnHnd(Poco::Data::SessionImpl * session) + : MySQLConnHnd() +{ + mSession.assign(session); + // Retrieve the internal handle property + mPtr = Poco::AnyCast< MYSQL * >(session->getProperty("handle")); +} + +// ------------------------------------------------------------------------------------------------ +MySQLConnHnd::~MySQLConnHnd() { Disconnect(); } // ------------------------------------------------------------------------------------------------ -void ConnHnd::Create(const Account & acc) +void MySQLConnHnd::Create(const MySQLAccount & acc) { // Is this connection already created? if (mPtr != nullptr) @@ -636,7 +655,7 @@ void ConnHnd::Create(const Account & acc) SQMOD_THROW_CURRENT(*this, "Cannot connect to database"); } // Attempt configure the auto-commit option - else if (mysql_autocommit(mPtr, static_cast< StmtBind::BoolType >(mAutoCommit)) != 0) + else if (mysql_autocommit(mPtr, static_cast< MySQLStmtBind::BoolType >(mAutoCommit)) != 0) { SQMOD_THROW_CURRENT(*this, "Cannot configure auto-commit"); } @@ -668,21 +687,29 @@ void ConnHnd::Create(const Account & acc) } // ------------------------------------------------------------------------------------------------ -void ConnHnd::Disconnect() +void MySQLConnHnd::Disconnect() { if (mPtr != nullptr) { - mysql_close(mPtr); - // mysql_init() called mysql_thread_init() therefore it needs to clear memory - // when the MYSQL handle is closed - mysql_thread_end(); + // If this connection is a pooled session then let it clean itself up + if (mSession.isNull()) + { + mysql_close(mPtr); + // mysql_init() called mysql_thread_init() therefore it needs to clear memory + // when the MYSQL handle is closed + mysql_thread_end(); + } + else + { + mSession.reset(); + } // Prevent further use of this handle mPtr = nullptr; } } // ------------------------------------------------------------------------------------------------ -uint64_t ConnHnd::Execute(const SQChar * query, unsigned long size) +uint64_t MySQLConnHnd::Execute(const SQChar * query, unsigned long size) { // Make sure that we are connected if (!mPtr) @@ -750,7 +777,7 @@ uint64_t ConnHnd::Execute(const SQChar * query, unsigned long size) } // ------------------------------------------------------------------------------------------------ -void StmtBind::SetInput(enum_field_types type, BindType * bind, const char * buffer, unsigned long length) +void MySQLStmtBind::SetInput(enum_field_types type, BindType * bind, const char * buffer, unsigned long length) { // Associate the library bind point with our bind wrapper mBind = bind; @@ -834,7 +861,7 @@ void StmtBind::SetInput(enum_field_types type, BindType * bind, const char * buf } // ------------------------------------------------------------------------------------------------ -void StmtHnd::GrabCurrent() +void MySQLStmtHnd::GrabCurrent() { mErrNo = mysql_stmt_errno(mPtr); mErrStr.assign(mysql_stmt_error(mPtr)); @@ -842,14 +869,14 @@ void StmtHnd::GrabCurrent() // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void StmtHnd::ThrowCurrent(const char * act, const char * file, int32_t line) +void MySQLStmtHnd::ThrowCurrent(const char * act, const char * file, int32_t line) { GrabCurrent(); // Throw the exception with the resulted message throw Sqrat::Exception(fmt::format("{} ({}) : {} =>[{}:{}]", act, mErrNo, mErrStr, file, line)); } #else -void StmtHnd::ThrowCurrent(const char * act) +void MySQLStmtHnd::ThrowCurrent(const char * act) { GrabCurrent(); // Throw the exception with the resulted message @@ -859,7 +886,7 @@ void StmtHnd::ThrowCurrent(const char * act) // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void StmtHnd::ValidateParam(uint32_t idx, const char * file, int32_t line) const +void MySQLStmtHnd::ValidateParam(uint32_t idx, const char * file, int32_t line) const { // Is the handle valid? if (mPtr == nullptr) @@ -872,7 +899,7 @@ void StmtHnd::ValidateParam(uint32_t idx, const char * file, int32_t line) const } } #else -void StmtHnd::ValidateParam(uint32_t idx) const +void MySQLStmtHnd::ValidateParam(uint32_t idx) const { // Is the handle valid? if (mPtr == nullptr) @@ -887,7 +914,7 @@ void StmtHnd::ValidateParam(uint32_t idx) const #endif // _DEBUG // ------------------------------------------------------------------------------------------------ -StmtHnd::StmtHnd() +MySQLStmtHnd::MySQLStmtHnd() : mPtr(nullptr) , mErrNo(0) , mErrStr() @@ -901,7 +928,7 @@ StmtHnd::StmtHnd() } // ------------------------------------------------------------------------------------------------ -StmtHnd::~StmtHnd() +MySQLStmtHnd::~MySQLStmtHnd() { // Should delete native bindings? if (mMyBinds) @@ -921,7 +948,7 @@ StmtHnd::~StmtHnd() } // ------------------------------------------------------------------------------------------------ -void StmtHnd::Create(const ConnRef & conn, const SQChar * query) +void MySQLStmtHnd::Create(const MySQLConnRef & conn, const SQChar * query) { // Is this statement already created? if (mPtr != nullptr) @@ -966,7 +993,7 @@ void StmtHnd::Create(const ConnRef & conn, const SQChar * query) return; } // Allocate the binding wrappers - mBinds = new StmtBind[mParams]; + mBinds = new MySQLStmtBind[mParams]; // Validate the allocated memory if (!mBinds) { @@ -984,7 +1011,7 @@ void StmtHnd::Create(const ConnRef & conn, const SQChar * query) } // ------------------------------------------------------------------------------------------------ -void ResBind::SetOutput(const FieldType & field, BindType * bind) +void MySQLResBind::SetOutput(const FieldType & field, BindType * bind) { // Associate the library bind point with our bind wrapper mBind = bind; @@ -1063,7 +1090,7 @@ void ResBind::SetOutput(const FieldType & field, BindType * bind) } // ------------------------------------------------------------------------------------------------ -ResHnd::ResHnd() +MySQLResHnd::MySQLResHnd() : mPtr(nullptr) , mFieldCount(0) , mLengths(nullptr) @@ -1079,7 +1106,7 @@ ResHnd::ResHnd() } // ------------------------------------------------------------------------------------------------ -ResHnd::~ResHnd() +MySQLResHnd::~MySQLResHnd() { // Is there a result-set that we should free? if (mPtr) @@ -1110,7 +1137,7 @@ ResHnd::~ResHnd() } // ------------------------------------------------------------------------------------------------ -void ResHnd::GrabCurrent() const +void MySQLResHnd::GrabCurrent() const { if (mConnection) { @@ -1124,7 +1151,7 @@ void ResHnd::GrabCurrent() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void ResHnd::ThrowCurrent(const char * act, const char * file, int32_t line) const +void MySQLResHnd::ThrowCurrent(const char * act, const char * file, int32_t line) const { GrabCurrent(); // Throw the exception with the resulted message @@ -1138,7 +1165,7 @@ void ResHnd::ThrowCurrent(const char * act, const char * file, int32_t line) con } } #else -void ResHnd::ThrowCurrent(const char * act) const +void MySQLResHnd::ThrowCurrent(const char * act) const { GrabCurrent(); // Throw the exception with the resulted message @@ -1155,7 +1182,7 @@ void ResHnd::ThrowCurrent(const char * act) const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void ResHnd::ValidateField(uint32_t idx, const char * file, int32_t line) const +void MySQLResHnd::ValidateField(uint32_t idx, const char * file, int32_t line) const { // Is the handle valid? if (mPtr == nullptr) @@ -1168,7 +1195,7 @@ void ResHnd::ValidateField(uint32_t idx, const char * file, int32_t line) const } } #else -void ResHnd::ValidateField(uint32_t idx) const +void MySQLResHnd::ValidateField(uint32_t idx) const { // Is the handle valid? if (mPtr == nullptr) @@ -1183,7 +1210,7 @@ void ResHnd::ValidateField(uint32_t idx) const #endif // _DEBUG // ------------------------------------------------------------------------------------------------ -uint32_t ResHnd::GetFieldIndex(const SQChar * name) +uint32_t MySQLResHnd::GetFieldIndex(const SQChar * name) { // Validate the handle if (!mPtr) @@ -1202,7 +1229,7 @@ uint32_t ResHnd::GetFieldIndex(const SQChar * name) } // ------------------------------------------------------------------------------------------------ -void ResHnd::Create(const ConnRef & conn) +void MySQLResHnd::Create(const MySQLConnRef & conn) { // Is this result-set already created? if (mPtr != nullptr) @@ -1249,7 +1276,7 @@ void ResHnd::Create(const ConnRef & conn) } // ------------------------------------------------------------------------------------------------ -void ResHnd::Create(const StmtRef & stmt) +void MySQLResHnd::Create(const MySQLStmtRef & stmt) { // Is this result-set already created? if (mPtr != nullptr) @@ -1289,7 +1316,7 @@ void ResHnd::Create(const StmtRef & stmt) if (mFieldCount > 0) { // Allocate the bind wrappers - mBinds = new ResBind[mFieldCount]; + mBinds = new MySQLResBind[mFieldCount]; // Validate the allocated structures if (!mBinds) { @@ -1339,7 +1366,7 @@ void ResHnd::Create(const StmtRef & stmt) } // ------------------------------------------------------------------------------------------------ -uint64_t ResHnd::RowIndex() const +uint64_t MySQLResHnd::RowIndex() const { // Is this result-set even valid? if (!mPtr) @@ -1356,7 +1383,7 @@ uint64_t ResHnd::RowIndex() const } // ------------------------------------------------------------------------------------------------ -uint64_t ResHnd::RowCount() const +uint64_t MySQLResHnd::RowCount() const { // Is this result-set even valid? if (!mPtr) @@ -1373,7 +1400,7 @@ uint64_t ResHnd::RowCount() const } // ------------------------------------------------------------------------------------------------ -bool ResHnd::Next() +bool MySQLResHnd::Next() { // Is this result-set even valid? if (!mPtr) @@ -1395,7 +1422,7 @@ bool ResHnd::Next() } // ------------------------------------------------------------------------------------------------ -bool ResHnd::SetRowIndex(uint64_t index) +bool MySQLResHnd::SetRowIndex(uint64_t index) { // Is this result-set even valid? if (!mPtr) @@ -1416,10 +1443,10 @@ bool ResHnd::SetRowIndex(uint64_t index) } // ------------------------------------------------------------------------------------------------ -const String Account::s_String{}; // NOLINT(cert-err58-cpp) +const String MySQLAccount::s_String{}; // NOLINT(cert-err58-cpp) // ------------------------------------------------------------------------------------------------ -SQInteger Account::Typename(HSQUIRRELVM vm) +SQInteger MySQLAccount::Typename(HSQUIRRELVM vm) { static const SQChar name[] = _SC("SqMySQLAccount"); sq_pushstring(vm, name, sizeof(name)); @@ -1427,7 +1454,7 @@ SQInteger Account::Typename(HSQUIRRELVM vm) } // ------------------------------------------------------------------------------------------------ -Account::Account(const SQChar * host, const SQChar * user, const SQChar * pass, const SQChar * name, SQInteger port, const SQChar * socket) +MySQLAccount::MySQLAccount(const SQChar * host, const SQChar * user, const SQChar * pass, const SQChar * name, SQInteger port, const SQChar * socket) : m_Port(0) , m_Host() , m_User() @@ -1462,7 +1489,7 @@ Account::Account(const SQChar * host, const SQChar * user, const SQChar * pass, } // ------------------------------------------------------------------------------------------------ -int32_t Account::Cmp(const Account & o) const +int32_t MySQLAccount::Cmp(const MySQLAccount & o) const { if (m_User == o.m_User && m_Pass == o.m_Pass) { @@ -1479,13 +1506,13 @@ int32_t Account::Cmp(const Account & o) const } // ------------------------------------------------------------------------------------------------ -String Account::ToString() const +String MySQLAccount::ToString() const { return fmt::format("{}:{}@{}:{}", m_User, m_Pass, m_Host, m_Port); } // ------------------------------------------------------------------------------------------------ -void Account::SetHost(const SQChar * addr) +void MySQLAccount::SetHost(const SQChar * addr) { // Clear the current host address m_Host.assign(_SC("")); @@ -1519,7 +1546,7 @@ void Account::SetHost(const SQChar * addr) } // ------------------------------------------------------------------------------------------------ -void Account::SetPortNum(SQInteger port) +void MySQLAccount::SetPortNum(SQInteger port) { // Validate the specified port number if (port >= 0xFFFF) @@ -1531,7 +1558,7 @@ void Account::SetPortNum(SQInteger port) } // ------------------------------------------------------------------------------------------------ -void Account::SetSSL(const SQChar * key, const SQChar * cert, const SQChar * ca, const SQChar * ca_path, const SQChar * cipher) +void MySQLAccount::SetSSL(const SQChar * key, const SQChar * cert, const SQChar * ca, const SQChar * ca_path, const SQChar * cipher) { if (!key || *key == '\0') { @@ -1552,7 +1579,7 @@ void Account::SetSSL(const SQChar * key, const SQChar * cert, const SQChar * ca, } // ------------------------------------------------------------------------------------------------ -Table Account::GetOptionsTable() const +Table MySQLAccount::GetOptionsTable() const { // Allocate an empty table Table tbl(SqVM(), static_cast< SQInteger >(m_Options.size())); @@ -1566,7 +1593,7 @@ Table Account::GetOptionsTable() const } // ------------------------------------------------------------------------------------------------ -const String & Account::GetOption(const SQChar * name) const +const String & MySQLAccount::GetOption(const SQChar * name) const { // Make sure the specified name is valid if (!name || *name == '\0') @@ -1580,7 +1607,7 @@ const String & Account::GetOption(const SQChar * name) const } // ------------------------------------------------------------------------------------------------ -void Account::SetOption(const SQChar * name, const SQChar * value) +void MySQLAccount::SetOption(const SQChar * name, const SQChar * value) { // Make sure the specified name is valid if (!name || *name == '\0') @@ -1592,7 +1619,7 @@ void Account::SetOption(const SQChar * name, const SQChar * value) } // ------------------------------------------------------------------------------------------------ -void Account::RemoveOption(const SQChar * name) +void MySQLAccount::RemoveOption(const SQChar * name) { // Make sure the specified name is valid if (!name || *name == '\0') @@ -1604,13 +1631,13 @@ void Account::RemoveOption(const SQChar * name) } // ------------------------------------------------------------------------------------------------ -Connection Account::Connect() const +MySQLConnection MySQLAccount::Connect() const { - return Connection(*this); + return MySQLConnection(*this); } // ------------------------------------------------------------------------------------------------ -SQInteger Connection::Typename(HSQUIRRELVM vm) +SQInteger MySQLConnection::Typename(HSQUIRRELVM vm) { static const SQChar name[] = _SC("SqMySQLConnection"); sq_pushstring(vm, name, sizeof(name)); @@ -1619,7 +1646,7 @@ SQInteger Connection::Typename(HSQUIRRELVM vm) // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void Connection::Validate(const char * file, int32_t line) const +void MySQLConnection::Validate(const char * file, int32_t line) const { if (!m_Handle) { @@ -1627,7 +1654,7 @@ void Connection::Validate(const char * file, int32_t line) const } } #else -void Connection::Validate() const +void MySQLConnection::Validate() const { if (!m_Handle) { @@ -1638,7 +1665,7 @@ void Connection::Validate() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void Connection::ValidateCreated(const char * file, int32_t line) const +void MySQLConnection::ValidateCreated(const char * file, int32_t line) const { if (!m_Handle) { @@ -1650,7 +1677,7 @@ void Connection::ValidateCreated(const char * file, int32_t line) const } } #else -void Connection::ValidateCreated() const +void MySQLConnection::ValidateCreated() const { if (!m_Handle) { @@ -1665,13 +1692,13 @@ void Connection::ValidateCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ConnRef & Connection::GetValid(const char * file, int32_t line) const +const MySQLConnRef & MySQLConnection::GetValid(const char * file, int32_t line) const { Validate(file, line); return m_Handle; } #else -const ConnRef & Connection::GetValid() const +const MySQLConnRef & MySQLConnection::GetValid() const { Validate(); return m_Handle; @@ -1680,13 +1707,13 @@ const ConnRef & Connection::GetValid() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ConnRef & Connection::GetCreated(const char * file, int32_t line) const +const MySQLConnRef & MySQLConnection::GetCreated(const char * file, int32_t line) const { ValidateCreated(file, line); return m_Handle; } #else -const ConnRef & Connection::GetCreated() const +const MySQLConnRef & MySQLConnection::GetCreated() const { ValidateCreated(); return m_Handle; @@ -1694,7 +1721,7 @@ const ConnRef & Connection::GetCreated() const #endif // _DEBUG // ------------------------------------------------------------------------------------------------ -SQInteger Connection::Insert(const SQChar * query) +SQInteger MySQLConnection::Insert(const SQChar * query) { // Make sure the specified query is valid if (!query || *query == '\0') @@ -1711,7 +1738,7 @@ SQInteger Connection::Insert(const SQChar * query) } // ------------------------------------------------------------------------------------------------ -ResultSet Connection::Query(const SQChar * query) +MySQLResultSet MySQLConnection::Query(const SQChar * query) { // Make sure the specified query is valid if (!query || *query == '\0') @@ -1724,17 +1751,17 @@ ResultSet Connection::Query(const SQChar * query) SQMOD_THROW_CURRENT(*m_Handle, "Unable to execute MySQL query"); } // Return the identifier of the inserted row - return ResultSet(m_Handle); + return MySQLResultSet(m_Handle); } // ------------------------------------------------------------------------------------------------ -Statement Connection::GetStatement(const SQChar * query) +MySQLStatement MySQLConnection::GetStatement(const SQChar * query) { - return Statement(SQMOD_GET_CREATED(*this), query); + return MySQLStatement(SQMOD_GET_CREATED(*this), query); } // ------------------------------------------------------------------------------------------------ -SQInteger Connection::ExecuteF(HSQUIRRELVM vm) +SQInteger MySQLConnection::ExecuteF(HSQUIRRELVM vm) { const auto top = static_cast(sq_gettop(vm)); // Was the query value specified? @@ -1743,11 +1770,11 @@ SQInteger Connection::ExecuteF(HSQUIRRELVM vm) return sq_throwerror(vm, "Missing query value"); } // The connection instance - Connection * conn = nullptr; + MySQLConnection * conn = nullptr; // Attempt to extract the argument values try { - conn = Var< Connection * >(vm, 1).value; + conn = Var< MySQLConnection * >(vm, 1).value; } catch (const Sqrat::Exception & e) { @@ -1795,7 +1822,7 @@ SQInteger Connection::ExecuteF(HSQUIRRELVM vm) } // ------------------------------------------------------------------------------------------------ -SQInteger Connection::InsertF(HSQUIRRELVM vm) +SQInteger MySQLConnection::InsertF(HSQUIRRELVM vm) { const auto top = static_cast(sq_gettop(vm)); // Was the query value specified? @@ -1804,11 +1831,11 @@ SQInteger Connection::InsertF(HSQUIRRELVM vm) return sq_throwerror(vm, "Missing query value"); } // The connection instance - Connection * conn = nullptr; + MySQLConnection * conn = nullptr; // Attempt to extract the argument values try { - conn = Var< Connection * >(vm, 1).value; + conn = Var< MySQLConnection * >(vm, 1).value; } catch (const Sqrat::Exception & e) { @@ -1862,7 +1889,7 @@ SQInteger Connection::InsertF(HSQUIRRELVM vm) // ------------------------------------------------------------------------------------------------ -SQInteger Connection::QueryF(HSQUIRRELVM vm) +SQInteger MySQLConnection::QueryF(HSQUIRRELVM vm) { const auto top = static_cast(sq_gettop(vm)); // Was the query value specified? @@ -1871,11 +1898,11 @@ SQInteger Connection::QueryF(HSQUIRRELVM vm) return sq_throwerror(vm, "Missing query value"); } // The connection instance - Connection * conn = nullptr; + MySQLConnection * conn = nullptr; // Attempt to extract the argument values try { - conn = Var< Connection * >(vm, 1).value; + conn = Var< MySQLConnection * >(vm, 1).value; } catch (const Sqrat::Exception & e) { @@ -1917,7 +1944,7 @@ SQInteger Connection::QueryF(HSQUIRRELVM vm) SQMOD_THROW_CURRENT(*(conn->m_Handle), "Unable to execute MySQL query"); } // Return a new instance with the obtained result set - Var< ResultSet * >::push(vm, new ResultSet(conn->m_Handle)); + Var< MySQLResultSet * >::push(vm, new MySQLResultSet(conn->m_Handle)); } catch (const Sqrat::Exception & e) { @@ -1929,7 +1956,7 @@ SQInteger Connection::QueryF(HSQUIRRELVM vm) } // ------------------------------------------------------------------------------------------------ -LightObj Connection::EscapeString(StackStrF & str) +LightObj MySQLConnection::EscapeString(StackStrF & str) { // Is there even a string to escape? if (str.mLen <= 0) @@ -1946,7 +1973,7 @@ LightObj Connection::EscapeString(StackStrF & str) } // ------------------------------------------------------------------------------------------------ -SQInteger Field::Typename(HSQUIRRELVM vm) +SQInteger MySQLField::Typename(HSQUIRRELVM vm) { static const SQChar name[] = _SC("SqMySQLField"); sq_pushstring(vm, name, sizeof(name)); @@ -1955,7 +1982,7 @@ SQInteger Field::Typename(HSQUIRRELVM vm) // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void Field::Validate(const char * file, int32_t line) const +void MySQLField::Validate(const char * file, int32_t line) const { // Do we have a valid result-set handle? if (!m_Handle) @@ -1969,7 +1996,7 @@ void Field::Validate(const char * file, int32_t line) const } } #else -void Field::Validate() const +void MySQLField::Validate() const { // Do we have a valid result-set handle? if (!m_Handle) @@ -1986,7 +2013,7 @@ void Field::Validate() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void Field::ValidateCreated(const char * file, int32_t line) const +void MySQLField::ValidateCreated(const char * file, int32_t line) const { // Do we have a valid result-set handle? if (!m_Handle) @@ -1997,7 +2024,7 @@ void Field::ValidateCreated(const char * file, int32_t line) const m_Handle->ValidateField(m_Index, file, line); } #else -void Field::ValidateCreated() const +void MySQLField::ValidateCreated() const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2011,7 +2038,7 @@ void Field::ValidateCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void Field::ValidateStepped(const char * file, int32_t line) const +void MySQLField::ValidateStepped(const char * file, int32_t line) const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2027,7 +2054,7 @@ void Field::ValidateStepped(const char * file, int32_t line) const m_Handle->ValidateField(m_Index, file, line); } #else -void Field::ValidateStepped() const +void MySQLField::ValidateStepped() const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2046,13 +2073,13 @@ void Field::ValidateStepped() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ResRef & Field::GetValid(const char * file, int32_t line) const +const MySQLResRef & MySQLField::GetValid(const char * file, int32_t line) const { Validate(file, line); return m_Handle; } #else -const ResRef & Field::GetValid() const +const MySQLResRef & MySQLField::GetValid() const { Validate(); return m_Handle; @@ -2061,13 +2088,13 @@ const ResRef & Field::GetValid() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ResRef & Field::GetCreated(const char * file, int32_t line) const +const MySQLResRef & MySQLField::GetCreated(const char * file, int32_t line) const { ValidateCreated(file, line); return m_Handle; } #else -const ResRef & Field::GetCreated() const +const MySQLResRef & MySQLField::GetCreated() const { ValidateCreated(); return m_Handle; @@ -2076,13 +2103,13 @@ const ResRef & Field::GetCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ResRef & Field::GetStepped(const char * file, int32_t line) const +const MySQLResRef & MySQLField::GetStepped(const char * file, int32_t line) const { ValidateStepped(file, line); return m_Handle; } #else -const ResRef & Field::GetStepped() const +const MySQLResRef & MySQLField::GetStepped() const { ValidateStepped(); return m_Handle; @@ -2091,7 +2118,7 @@ const ResRef & Field::GetStepped() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void Field::ValidateField(uint32_t idx, const char * file, int32_t line) const +void MySQLField::ValidateField(uint32_t idx, const char * file, int32_t line) const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2102,7 +2129,7 @@ void Field::ValidateField(uint32_t idx, const char * file, int32_t line) const m_Handle->ValidateField(idx, file, line); } #else -void Field::ValidateField(uint32_t idx) const +void MySQLField::ValidateField(uint32_t idx) const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2115,7 +2142,7 @@ void Field::ValidateField(uint32_t idx) const #endif // _DEBUG // ------------------------------------------------------------------------------------------------ -void Field::SetIndex(const Object & field) +void MySQLField::SetIndex(const Object & field) { // Where the index will be extracted uint32_t idx = INVALID_INDEX; @@ -2189,19 +2216,19 @@ void Field::SetIndex(const Object & field) } // ------------------------------------------------------------------------------------------------ -Object Field::GetResultSet() const // NOLINT(readability-convert-member-functions-to-static) +Object MySQLField::GetResultSet() const // NOLINT(readability-convert-member-functions-to-static) { return Object(); } // ------------------------------------------------------------------------------------------------ -Object Field::GetConnection() const // NOLINT(readability-convert-member-functions-to-static) +Object MySQLField::GetConnection() const // NOLINT(readability-convert-member-functions-to-static) { return Object(); } // ------------------------------------------------------------------------------------------------ -bool Field::GetBoolean() const +bool MySQLField::GetBoolean() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2216,7 +2243,7 @@ bool Field::GetBoolean() const } // ------------------------------------------------------------------------------------------------ -SQChar Field::GetChar() const +SQChar MySQLField::GetChar() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2231,7 +2258,7 @@ SQChar Field::GetChar() const } // ------------------------------------------------------------------------------------------------ -SQInteger Field::GetInteger() const +SQInteger MySQLField::GetInteger() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2250,7 +2277,7 @@ SQInteger Field::GetInteger() const } // ------------------------------------------------------------------------------------------------ -SQFloat Field::GetFloat() const +SQFloat MySQLField::GetFloat() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2269,7 +2296,7 @@ SQFloat Field::GetFloat() const } // ------------------------------------------------------------------------------------------------ -SQInteger Field::GetInt8() const +SQInteger MySQLField::GetInt8() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2284,7 +2311,7 @@ SQInteger Field::GetInt8() const } // ------------------------------------------------------------------------------------------------ -SQInteger Field::GetUint8() const +SQInteger MySQLField::GetUint8() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2299,7 +2326,7 @@ SQInteger Field::GetUint8() const } // ------------------------------------------------------------------------------------------------ -SQInteger Field::GetInt16() const +SQInteger MySQLField::GetInt16() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2314,7 +2341,7 @@ SQInteger Field::GetInt16() const } // ------------------------------------------------------------------------------------------------ -SQInteger Field::GetUint16() const +SQInteger MySQLField::GetUint16() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2329,7 +2356,7 @@ SQInteger Field::GetUint16() const } // ------------------------------------------------------------------------------------------------ -SQInteger Field::GetInt32() const +SQInteger MySQLField::GetInt32() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2344,7 +2371,7 @@ SQInteger Field::GetInt32() const } // ------------------------------------------------------------------------------------------------ -SQInteger Field::GetUint32() const +SQInteger MySQLField::GetUint32() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2359,7 +2386,7 @@ SQInteger Field::GetUint32() const } // ------------------------------------------------------------------------------------------------ -SQInteger Field::GetInt64() const +SQInteger MySQLField::GetInt64() const { SQMOD_VALIDATE_STEPPED(*this); // Obtain the initial stack size @@ -2376,7 +2403,7 @@ SQInteger Field::GetInt64() const } // ------------------------------------------------------------------------------------------------ -SQInteger Field::GetUint64() const +SQInteger MySQLField::GetUint64() const { SQMOD_VALIDATE_STEPPED(*this); // Obtain the initial stack size @@ -2393,7 +2420,7 @@ SQInteger Field::GetUint64() const } // ------------------------------------------------------------------------------------------------ -SQFloat Field::GetFloat32() const +SQFloat MySQLField::GetFloat32() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2408,7 +2435,7 @@ SQFloat Field::GetFloat32() const } // ------------------------------------------------------------------------------------------------ -SQFloat Field::GetFloat64() const +SQFloat MySQLField::GetFloat64() const { SQMOD_VALIDATE_STEPPED(*this); // Should we retrieve the value from the bind wrapper? @@ -2423,7 +2450,7 @@ SQFloat Field::GetFloat64() const } // ------------------------------------------------------------------------------------------------ -Object Field::GetString() const +Object MySQLField::GetString() const { SQMOD_VALIDATE_STEPPED(*this); // Obtain the initial stack size @@ -2439,19 +2466,19 @@ Object Field::GetString() const } // ------------------------------------------------------------------------------------------------ -Object Field::GetBuffer() const // NOLINT(readability-convert-member-functions-to-static) +Object MySQLField::GetBuffer() const // NOLINT(readability-convert-member-functions-to-static) { return NullObject(); } // ------------------------------------------------------------------------------------------------ -Object Field::GetBlob() const // NOLINT(readability-convert-member-functions-to-static) +Object MySQLField::GetBlob() const // NOLINT(readability-convert-member-functions-to-static) { return NullObject(); } // ------------------------------------------------------------------------------------------------ -SQInteger ResultSet::Typename(HSQUIRRELVM vm) +SQInteger MySQLResultSet::Typename(HSQUIRRELVM vm) { static const SQChar name[] = _SC("SqMySQLResultSet"); sq_pushstring(vm, name, sizeof(name)); @@ -2460,7 +2487,7 @@ SQInteger ResultSet::Typename(HSQUIRRELVM vm) // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void ResultSet::Validate(const char * file, int32_t line) const +void MySQLResultSet::Validate(const char * file, int32_t line) const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2469,7 +2496,7 @@ void ResultSet::Validate(const char * file, int32_t line) const } } #else -void ResultSet::Validate() const +void MySQLResultSet::Validate() const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2481,7 +2508,7 @@ void ResultSet::Validate() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void ResultSet::ValidateCreated(const char * file, int32_t line) const +void MySQLResultSet::ValidateCreated(const char * file, int32_t line) const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2494,7 +2521,7 @@ void ResultSet::ValidateCreated(const char * file, int32_t line) const } } #else -void ResultSet::ValidateCreated() const +void MySQLResultSet::ValidateCreated() const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2510,7 +2537,7 @@ void ResultSet::ValidateCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void ResultSet::ValidateStepped(const char * file, int32_t line) const +void MySQLResultSet::ValidateStepped(const char * file, int32_t line) const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2524,7 +2551,7 @@ void ResultSet::ValidateStepped(const char * file, int32_t line) const } } #else -void ResultSet::ValidateStepped() const +void MySQLResultSet::ValidateStepped() const { // Do we have a valid result-set handle? if (!m_Handle) @@ -2541,13 +2568,13 @@ void ResultSet::ValidateStepped() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ResRef & ResultSet::GetValid(const char * file, int32_t line) const +const MySQLResRef & MySQLResultSet::GetValid(const char * file, int32_t line) const { Validate(file, line); return m_Handle; } #else -const ResRef & ResultSet::GetValid() const +const MySQLResRef & MySQLResultSet::GetValid() const { Validate(); return m_Handle; @@ -2556,13 +2583,13 @@ const ResRef & ResultSet::GetValid() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ResRef & ResultSet::GetCreated(const char * file, int32_t line) const +const MySQLResRef & MySQLResultSet::GetCreated(const char * file, int32_t line) const { ValidateCreated(file, line); return m_Handle; } #else -const ResRef & ResultSet::GetCreated() const +const MySQLResRef & MySQLResultSet::GetCreated() const { ValidateCreated(); return m_Handle; @@ -2571,13 +2598,13 @@ const ResRef & ResultSet::GetCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ResRef & ResultSet::GetStepped(const char * file, int32_t line) const +const MySQLResRef & MySQLResultSet::GetStepped(const char * file, int32_t line) const { ValidateStepped(file, line); return m_Handle; } #else -const ResRef & ResultSet::GetStepped() const +const MySQLResRef & MySQLResultSet::GetStepped() const { ValidateStepped(); return m_Handle; @@ -2586,13 +2613,13 @@ const ResRef & ResultSet::GetStepped() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void ResultSet::ValidateField(int32_t idx, const char * file, int32_t line) const +void MySQLResultSet::ValidateField(int32_t idx, const char * file, int32_t line) const { ValidateCreated(file, line); m_Handle->ValidateField(idx, file, line); } #else -void ResultSet::ValidateField(int32_t idx) const +void MySQLResultSet::ValidateField(int32_t idx) const { ValidateCreated(); m_Handle->ValidateField(static_cast(idx)); @@ -2600,13 +2627,13 @@ void ResultSet::ValidateField(int32_t idx) const #endif // _DEBUG // ------------------------------------------------------------------------------------------------ -Array ResultSet::GetFieldNames() const +Array MySQLResultSet::GetFieldNames() const { SQMOD_VALIDATE_CREATED(*this); // Grab the number of available fields const SQInteger field_count = ConvTo< SQInteger >::From(m_Handle->mFieldCount); // Grab the array with field instances - const ResHnd::FieldType * fields = m_Handle->mFields; + const MySQLResHnd::FieldType * fields = m_Handle->mFields; // Is there even something to process? if (!field_count || !fields) { @@ -2624,7 +2651,7 @@ Array ResultSet::GetFieldNames() const } // ------------------------------------------------------------------------------------------------ -Array ResultSet::GetFieldsArray() const +Array MySQLResultSet::GetFieldsArray() const { SQMOD_VALIDATE_CREATED(*this); // Grab the number of available fields @@ -2635,7 +2662,7 @@ Array ResultSet::GetFieldsArray() const return Array(SqVM(), 0); } // Create a field instance to insert as copy - Field field(m_Handle); + MySQLField field(m_Handle); // Allocate an array with the same amount of elements as the number of fields Array arr(SqVM(), field_count); // Iterate over all the available fields and insert them into the created array @@ -2651,7 +2678,7 @@ Array ResultSet::GetFieldsArray() const } // ------------------------------------------------------------------------------------------------ -Array ResultSet::FetchFieldsArray(Array & fields) const +Array MySQLResultSet::FetchFieldsArray(Array & fields) const { SQMOD_VALIDATE_CREATED(*this); // Is there even something to process? @@ -2660,7 +2687,7 @@ Array ResultSet::FetchFieldsArray(Array & fields) const return Array(SqVM(), 0); } // Create a field instance to insert as copy - Field field(m_Handle); + MySQLField field(m_Handle); // Allocate an array with the same amount of elements as the number of fields Array arr(SqVM(), fields.Length()); // Iterate the specified fields array @@ -2677,20 +2704,20 @@ Array ResultSet::FetchFieldsArray(Array & fields) const } // ------------------------------------------------------------------------------------------------ -Table ResultSet::GetFieldsTable() const +Table MySQLResultSet::GetFieldsTable() const { SQMOD_VALIDATE_CREATED(*this); // Grab the number of available fields const SQInteger field_count = ConvTo< SQInteger >::From(m_Handle->mFieldCount); // Grab the array with field instances - const ResHnd::FieldType * fields = m_Handle->mFields; + const MySQLResHnd::FieldType * fields = m_Handle->mFields; // Is there even something to process? if (!field_count || !fields) { return Table(); } // Create a field instance to insert as copy - Field field(m_Handle); + MySQLField field(m_Handle); // Allocate a table to be populated with field instances Table tbl(SqVM(), field_count); // Iterate over all the available fields and insert them into the created table @@ -2706,7 +2733,7 @@ Table ResultSet::GetFieldsTable() const } // ------------------------------------------------------------------------------------------------ -Table ResultSet::FetchFieldsTable(Array & fields) const +Table MySQLResultSet::FetchFieldsTable(Array & fields) const { SQMOD_VALIDATE_CREATED(*this); // Is there even something to process? @@ -2715,11 +2742,11 @@ Table ResultSet::FetchFieldsTable(Array & fields) const return Table(); } // Create a field instance to insert as copy - Field field(m_Handle); + MySQLField field(m_Handle); // Allocate a table to be populated with field instances Table tbl(SqVM(), fields.Length()); // Grab the array with field instances - const ResHnd::FieldType * fields_ptr = m_Handle->mFields; + const MySQLResHnd::FieldType * fields_ptr = m_Handle->mFields; // Iterate the specified fields array fields.Foreach([&field, &tbl, fields_ptr](HSQUIRRELVM vm, SQInteger i) -> SQRESULT { // Update the field index @@ -2734,7 +2761,7 @@ Table ResultSet::FetchFieldsTable(Array & fields) const } // ------------------------------------------------------------------------------------------------ -SQInteger Statement::Typename(HSQUIRRELVM vm) +SQInteger MySQLStatement::Typename(HSQUIRRELVM vm) { static const SQChar name[] = _SC("SqMySQLStatement"); sq_pushstring(vm, name, sizeof(name)); @@ -2743,7 +2770,7 @@ SQInteger Statement::Typename(HSQUIRRELVM vm) // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void Statement::Validate(const char * file, int32_t line) const +void MySQLStatement::Validate(const char * file, int32_t line) const { if (!m_Handle) { @@ -2751,7 +2778,7 @@ void Statement::Validate(const char * file, int32_t line) const } } #else -void Statement::Validate() const +void MySQLStatement::Validate() const { if (!m_Handle) { @@ -2762,7 +2789,7 @@ void Statement::Validate() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void Statement::ValidateCreated(const char * file, int32_t line) const +void MySQLStatement::ValidateCreated(const char * file, int32_t line) const { if (!m_Handle) { @@ -2774,7 +2801,7 @@ void Statement::ValidateCreated(const char * file, int32_t line) const } } #else -void Statement::ValidateCreated() const +void MySQLStatement::ValidateCreated() const { if (!m_Handle) { @@ -2789,13 +2816,13 @@ void Statement::ValidateCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const StmtRef & Statement::GetValid(const char * file, int32_t line) const +const MySQLStmtRef & MySQLStatement::GetValid(const char * file, int32_t line) const { Validate(file, line); return m_Handle; } #else -const StmtRef & Statement::GetValid() const +const MySQLStmtRef & MySQLStatement::GetValid() const { Validate(); return m_Handle; @@ -2804,13 +2831,13 @@ const StmtRef & Statement::GetValid() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const StmtRef & Statement::GetCreated(const char * file, int32_t line) const +const MySQLStmtRef & MySQLStatement::GetCreated(const char * file, int32_t line) const { ValidateCreated(file, line); return m_Handle; } #else -const StmtRef & Statement::GetCreated() const +const MySQLStmtRef & MySQLStatement::GetCreated() const { ValidateCreated(); return m_Handle; @@ -2819,13 +2846,13 @@ const StmtRef & Statement::GetCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -void Statement::ValidateParam(int32_t idx, const char * file, int32_t line) const +void MySQLStatement::ValidateParam(int32_t idx, const char * file, int32_t line) const { ValidateCreated(file, line); m_Handle->ValidateParam(idx, file, line); } #else -void Statement::ValidateParam(int32_t idx) const +void MySQLStatement::ValidateParam(int32_t idx) const { ValidateCreated(); m_Handle->ValidateParam(static_cast< uint32_t >(idx)); @@ -2833,26 +2860,26 @@ void Statement::ValidateParam(int32_t idx) const #endif // _DEBUG // ------------------------------------------------------------------------------------------------ -Statement::Statement(const Connection & connection, const SQChar * query) - : Statement(connection.GetHandle(), query) +MySQLStatement::MySQLStatement(const MySQLConnection & connection, const SQChar * query) + : MySQLStatement(connection.GetHandle(), query) { /* ... */ } // ------------------------------------------------------------------------------------------------ -Connection Statement::GetConnection() const +MySQLConnection MySQLStatement::GetConnection() const { - return Connection(SQMOD_GET_VALID(*this)->mConnection); + return MySQLConnection(SQMOD_GET_VALID(*this)->mConnection); } // ------------------------------------------------------------------------------------------------ -void Statement::SetConnection(const Connection & conn) +void MySQLStatement::SetConnection(const MySQLConnection & conn) { SQMOD_GET_VALID(*this)->mConnection = conn.GetHandle(); } // ------------------------------------------------------------------------------------------------ -int32_t Statement::Execute() +int32_t MySQLStatement::Execute() { // Attempt to bind the parameters if (mysql_stmt_bind_param(SQMOD_GET_CREATED(*this)->mPtr, m_Handle->mMyBinds)) @@ -2869,7 +2896,7 @@ int32_t Statement::Execute() } // ------------------------------------------------------------------------------------------------ -uint32_t Statement::Insert() +uint32_t MySQLStatement::Insert() { // Attempt to bind the parameters if (mysql_stmt_bind_param(SQMOD_GET_CREATED(*this)->mPtr, m_Handle->mMyBinds)) @@ -2886,7 +2913,7 @@ uint32_t Statement::Insert() } // ------------------------------------------------------------------------------------------------ -ResultSet Statement::Query() +MySQLResultSet MySQLStatement::Query() { // Attempt to bind the parameters if (mysql_stmt_bind_param(SQMOD_GET_CREATED(*this)->mPtr, m_Handle->mMyBinds)) @@ -2899,11 +2926,11 @@ ResultSet Statement::Query() SQMOD_THROW_CURRENT(*m_Handle, "Cannot execute MySQL statement"); } // Return the results of this query - return ResultSet(m_Handle); + return MySQLResultSet(m_Handle); } // ------------------------------------------------------------------------------------------------ -void Statement::SetInt8(uint32_t idx, SQInteger val) const +void MySQLStatement::SetInt8(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -2913,7 +2940,7 @@ void Statement::SetInt8(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetUint8(uint32_t idx, SQInteger val) const +void MySQLStatement::SetUint8(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -2925,7 +2952,7 @@ void Statement::SetUint8(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetInt16(uint32_t idx, SQInteger val) const +void MySQLStatement::SetInt16(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -2935,7 +2962,7 @@ void Statement::SetInt16(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetUint16(uint32_t idx, SQInteger val) const +void MySQLStatement::SetUint16(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -2947,7 +2974,7 @@ void Statement::SetUint16(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetInt32(uint32_t idx, SQInteger val) const +void MySQLStatement::SetInt32(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -2957,7 +2984,7 @@ void Statement::SetInt32(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetUint32(uint32_t idx, SQInteger val) const +void MySQLStatement::SetUint32(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -2969,7 +2996,7 @@ void Statement::SetUint32(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetInt64(uint32_t idx, SQInteger val) const +void MySQLStatement::SetInt64(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -2979,7 +3006,7 @@ void Statement::SetInt64(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetUint64(uint32_t idx, SQInteger val) const +void MySQLStatement::SetUint64(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -2991,7 +3018,7 @@ void Statement::SetUint64(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetSLongInt(uint32_t idx, SQInteger val) const +void MySQLStatement::SetSLongInt(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3001,7 +3028,7 @@ void Statement::SetSLongInt(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetULongInt(uint32_t idx, SQInteger val) const +void MySQLStatement::SetULongInt(uint32_t idx, SQInteger val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3013,7 +3040,7 @@ void Statement::SetULongInt(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetInteger(uint32_t idx, SQInteger val) const +void MySQLStatement::SetInteger(uint32_t idx, SQInteger val) const { #ifdef _SQ64 SetInt64(idx, val); @@ -3023,7 +3050,7 @@ void Statement::SetInteger(uint32_t idx, SQInteger val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetFloat32(uint32_t idx, SQFloat val) const +void MySQLStatement::SetFloat32(uint32_t idx, SQFloat val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3033,7 +3060,7 @@ void Statement::SetFloat32(uint32_t idx, SQFloat val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetFloat64(uint32_t idx, SQFloat val) const +void MySQLStatement::SetFloat64(uint32_t idx, SQFloat val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3043,7 +3070,7 @@ void Statement::SetFloat64(uint32_t idx, SQFloat val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetFloat(uint32_t idx, SQFloat val) const +void MySQLStatement::SetFloat(uint32_t idx, SQFloat val) const { #ifdef SQUSEDOUBLE SetFloat64(idx, val); @@ -3053,7 +3080,7 @@ void Statement::SetFloat(uint32_t idx, SQFloat val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetBoolean(uint32_t idx, bool val) const +void MySQLStatement::SetBoolean(uint32_t idx, bool val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3063,7 +3090,7 @@ void Statement::SetBoolean(uint32_t idx, bool val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetDate(uint32_t idx, const Date & val) const +void MySQLStatement::SetDate(uint32_t idx, const Date & val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3073,7 +3100,7 @@ void Statement::SetDate(uint32_t idx, const Date & val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetTime(uint32_t idx, const Time & val) const +void MySQLStatement::SetTime(uint32_t idx, const Time & val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3083,7 +3110,7 @@ void Statement::SetTime(uint32_t idx, const Time & val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetDatetime(uint32_t idx, const Datetime & val) const +void MySQLStatement::SetDatetime(uint32_t idx, const Datetime & val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3093,7 +3120,7 @@ void Statement::SetDatetime(uint32_t idx, const Datetime & val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetString(uint32_t idx, const SQChar * val) const +void MySQLStatement::SetString(uint32_t idx, const SQChar * val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3102,7 +3129,7 @@ void Statement::SetString(uint32_t idx, const SQChar * val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetEnum(uint32_t idx, const SQChar * val) const +void MySQLStatement::SetEnum(uint32_t idx, const SQChar * val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3111,7 +3138,7 @@ void Statement::SetEnum(uint32_t idx, const SQChar * val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetSet(uint32_t idx, const SQChar * val) const +void MySQLStatement::SetSet(uint32_t idx, const SQChar * val) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3120,19 +3147,19 @@ void Statement::SetSet(uint32_t idx, const SQChar * val) const } // ------------------------------------------------------------------------------------------------ -void Statement::SetBlob(uint32_t /*idx*/, Object & /*val*/) const +void MySQLStatement::SetBlob(uint32_t /*idx*/, Object & /*val*/) const { // TODO: implement } // ------------------------------------------------------------------------------------------------ -void Statement::SetData(uint32_t /*idx*/, Object & /*val*/) const +void MySQLStatement::SetData(uint32_t /*idx*/, Object & /*val*/) const { // TODO: implement } // ------------------------------------------------------------------------------------------------ -void Statement::SetNull(uint32_t idx) const +void MySQLStatement::SetNull(uint32_t idx) const { SQMOD_VALIDATE_PARAM(*this, idx); // Attempt to set the input value @@ -3144,217 +3171,217 @@ void Register_MySQL(HSQUIRRELVM vm) { Table sqlns(vm); - sqlns.Bind(_SC("Account") - , Class< Account >(sqlns.GetVM(), _SC("SqMySQLAccount")) + sqlns.Bind(_SC("MySQLAccount") + , Class< MySQLAccount >(sqlns.GetVM(), _SC("SqMySQLAccount")) // Constructors - .Ctor< const Account & >() + .Ctor< const MySQLAccount & >() .Ctor< const SQChar *, const SQChar * >() .Ctor< const SQChar *, const SQChar *, const SQChar * >() .Ctor< const SQChar *, const SQChar *, const SQChar *, const SQChar * >() .Ctor< const SQChar *, const SQChar *, const SQChar *, const SQChar *, SQInteger >() .Ctor< const SQChar *, const SQChar *, const SQChar *, const SQChar *, SQInteger, const SQChar * >() // Core Meta-methods - .Func(_SC("_cmp"), &Account::Cmp) - .SquirrelFunc(_SC("_typename"), &Account::Typename) - .Func(_SC("_tostring"), &Account::ToString) + .Func(_SC("_cmp"), &MySQLAccount::Cmp) + .SquirrelFunc(_SC("_typename"), &MySQLAccount::Typename) + .Func(_SC("_tostring"), &MySQLAccount::ToString) // Properties - .Prop(_SC("Port"), &Account::GetPortNum, &Account::SetPortNum) - .Prop(_SC("Host"), &Account::GetHost, &Account::SetHost) - .Prop(_SC("User"), &Account::GetUser, &Account::SetUser) - .Prop(_SC("Pass"), &Account::GetPass, &Account::SetPass) - .Prop(_SC("Socket"), &Account::GetSocket, &Account::SetSocket) - .Prop(_SC("Flags"), &Account::GetFlags, &Account::SetFlags) - .Prop(_SC("SSL_Key"), &Account::GetSSL_Key, &Account::SetSSL_Key) - .Prop(_SC("SSL_Cert"), &Account::GetSSL_Cert, &Account::SetSSL_Cert) - .Prop(_SC("SSL_CA"), &Account::GetSSL_CA, &Account::SetSSL_CA) - .Prop(_SC("SSL_CA_Path"), &Account::GetSSL_CA_Path, &Account::SetSSL_CA_Path) - .Prop(_SC("SSL_Cipher"), &Account::GetSSL_Cipher, &Account::SetSSL_Cipher) - .Prop(_SC("AutoCommit"), &Account::GetAutoCommit, &Account::SetAutoCommit) - .Prop(_SC("Options"), &Account::GetOptionsTable) - .Prop(_SC("OptionsCount"), &Account::OptionsCount) - .Prop(_SC("OptionsEmpty"), &Account::OptionsEmpty) + .Prop(_SC("Port"), &MySQLAccount::GetPortNum, &MySQLAccount::SetPortNum) + .Prop(_SC("Host"), &MySQLAccount::GetHost, &MySQLAccount::SetHost) + .Prop(_SC("User"), &MySQLAccount::GetUser, &MySQLAccount::SetUser) + .Prop(_SC("Pass"), &MySQLAccount::GetPass, &MySQLAccount::SetPass) + .Prop(_SC("Socket"), &MySQLAccount::GetSocket, &MySQLAccount::SetSocket) + .Prop(_SC("Flags"), &MySQLAccount::GetFlags, &MySQLAccount::SetFlags) + .Prop(_SC("SSL_Key"), &MySQLAccount::GetSSL_Key, &MySQLAccount::SetSSL_Key) + .Prop(_SC("SSL_Cert"), &MySQLAccount::GetSSL_Cert, &MySQLAccount::SetSSL_Cert) + .Prop(_SC("SSL_CA"), &MySQLAccount::GetSSL_CA, &MySQLAccount::SetSSL_CA) + .Prop(_SC("SSL_CA_Path"), &MySQLAccount::GetSSL_CA_Path, &MySQLAccount::SetSSL_CA_Path) + .Prop(_SC("SSL_Cipher"), &MySQLAccount::GetSSL_Cipher, &MySQLAccount::SetSSL_Cipher) + .Prop(_SC("AutoCommit"), &MySQLAccount::GetAutoCommit, &MySQLAccount::SetAutoCommit) + .Prop(_SC("Options"), &MySQLAccount::GetOptionsTable) + .Prop(_SC("OptionsCount"), &MySQLAccount::OptionsCount) + .Prop(_SC("OptionsEmpty"), &MySQLAccount::OptionsEmpty) // Member Methods - .Func(_SC("EnableFlags"), &Account::EnableFlags) - .Func(_SC("DisableFlags"), &Account::DisableFlags) - .Func(_SC("SetSSL"), &Account::SetSSL) - .Func(_SC("GetOption"), &Account::GetOption) - .Func(_SC("SetOption"), &Account::SetOption) - .Func(_SC("RemoveOption"), &Account::RemoveOption) - .Func(_SC("OptionsClear"), &Account::OptionsClear) - .Func(_SC("Connect"), &Account::Connect) + .Func(_SC("EnableFlags"), &MySQLAccount::EnableFlags) + .Func(_SC("DisableFlags"), &MySQLAccount::DisableFlags) + .Func(_SC("SetSSL"), &MySQLAccount::SetSSL) + .Func(_SC("GetOption"), &MySQLAccount::GetOption) + .Func(_SC("SetOption"), &MySQLAccount::SetOption) + .Func(_SC("RemoveOption"), &MySQLAccount::RemoveOption) + .Func(_SC("OptionsClear"), &MySQLAccount::OptionsClear) + .Func(_SC("Connect"), &MySQLAccount::Connect) ); sqlns.Bind(_SC("Connection") - , Class< Connection >(sqlns.GetVM(), _SC("SqMySQLConnection")) + , Class< MySQLConnection >(sqlns.GetVM(), _SC("SqMySQLConnection")) // Constructors .Ctor() - .Ctor< const Account & >() + .Ctor< const MySQLAccount & >() // Core Meta-methods - .Func(_SC("_cmp"), &Connection::Cmp) - .SquirrelFunc(_SC("_typename"), &Connection::Typename) - .Func(_SC("_tostring"), &Connection::ToString) + .Func(_SC("_cmp"), &MySQLConnection::Cmp) + .SquirrelFunc(_SC("_typename"), &MySQLConnection::Typename) + .Func(_SC("_tostring"), &MySQLConnection::ToString) // Properties - .Prop(_SC("IsValid"), &Connection::IsValid) - .Prop(_SC("Connected"), &Connection::IsConnected) - .Prop(_SC("References"), &Connection::GetRefCount) - .Prop(_SC("ErrNo"), &Connection::GetErrNo) - .Prop(_SC("ErrStr"), &Connection::GetErrStr) - .Prop(_SC("LastErrNo"), &Connection::GetLastErrNo) - .Prop(_SC("LastErrStr"), &Connection::GetLastErrStr) - .Prop(_SC("Port"), &Connection::GetPortNum) - .Prop(_SC("Host"), &Connection::GetHost) - .Prop(_SC("User"), &Connection::GetUser) - .Prop(_SC("Pass"), &Connection::GetPass) - .Prop(_SC("Name"), &Connection::GetName, &Connection::SetName) - .Prop(_SC("Socket"), &Connection::GetSocket) - .Prop(_SC("Flags"), &Connection::GetFlags) - .Prop(_SC("SSL_Key"), &Connection::GetSSL_Key) - .Prop(_SC("SSL_Cert"), &Connection::GetSSL_Cert) - .Prop(_SC("SSL_CA"), &Connection::GetSSL_CA) - .Prop(_SC("SSL_CA_Path"), &Connection::GetSSL_CA_Path) - .Prop(_SC("SSL_Cipher"), &Connection::GetSSL_Cipher) - .Prop(_SC("Charset"), &Connection::GetCharset, &Connection::SetCharset) - .Prop(_SC("AutoCommit"), &Connection::GetAutoCommit, &Connection::SetAutoCommit) - .Prop(_SC("InTransaction"), &Connection::GetInTransaction) + .Prop(_SC("IsValid"), &MySQLConnection::IsValid) + .Prop(_SC("Connected"), &MySQLConnection::IsConnected) + .Prop(_SC("References"), &MySQLConnection::GetRefCount) + .Prop(_SC("ErrNo"), &MySQLConnection::GetErrNo) + .Prop(_SC("ErrStr"), &MySQLConnection::GetErrStr) + .Prop(_SC("LastErrNo"), &MySQLConnection::GetLastErrNo) + .Prop(_SC("LastErrStr"), &MySQLConnection::GetLastErrStr) + .Prop(_SC("Port"), &MySQLConnection::GetPortNum) + .Prop(_SC("Host"), &MySQLConnection::GetHost) + .Prop(_SC("User"), &MySQLConnection::GetUser) + .Prop(_SC("Pass"), &MySQLConnection::GetPass) + .Prop(_SC("Name"), &MySQLConnection::GetName, &MySQLConnection::SetName) + .Prop(_SC("Socket"), &MySQLConnection::GetSocket) + .Prop(_SC("Flags"), &MySQLConnection::GetFlags) + .Prop(_SC("SSL_Key"), &MySQLConnection::GetSSL_Key) + .Prop(_SC("SSL_Cert"), &MySQLConnection::GetSSL_Cert) + .Prop(_SC("SSL_CA"), &MySQLConnection::GetSSL_CA) + .Prop(_SC("SSL_CA_Path"), &MySQLConnection::GetSSL_CA_Path) + .Prop(_SC("SSL_Cipher"), &MySQLConnection::GetSSL_Cipher) + .Prop(_SC("Charset"), &MySQLConnection::GetCharset, &MySQLConnection::SetCharset) + .Prop(_SC("AutoCommit"), &MySQLConnection::GetAutoCommit, &MySQLConnection::SetAutoCommit) + .Prop(_SC("InTransaction"), &MySQLConnection::GetInTransaction) // Member Methods - .Func(_SC("Disconnect"), &Connection::Disconnect) - .Func(_SC("SelectDb"), &Connection::SetName) - .Func(_SC("Execute"), &Connection::Execute) - .Func(_SC("Insert"), &Connection::Insert) - .Func(_SC("Query"), &Connection::Query) - .Func(_SC("Statement"), &Connection::GetStatement) - //.Func(_SC("Transaction"), &Connection::GetTransaction) - .FmtFunc(_SC("EscapeString"), &Connection::EscapeString) + .Func(_SC("Disconnect"), &MySQLConnection::Disconnect) + .Func(_SC("SelectDb"), &MySQLConnection::SetName) + .Func(_SC("Execute"), &MySQLConnection::Execute) + .Func(_SC("Insert"), &MySQLConnection::Insert) + .Func(_SC("Query"), &MySQLConnection::Query) + .Func(_SC("Statement"), &MySQLConnection::GetStatement) + //.Func(_SC("Transaction"), &MySQLConnection::GetTransaction) + .FmtFunc(_SC("EscapeString"), &MySQLConnection::EscapeString) // Squirrel Methods - .SquirrelFunc(_SC("ExecuteF"), &Connection::ExecuteF) - .SquirrelFunc(_SC("InsertF"), &Connection::InsertF) - .SquirrelFunc(_SC("QueryF"), &Connection::QueryF) + .SquirrelFunc(_SC("ExecuteF"), &MySQLConnection::ExecuteF) + .SquirrelFunc(_SC("InsertF"), &MySQLConnection::InsertF) + .SquirrelFunc(_SC("QueryF"), &MySQLConnection::QueryF) ); sqlns.Bind(_SC("Field"), - Class< Field >(sqlns.GetVM(), _SC("SqMySQLField")) + Class< MySQLField >(sqlns.GetVM(), _SC("SqMySQLField")) // Constructors .Ctor() - .Ctor< const Field & >() + .Ctor< const MySQLField & >() // Meta-methods - .Func(_SC("_cmp"), &Field::Cmp) - .SquirrelFunc(_SC("_typename"), &Field::Typename) - .Func(_SC("_tostring"), &Field::ToString) + .Func(_SC("_cmp"), &MySQLField::Cmp) + .SquirrelFunc(_SC("_typename"), &MySQLField::Typename) + .Func(_SC("_tostring"), &MySQLField::ToString) // Properties - .Prop(_SC("IsValid"), &Field::IsValid) - .Prop(_SC("References"), &Field::GetRefCount) - .Prop(_SC("Index"), &Field::GetIndex) - .Prop(_SC("ResultSet"), &Field::GetResultSet) - .Prop(_SC("Connection"), &Field::GetConnection) - .Prop(_SC("Bool"), &Field::GetBoolean) - .Prop(_SC("Boolean"), &Field::GetBoolean) - .Prop(_SC("Char"), &Field::GetChar) - .Prop(_SC("Integer"), &Field::GetInteger) - .Prop(_SC("Float"), &Field::GetFloat) - .Prop(_SC("int8_t"), &Field::GetInt8) - .Prop(_SC("uint8_t"), &Field::GetUint8) - .Prop(_SC("int16_t"), &Field::GetInt16) - .Prop(_SC("uint16_t"), &Field::GetUint16) - .Prop(_SC("int32_t"), &Field::GetInt32) - .Prop(_SC("uint32_t"), &Field::GetUint32) - .Prop(_SC("int64_t"), &Field::GetInt64) - .Prop(_SC("uint64_t"), &Field::GetUint64) - .Prop(_SC("float"), &Field::GetFloat32) - .Prop(_SC("double"), &Field::GetFloat64) - .Prop(_SC("String"), &Field::GetString) - .Prop(_SC("Buffer"), &Field::GetBuffer) - .Prop(_SC("Blob"), &Field::GetBlob) + .Prop(_SC("IsValid"), &MySQLField::IsValid) + .Prop(_SC("References"), &MySQLField::GetRefCount) + .Prop(_SC("Index"), &MySQLField::GetIndex) + .Prop(_SC("ResultSet"), &MySQLField::GetResultSet) + .Prop(_SC("Connection"), &MySQLField::GetConnection) + .Prop(_SC("Bool"), &MySQLField::GetBoolean) + .Prop(_SC("Boolean"), &MySQLField::GetBoolean) + .Prop(_SC("Char"), &MySQLField::GetChar) + .Prop(_SC("Integer"), &MySQLField::GetInteger) + .Prop(_SC("Float"), &MySQLField::GetFloat) + .Prop(_SC("int8_t"), &MySQLField::GetInt8) + .Prop(_SC("uint8_t"), &MySQLField::GetUint8) + .Prop(_SC("int16_t"), &MySQLField::GetInt16) + .Prop(_SC("uint16_t"), &MySQLField::GetUint16) + .Prop(_SC("int32_t"), &MySQLField::GetInt32) + .Prop(_SC("uint32_t"), &MySQLField::GetUint32) + .Prop(_SC("int64_t"), &MySQLField::GetInt64) + .Prop(_SC("uint64_t"), &MySQLField::GetUint64) + .Prop(_SC("float"), &MySQLField::GetFloat32) + .Prop(_SC("double"), &MySQLField::GetFloat64) + .Prop(_SC("String"), &MySQLField::GetString) + .Prop(_SC("Buffer"), &MySQLField::GetBuffer) + .Prop(_SC("Blob"), &MySQLField::GetBlob) // Member Methods - .Func(_SC("Release"), &Field::Release) + .Func(_SC("Release"), &MySQLField::Release) ); sqlns.Bind(_SC("ResultSet") - , Class< ResultSet >(sqlns.GetVM(), _SC("SqMySQLResultSet")) + , Class< MySQLResultSet >(sqlns.GetVM(), _SC("SqMySQLResultSet")) // Constructors .Ctor() - .Ctor< const ResultSet & >() + .Ctor< const MySQLResultSet & >() // Core Meta-methods - .Func(_SC("_cmp"), &ResultSet::Cmp) - .SquirrelFunc(_SC("_typename"), &ResultSet::Typename) - .Func(_SC("_tostring"), &ResultSet::ToString) + .Func(_SC("_cmp"), &MySQLResultSet::Cmp) + .SquirrelFunc(_SC("_typename"), &MySQLResultSet::Typename) + .Func(_SC("_tostring"), &MySQLResultSet::ToString) // Properties - .Prop(_SC("IsValid"), &ResultSet::IsValid) - .Prop(_SC("FieldNames"), &ResultSet::GetFieldNames) - .Prop(_SC("FieldsArray"), &ResultSet::GetFieldsArray) - .Prop(_SC("FieldsTable"), &ResultSet::GetFieldsTable) - .Prop(_SC("RowIndex"), &ResultSet::RowIndex) - .Prop(_SC("RowCount"), &ResultSet::RowCount) + .Prop(_SC("IsValid"), &MySQLResultSet::IsValid) + .Prop(_SC("FieldNames"), &MySQLResultSet::GetFieldNames) + .Prop(_SC("FieldsArray"), &MySQLResultSet::GetFieldsArray) + .Prop(_SC("FieldsTable"), &MySQLResultSet::GetFieldsTable) + .Prop(_SC("RowIndex"), &MySQLResultSet::RowIndex) + .Prop(_SC("RowCount"), &MySQLResultSet::RowCount) // Member Methods - .Func(_SC("Next"), &ResultSet::Next) - .Func(_SC("Step"), &ResultSet::Next) - .Func(_SC("SetRowIndex"), &ResultSet::SetRowIndex) - .Func(_SC("SetLongRowIndex"), &ResultSet::SetLongRowIndex) - .Func(_SC("Get"), &ResultSet::GetField) - .Func(_SC("GetField"), &ResultSet::GetField) - .Func(_SC("GetBool"), &ResultSet::GetBoolean) - .Func(_SC("GetBoolean"), &ResultSet::GetBoolean) - .Func(_SC("GetChar"), &ResultSet::GetChar) - .Func(_SC("GetInteger"), &ResultSet::GetInteger) - .Func(_SC("GetFloat"), &ResultSet::GetFloat) - .Func(_SC("GetInt8"), &ResultSet::GetInt8) - .Func(_SC("GetUint8"), &ResultSet::GetUint8) - .Func(_SC("GetInt16"), &ResultSet::GetInt16) - .Func(_SC("GetUint16"), &ResultSet::GetUint16) - .Func(_SC("GetInt32"), &ResultSet::GetInt32) - .Func(_SC("GetUint32"), &ResultSet::GetUint32) - .Func(_SC("GetInt64"), &ResultSet::GetInt64) - .Func(_SC("GetUint64"), &ResultSet::GetUint64) - .Func(_SC("GetFloat32"), &ResultSet::GetFloat32) - .Func(_SC("GetFloat64"), &ResultSet::GetFloat64) - .Func(_SC("GetString"), &ResultSet::GetString) - .Func(_SC("GetBuffer"), &ResultSet::GetBuffer) - .Func(_SC("GetBlob"), &ResultSet::GetBlob) - .Func(_SC("GetFieldsArray"), &ResultSet::FetchFieldsArray) - .Func(_SC("GetFieldsTable"), &ResultSet::FetchFieldsTable) + .Func(_SC("Next"), &MySQLResultSet::Next) + .Func(_SC("Step"), &MySQLResultSet::Next) + .Func(_SC("SetRowIndex"), &MySQLResultSet::SetRowIndex) + .Func(_SC("SetLongRowIndex"), &MySQLResultSet::SetLongRowIndex) + .Func(_SC("Get"), &MySQLResultSet::GetField) + .Func(_SC("GetField"), &MySQLResultSet::GetField) + .Func(_SC("GetBool"), &MySQLResultSet::GetBoolean) + .Func(_SC("GetBoolean"), &MySQLResultSet::GetBoolean) + .Func(_SC("GetChar"), &MySQLResultSet::GetChar) + .Func(_SC("GetInteger"), &MySQLResultSet::GetInteger) + .Func(_SC("GetFloat"), &MySQLResultSet::GetFloat) + .Func(_SC("GetInt8"), &MySQLResultSet::GetInt8) + .Func(_SC("GetUint8"), &MySQLResultSet::GetUint8) + .Func(_SC("GetInt16"), &MySQLResultSet::GetInt16) + .Func(_SC("GetUint16"), &MySQLResultSet::GetUint16) + .Func(_SC("GetInt32"), &MySQLResultSet::GetInt32) + .Func(_SC("GetUint32"), &MySQLResultSet::GetUint32) + .Func(_SC("GetInt64"), &MySQLResultSet::GetInt64) + .Func(_SC("GetUint64"), &MySQLResultSet::GetUint64) + .Func(_SC("GetFloat32"), &MySQLResultSet::GetFloat32) + .Func(_SC("GetFloat64"), &MySQLResultSet::GetFloat64) + .Func(_SC("GetString"), &MySQLResultSet::GetString) + .Func(_SC("GetBuffer"), &MySQLResultSet::GetBuffer) + .Func(_SC("GetBlob"), &MySQLResultSet::GetBlob) + .Func(_SC("GetFieldsArray"), &MySQLResultSet::FetchFieldsArray) + .Func(_SC("GetFieldsTable"), &MySQLResultSet::FetchFieldsTable) ); sqlns.Bind(_SC("Statement") - , Class< Statement >(sqlns.GetVM(), _SC("SqMySQLStatement")) + , Class< MySQLStatement >(sqlns.GetVM(), _SC("SqMySQLStatement")) // Constructors .Ctor() - .Ctor< const Statement & >() - .Ctor< const Connection &, const SQChar * >() + .Ctor< const MySQLStatement & >() + .Ctor< const MySQLConnection &, const SQChar * >() // Core Meta-methods - .Func(_SC("_cmp"), &Statement::Cmp) - .SquirrelFunc(_SC("_typename"), &Statement::Typename) - .Func(_SC("_tostring"), &Statement::ToString) + .Func(_SC("_cmp"), &MySQLStatement::Cmp) + .SquirrelFunc(_SC("_typename"), &MySQLStatement::Typename) + .Func(_SC("_tostring"), &MySQLStatement::ToString) // Properties - .Prop(_SC("IsValid"), &Statement::IsValid) - .Prop(_SC("Connection"), &Statement::GetConnection, &Statement::SetConnection) + .Prop(_SC("IsValid"), &MySQLStatement::IsValid) + .Prop(_SC("Connection"), &MySQLStatement::GetConnection, &MySQLStatement::SetConnection) // Member Methods - .Func(_SC("Execute"), &Statement::Execute) - .Func(_SC("Insert"), &Statement::Insert) - .Func(_SC("Query"), &Statement::Query) - .Func(_SC("SetInt8"), &Statement::SetInt8) - .Func(_SC("SetUint8"), &Statement::SetUint8) - .Func(_SC("SetInt16"), &Statement::SetInt16) - .Func(_SC("SetUint16"), &Statement::SetUint16) - .Func(_SC("SetInt32"), &Statement::SetInt32) - .Func(_SC("SetUint32"), &Statement::SetUint32) - .Func(_SC("SetInt64"), &Statement::SetInt64) - .Func(_SC("SetUint64"), &Statement::SetUint64) - .Func(_SC("SetSLongInt"), &Statement::SetSLongInt) - .Func(_SC("SetULongInt"), &Statement::SetULongInt) - .Func(_SC("SetInteger"), &Statement::SetInteger) - .Func(_SC("SetFloat32"), &Statement::SetFloat32) - .Func(_SC("SetFloat64"), &Statement::SetFloat64) - .Func(_SC("SetFloat"), &Statement::SetFloat) - .Func(_SC("SetBoolean"), &Statement::SetBoolean) - .Func(_SC("SetDate"), &Statement::SetDate) - .Func(_SC("SetTime"), &Statement::SetTime) - .Func(_SC("SetDatetime"), &Statement::SetDatetime) - .Func(_SC("SetString"), &Statement::SetString) - .Func(_SC("SetEnum"), &Statement::SetEnum) - .Func(_SC("SetSet"), &Statement::SetSet) - .Func(_SC("SetBlob"), &Statement::SetBlob) - .Func(_SC("SetData"), &Statement::SetData) - .Func(_SC("SetBuffer"), &Statement::SetData) - .Func(_SC("SetNull"), &Statement::SetNull) + .Func(_SC("Execute"), &MySQLStatement::Execute) + .Func(_SC("Insert"), &MySQLStatement::Insert) + .Func(_SC("Query"), &MySQLStatement::Query) + .Func(_SC("SetInt8"), &MySQLStatement::SetInt8) + .Func(_SC("SetUint8"), &MySQLStatement::SetUint8) + .Func(_SC("SetInt16"), &MySQLStatement::SetInt16) + .Func(_SC("SetUint16"), &MySQLStatement::SetUint16) + .Func(_SC("SetInt32"), &MySQLStatement::SetInt32) + .Func(_SC("SetUint32"), &MySQLStatement::SetUint32) + .Func(_SC("SetInt64"), &MySQLStatement::SetInt64) + .Func(_SC("SetUint64"), &MySQLStatement::SetUint64) + .Func(_SC("SetSLongInt"), &MySQLStatement::SetSLongInt) + .Func(_SC("SetULongInt"), &MySQLStatement::SetULongInt) + .Func(_SC("SetInteger"), &MySQLStatement::SetInteger) + .Func(_SC("SetFloat32"), &MySQLStatement::SetFloat32) + .Func(_SC("SetFloat64"), &MySQLStatement::SetFloat64) + .Func(_SC("SetFloat"), &MySQLStatement::SetFloat) + .Func(_SC("SetBoolean"), &MySQLStatement::SetBoolean) + .Func(_SC("SetDate"), &MySQLStatement::SetDate) + .Func(_SC("SetTime"), &MySQLStatement::SetTime) + .Func(_SC("SetDatetime"), &MySQLStatement::SetDatetime) + .Func(_SC("SetString"), &MySQLStatement::SetString) + .Func(_SC("SetEnum"), &MySQLStatement::SetEnum) + .Func(_SC("SetSet"), &MySQLStatement::SetSet) + .Func(_SC("SetBlob"), &MySQLStatement::SetBlob) + .Func(_SC("SetData"), &MySQLStatement::SetData) + .Func(_SC("SetBuffer"), &MySQLStatement::SetData) + .Func(_SC("SetNull"), &MySQLStatement::SetNull) ); RootTable(vm).Bind(_SC("MySQL"), sqlns); diff --git a/module/Library/MySQL.hpp b/module/Library/MySQL.hpp index 16b09c3c..8a616d90 100644 --- a/module/Library/MySQL.hpp +++ b/module/Library/MySQL.hpp @@ -11,6 +11,10 @@ #include "Library/Chrono/Time.hpp" #include "Library/Chrono/Timestamp.hpp" +// ------------------------------------------------------------------------------------------------ +#include "Poco/AutoPtr.h" +#include "Poco/Data/SessionImpl.h" + // ------------------------------------------------------------------------------------------------ #include #include @@ -53,24 +57,24 @@ namespace SqMod { /* ------------------------------------------------------------------------------------------------ * Forward declarations. */ -struct ConnHnd; -struct StmtHnd; -struct ResHnd; +struct MySQLConnHnd; +struct MySQLStmtHnd; +struct MySQLResHnd; // ------------------------------------------------------------------------------------------------ -class Account; +class MySQLAccount; class Column; -class Connection; -class ResultSet; -class Statement; -class Transaction; +class MySQLConnection; +class MySQLResultSet; +class MySQLStatement; +class MySQLTransaction; /* ------------------------------------------------------------------------------------------------ * Common typedefs. */ -typedef SharedPtr< ConnHnd > ConnRef; -typedef SharedPtr< StmtHnd > StmtRef; -typedef SharedPtr< ResHnd > ResRef; +typedef SharedPtr< MySQLConnHnd > MySQLConnRef; +typedef SharedPtr< MySQLStmtHnd > MySQLStmtRef; +typedef SharedPtr< MySQLResHnd > MySQLResRef; /* ------------------------------------------------------------------------------------------------ * Replicate the values of a script Date type to a database time type. @@ -201,7 +205,7 @@ template < > struct DbConvTo< char > /* ------------------------------------------------------------------------------------------------ * The structure that holds the data associated with a certain connection. */ -struct ConnHnd +struct MySQLConnHnd { public: @@ -228,6 +232,9 @@ public: uint32_t mErrNo; // Last received error string. String mErrStr; // Last received error message. + // -------------------------------------------------------------------------------------------- + Poco::AutoPtr< Poco::Data::SessionImpl > mSession; // POCO session when this connection comes from a pool. + // -------------------------------------------------------------------------------------------- uint16_t mPort; // Server port. String mHost; // Host address. @@ -254,12 +261,17 @@ public: /* -------------------------------------------------------------------------------------------- * Default constructor. */ - ConnHnd(); + MySQLConnHnd(); + + /* -------------------------------------------------------------------------------------------- + * Explicit constructor. + */ + explicit MySQLConnHnd(Poco::Data::SessionImpl * session); /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~ConnHnd(); + ~MySQLConnHnd(); /* -------------------------------------------------------------------------------------------- * Grab the current error in the connection handle. @@ -278,7 +290,7 @@ public: /* -------------------------------------------------------------------------------------------- * Create the connection handle. */ - void Create(const Account & acc); + void Create(const MySQLAccount & acc); /* -------------------------------------------------------------------------------------------- * Disconnect the managed connection handle. @@ -294,7 +306,7 @@ public: /* ------------------------------------------------------------------------------------------------ * The structure that holds the data associated with a certain bind point. */ -struct StmtBind // NOLINT(cppcoreguidelines-pro-type-member-init) +struct MySQLStmtBind // NOLINT(cppcoreguidelines-pro-type-member-init) { public: @@ -342,27 +354,27 @@ public: /* -------------------------------------------------------------------------------------------- * Default constructor. */ - StmtBind() = default; + MySQLStmtBind() = default; /* -------------------------------------------------------------------------------------------- * Copy constructor. (disabled) */ - StmtBind(const StmtBind & o) = delete; + MySQLStmtBind(const MySQLStmtBind & o) = delete; /* -------------------------------------------------------------------------------------------- * Move constructor. (disabled) */ - StmtBind(StmtBind && o) = delete; + MySQLStmtBind(MySQLStmtBind && o) = delete; /* -------------------------------------------------------------------------------------------- * Copy assignment operator. (disabled) */ - StmtBind & operator = (const StmtBind & o) = delete; + MySQLStmtBind & operator = (const MySQLStmtBind & o) = delete; /* -------------------------------------------------------------------------------------------- * Move assignment operator. (disabled) */ - StmtBind & operator = (StmtBind && o) = delete; + MySQLStmtBind & operator = (MySQLStmtBind && o) = delete; /* -------------------------------------------------------------------------------------------- * Retrieve the used buffer. @@ -389,7 +401,7 @@ public: /* ------------------------------------------------------------------------------------------------ * The structure that holds the data associated with a certain statement handle. */ -struct StmtHnd +struct MySQLStmtHnd { public: @@ -424,22 +436,22 @@ public: // -------------------------------------------------------------------------------------------- unsigned long mParams; // Number of parameters in the statement. - StmtBind * mBinds; // List of parameter binds. + MySQLStmtBind * mBinds; // List of parameter binds. BindType * mMyBinds; // List of parameter binds. // -------------------------------------------------------------------------------------------- - ConnRef mConnection; // Reference to the associated connection. + MySQLConnRef mConnection; // Reference to the associated connection. String mQuery; // The query string. /* -------------------------------------------------------------------------------------------- * Default constructor. */ - StmtHnd(); + MySQLStmtHnd(); /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~StmtHnd(); + ~MySQLStmtHnd(); /* -------------------------------------------------------------------------------------------- * Grab the current error in the associated statement handle. @@ -475,13 +487,13 @@ public: /* -------------------------------------------------------------------------------------------- * Create the actual statement. */ - void Create(const ConnRef & conn, const SQChar * query); + void Create(const MySQLConnRef & conn, const SQChar * query); }; /* ------------------------------------------------------------------------------------------------ * The structure that holds the data associated with a certain field. */ -struct ResBind // NOLINT(cppcoreguidelines-pro-type-member-init) +struct MySQLResBind // NOLINT(cppcoreguidelines-pro-type-member-init) { public: @@ -534,27 +546,27 @@ public: /* -------------------------------------------------------------------------------------------- * Default constructor. */ - ResBind() = default; + MySQLResBind() = default; /* -------------------------------------------------------------------------------------------- * Copy constructor. (disabled) */ - ResBind(const ResBind & o) = delete; + MySQLResBind(const MySQLResBind & o) = delete; /* -------------------------------------------------------------------------------------------- * Move constructor. (disabled) */ - ResBind(ResBind && o) = delete; + MySQLResBind(MySQLResBind && o) = delete; /* -------------------------------------------------------------------------------------------- * Copy assignment operator. (disabled) */ - ResBind & operator = (const ResBind & o) = delete; + MySQLResBind & operator = (const MySQLResBind & o) = delete; /* -------------------------------------------------------------------------------------------- * Move assignment operator. (disabled) */ - ResBind & operator = (ResBind && o) = delete; + MySQLResBind & operator = (MySQLResBind && o) = delete; /* -------------------------------------------------------------------------------------------- * Retrieve the used buffer. @@ -581,7 +593,7 @@ public: /* ------------------------------------------------------------------------------------------------ * The structure that holds the data associated with a certain result-set handle. */ -struct ResHnd +struct MySQLResHnd { public: @@ -619,26 +631,26 @@ public: uint32_t mFieldCount; // Number of fields in the result-set. unsigned long * mLengths; // Data length when the result-set came from a connection. FieldType * mFields; // Fields in the results set. - ResBind * mBinds; // Bind wrappers. + MySQLResBind * mBinds; // Bind wrappers. BindType * mMyBinds; // Bind points. RowType mRow; // Row data. // -------------------------------------------------------------------------------------------- - ConnRef mConnection; // Associated connection. - StmtRef mStatement; // Associated statement. - IndexMap mIndexes; // Field names and their associated index. + MySQLConnRef mConnection; // Associated connection. + MySQLStmtRef mStatement; // Associated statement. + IndexMap mIndexes; // MySQLField names and their associated index. public: /* -------------------------------------------------------------------------------------------- * Default constructor. */ - ResHnd(); + MySQLResHnd(); /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~ResHnd(); + ~MySQLResHnd(); /* -------------------------------------------------------------------------------------------- * Grab the current error in the associated statement or connection handle. @@ -677,14 +689,14 @@ public: uint32_t GetFieldIndex(const SQChar * name); /* -------------------------------------------------------------------------------------------- - * Create the result-set from a Connection. + * Create the result-set from a MySQLConnection. */ - void Create(const ConnRef & conn); + void Create(const MySQLConnRef & conn); /* -------------------------------------------------------------------------------------------- - * Create the result-set from a Statement. + * Create the result-set from a MySQLStatement. */ - void Create(const StmtRef & stmt); + void Create(const MySQLStmtRef & stmt); /* -------------------------------------------------------------------------------------------- * Returns the current position of the row cursor for the last Next(). @@ -711,7 +723,7 @@ public: /* ------------------------------------------------------------------------------------------------ * Helper class containing shared connection information to avoid repetition. */ -class Account +class MySQLAccount { public: @@ -750,8 +762,8 @@ public: /* -------------------------------------------------------------------------------------------- * Base Constructor. */ - Account(const SQChar * host, const SQChar * user) - : Account(host, user, _SC(""), _SC(""), 3306, _SC("")) + MySQLAccount(const SQChar * host, const SQChar * user) + : MySQLAccount(host, user, _SC(""), _SC(""), 3306, _SC("")) { /* ... */ } @@ -759,8 +771,8 @@ public: /* -------------------------------------------------------------------------------------------- * Base Constructor. */ - Account(const SQChar * host, const SQChar * user, const SQChar * pass) - : Account(host, user, pass, _SC(""), 3306, _SC("")) + MySQLAccount(const SQChar * host, const SQChar * user, const SQChar * pass) + : MySQLAccount(host, user, pass, _SC(""), 3306, _SC("")) { /* ... */ } @@ -768,8 +780,8 @@ public: /* -------------------------------------------------------------------------------------------- * Base Constructor. */ - Account(const SQChar * host, const SQChar * user, const SQChar * pass, const SQChar * name) - : Account(host, user, pass, name, 3306, _SC("")) + MySQLAccount(const SQChar * host, const SQChar * user, const SQChar * pass, const SQChar * name) + : MySQLAccount(host, user, pass, name, 3306, _SC("")) { /* ... */ } @@ -777,8 +789,8 @@ public: /* -------------------------------------------------------------------------------------------- * Base Constructor. */ - Account(const SQChar * host, const SQChar * user, const SQChar * pass, const SQChar * name, SQInteger port) - : Account(host, user, pass, name, port, _SC("")) + MySQLAccount(const SQChar * host, const SQChar * user, const SQChar * pass, const SQChar * name, SQInteger port) + : MySQLAccount(host, user, pass, name, port, _SC("")) { /* ... */ } @@ -786,37 +798,37 @@ public: /* -------------------------------------------------------------------------------------------- * Base Constructor. */ - Account(const SQChar * host, const SQChar * user, const SQChar * pass, const SQChar * name, SQInteger port, const SQChar * socket); + MySQLAccount(const SQChar * host, const SQChar * user, const SQChar * pass, const SQChar * name, SQInteger port, const SQChar * socket); /* -------------------------------------------------------------------------------------------- * Copy constructor. */ - Account(const Account & o) = default; + MySQLAccount(const MySQLAccount & o) = default; /* -------------------------------------------------------------------------------------------- * Move constructor. */ - Account(Account && o) = default; + MySQLAccount(MySQLAccount && o) = default; /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~Account() = default; + ~MySQLAccount() = default; /* -------------------------------------------------------------------------------------------- * Copy assignment operator. */ - Account & operator = (const Account & o) = default; + MySQLAccount & operator = (const MySQLAccount & o) = default; /* -------------------------------------------------------------------------------------------- * Move assignment operator. */ - Account & operator = (Account && o) = default; + MySQLAccount & operator = (MySQLAccount && o) = default; /* -------------------------------------------------------------------------------------------- * Used by the script engine to compare two instances of this type. */ - int32_t Cmp(const Account & o) const; + int32_t Cmp(const MySQLAccount & o) const; /* -------------------------------------------------------------------------------------------- * Used by the script engine to convert an instance of this type to a string. @@ -1107,18 +1119,18 @@ public: /* -------------------------------------------------------------------------------------------- * Create a connection with the current account information. */ - Connection Connect() const; + MySQLConnection Connect() const; }; /* ------------------------------------------------------------------------------------------------ * Allows management and interaction with a connection handle. */ -class Connection +class MySQLConnection { private: // -------------------------------------------------------------------------------------------- - ConnRef m_Handle{}; // Reference to the actual database connection. + MySQLConnRef m_Handle{}; // Reference to the actual database connection. protected: @@ -1144,18 +1156,18 @@ protected: * Validate the managed connection handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - const ConnRef & GetValid(const char * file, int32_t line) const; + const MySQLConnRef & GetValid(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ConnRef & GetValid() const; + SQMOD_NODISCARD const MySQLConnRef & GetValid() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the managed connection handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - const ConnRef & GetCreated(const char * file, int32_t line) const; + const MySQLConnRef & GetCreated(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ConnRef & GetCreated() const; + SQMOD_NODISCARD const MySQLConnRef & GetCreated() const; #endif // _DEBUG public: @@ -1163,13 +1175,13 @@ public: /* -------------------------------------------------------------------------------------------- * Default constructor. */ - Connection() = default; + MySQLConnection() = default; /* -------------------------------------------------------------------------------------------- * Base constructor. */ - explicit Connection(const Account & acc) - : m_Handle(new ConnHnd()) + explicit MySQLConnection(const MySQLAccount & acc) + : m_Handle(new MySQLConnHnd()) { m_Handle->Create(acc); } @@ -1177,7 +1189,7 @@ public: /* -------------------------------------------------------------------------------------------- * Base constructor. */ - explicit Connection(const ConnRef & conn) // NOLINT(modernize-pass-by-value) + explicit MySQLConnection(const MySQLConnRef & conn) // NOLINT(modernize-pass-by-value) : m_Handle(conn) { /* ... */ @@ -1186,27 +1198,27 @@ public: /* -------------------------------------------------------------------------------------------- * Copy constructor. */ - Connection(const Connection & o) = default; + MySQLConnection(const MySQLConnection & o) = default; /* -------------------------------------------------------------------------------------------- * Move constructor. */ - Connection(Connection && o) = default; + MySQLConnection(MySQLConnection && o) = default; /* -------------------------------------------------------------------------------------------- * Copy assignment operator. */ - Connection & operator = (const Connection & o) = default; + MySQLConnection & operator = (const MySQLConnection & o) = default; /* -------------------------------------------------------------------------------------------- * Move assignment operator. */ - Connection & operator = (Connection && o) = default; + MySQLConnection & operator = (MySQLConnection && o) = default; /* -------------------------------------------------------------------------------------------- * Used by the script engine to compare two instances of this type. */ - SQMOD_NODISCARD int32_t Cmp(const Connection & o) const + SQMOD_NODISCARD int32_t Cmp(const MySQLConnection & o) const { if (m_Handle.Get() == o.m_Handle.Get()) { @@ -1238,7 +1250,7 @@ public: /* -------------------------------------------------------------------------------------------- * Retrieve the associated connection handle. */ - SQMOD_NODISCARD const ConnRef & GetHandle() const + SQMOD_NODISCARD const MySQLConnRef & GetHandle() const { return m_Handle; } @@ -1456,7 +1468,7 @@ public: { // Attempt to toggle auto-commit if necessary if (SQMOD_GET_CREATED(*this)->mAutoCommit != toggle && - mysql_autocommit(m_Handle->mPtr, static_cast< StmtBind::BoolType >(toggle)) != 0) + mysql_autocommit(m_Handle->mPtr, static_cast< MySQLStmtBind::BoolType >(toggle)) != 0) { SQMOD_THROW_CURRENT(*m_Handle, "Cannot toggle auto-commit"); } @@ -1498,17 +1510,17 @@ public: /* -------------------------------------------------------------------------------------------- * Execute a query on the server. */ - ResultSet Query(const SQChar * query); + MySQLResultSet Query(const SQChar * query); /* -------------------------------------------------------------------------------------------- * Create a new statement on the managed connection. */ - SQMOD_NODISCARD Statement GetStatement(const SQChar * query); + SQMOD_NODISCARD MySQLStatement GetStatement(const SQChar * query); /* -------------------------------------------------------------------------------------------- * Create a new transaction on the managed connection. */ - //SQMOD_NODISCARD Transaction GetTransaction(); + //SQMOD_NODISCARD MySQLTransaction GetTransaction(); /* -------------------------------------------------------------------------------------------- * Escape unwanted characters from a given string. @@ -1534,16 +1546,16 @@ public: /* ------------------------------------------------------------------------------------------------ * Used to manage and interact with fields from result-sets. */ -class Field +class MySQLField { // -------------------------------------------------------------------------------------------- - friend class ResultSet; + friend class MySQLResultSet; private: // -------------------------------------------------------------------------------------------- uint32_t m_Index; // The actual index of the referenced field. - ResRef m_Handle; // Reference to the actual database result-set. + MySQLResRef m_Handle; // Reference to the actual database result-set. protected: @@ -1578,27 +1590,27 @@ protected: * Validate the associated result-set handle and field index, and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const ResRef & GetValid(const char * file, int32_t line) const; + SQMOD_NODISCARD const MySQLResRef & GetValid(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ResRef & GetValid() const; + SQMOD_NODISCARD const MySQLResRef & GetValid() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the associated result-set handle and field index, and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const ResRef & GetCreated(const char * file, int32_t line) const; + SQMOD_NODISCARD const MySQLResRef & GetCreated(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ResRef & GetCreated() const; + SQMOD_NODISCARD const MySQLResRef & GetCreated() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the associated result-set handle field index and row, and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const ResRef & GetStepped(const char * file, int32_t line) const; + SQMOD_NODISCARD const MySQLResRef & GetStepped(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ResRef & GetStepped() const; + SQMOD_NODISCARD const MySQLResRef & GetStepped() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- @@ -1641,7 +1653,7 @@ public: /* -------------------------------------------------------------------------------------------- * Default constructor (null). */ - Field() + MySQLField() : m_Index(INVALID_INDEX), m_Handle() { /* ... */ @@ -1650,7 +1662,7 @@ public: /* -------------------------------------------------------------------------------------------- * No field constructor. */ - explicit Field(const ResRef & rset) // NOLINT(modernize-pass-by-value) + explicit MySQLField(const MySQLResRef & rset) // NOLINT(modernize-pass-by-value) : m_Index(INVALID_INDEX), m_Handle(rset) { /* ... */ @@ -1659,7 +1671,7 @@ public: /* -------------------------------------------------------------------------------------------- * Index constructor. */ - Field(const ResRef & rset, uint32_t idx) // NOLINT(modernize-pass-by-value) + MySQLField(const MySQLResRef & rset, uint32_t idx) // NOLINT(modernize-pass-by-value) : m_Index(idx), m_Handle(rset) { SQMOD_VALIDATE_FIELD(*this, m_Index); @@ -1668,7 +1680,7 @@ public: /* -------------------------------------------------------------------------------------------- * Name constructor. */ - Field(const ResRef & rset, const SQChar * name) + MySQLField(const MySQLResRef & rset, const SQChar * name) : m_Index(rset ? rset->GetFieldIndex(name) : -1), m_Handle(rset) { SQMOD_VALIDATE_FIELD(*this, m_Index); @@ -1677,7 +1689,7 @@ public: /* -------------------------------------------------------------------------------------------- * Dynamic constructor. */ - Field(const ResRef & rset, const Object & field) // NOLINT(modernize-pass-by-value) + MySQLField(const MySQLResRef & rset, const Object & field) // NOLINT(modernize-pass-by-value) : m_Index(INVALID_INDEX), m_Handle(rset) { if (!m_Handle) @@ -1691,27 +1703,27 @@ public: /* -------------------------------------------------------------------------------------------- * Copy constructor. */ - Field(const Field & o) = default; + MySQLField(const MySQLField & o) = default; /* -------------------------------------------------------------------------------------------- * Move constructor. */ - Field(Field && o) = default; + MySQLField(MySQLField && o) = default; /* -------------------------------------------------------------------------------------------- * Copy assignment operator. */ - Field & operator = (const Field & o) = default; + MySQLField & operator = (const MySQLField & o) = default; /* -------------------------------------------------------------------------------------------- * Move assignment operator. */ - Field & operator = (Field && o) = default; + MySQLField & operator = (MySQLField && o) = default; /* -------------------------------------------------------------------------------------------- * Perform an equality comparison between two result-set field indexes. */ - bool operator == (const Field & o) const + bool operator == (const MySQLField & o) const { return (m_Index == o.m_Index); } @@ -1719,7 +1731,7 @@ public: /* -------------------------------------------------------------------------------------------- * Perform an inequality comparison between two result-set field indexes. */ - bool operator != (const Field & o) const + bool operator != (const MySQLField & o) const { return (m_Index != o.m_Index); } @@ -1735,7 +1747,7 @@ public: /* -------------------------------------------------------------------------------------------- * Used by the script engine to compare two instances of this type. */ - SQMOD_NODISCARD int32_t Cmp(const Field & o) const + SQMOD_NODISCARD int32_t Cmp(const MySQLField & o) const { if (m_Index == o.m_Index) { @@ -1901,12 +1913,12 @@ public: /* ------------------------------------------------------------------------------------------------ * Allows management and interaction with a result set handle. */ -class ResultSet +class MySQLResultSet { private: // -------------------------------------------------------------------------------------------- - ResRef m_Handle; // Reference to the actual database result-set. + MySQLResRef m_Handle; // Reference to the actual database result-set. protected: @@ -1941,27 +1953,27 @@ protected: * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const ResRef & GetValid(const char * file, int32_t line) const; + SQMOD_NODISCARD const MySQLResRef & GetValid(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ResRef & GetValid() const; + SQMOD_NODISCARD const MySQLResRef & GetValid() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const ResRef & GetCreated(const char * file, int32_t line) const; + SQMOD_NODISCARD const MySQLResRef & GetCreated(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ResRef & GetCreated() const; + SQMOD_NODISCARD const MySQLResRef & GetCreated() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the managed statement handle and row, and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const ResRef & GetStepped(const char * file, int32_t line) const; + SQMOD_NODISCARD const MySQLResRef & GetStepped(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ResRef & GetStepped() const; + SQMOD_NODISCARD const MySQLResRef & GetStepped() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- @@ -1978,26 +1990,26 @@ public: /* -------------------------------------------------------------------------------------------- * Default constructor. */ - ResultSet() + MySQLResultSet() : m_Handle() { /* ... */ } /* -------------------------------------------------------------------------------------------- - * Connection constructor. + * MySQLConnection constructor. */ - explicit ResultSet(const ConnRef & conn) - : m_Handle(new ResHnd()) + explicit MySQLResultSet(const MySQLConnRef & conn) + : m_Handle(new MySQLResHnd()) { m_Handle->Create(conn); } /* -------------------------------------------------------------------------------------------- - * Statement constructor. + * MySQLStatement constructor. */ - explicit ResultSet(const StmtRef & stmt) - : m_Handle(new ResHnd()) + explicit MySQLResultSet(const MySQLStmtRef & stmt) + : m_Handle(new MySQLResHnd()) { m_Handle->Create(stmt); } @@ -2005,7 +2017,7 @@ public: /* -------------------------------------------------------------------------------------------- * Handle constructor. */ - explicit ResultSet(ResRef hnd) + explicit MySQLResultSet(MySQLResRef hnd) : m_Handle(std::move(hnd)) { /* ... */ @@ -2014,32 +2026,32 @@ public: /* -------------------------------------------------------------------------------------------- * Copy constructor. */ - ResultSet(const ResultSet & o) = default; + MySQLResultSet(const MySQLResultSet & o) = default; /* -------------------------------------------------------------------------------------------- * Move constructor. */ - ResultSet(ResultSet && o) = default; + MySQLResultSet(MySQLResultSet && o) = default; /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~ResultSet() = default; + ~MySQLResultSet() = default; /* -------------------------------------------------------------------------------------------- * Copy assignment operator. */ - ResultSet & operator = (const ResultSet & o) = default; + MySQLResultSet & operator = (const MySQLResultSet & o) = default; /* -------------------------------------------------------------------------------------------- * Move assignment operator. */ - ResultSet & operator = (ResultSet && o) = default; + MySQLResultSet & operator = (MySQLResultSet && o) = default; /* -------------------------------------------------------------------------------------------- * Used by the script engine to compare two instances of this type. */ - SQMOD_NODISCARD int32_t Cmp(const ResultSet & o) const + SQMOD_NODISCARD int32_t Cmp(const MySQLResultSet & o) const { if (m_Handle.Get() == o.m_Handle.Get()) { @@ -2150,9 +2162,9 @@ public: /* -------------------------------------------------------------------------------------------- * Retrieve the field with the specified name or index. */ - SQMOD_NODISCARD Field GetField(const Object & field) const + SQMOD_NODISCARD MySQLField GetField(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field); + return MySQLField(SQMOD_GET_STEPPED(*this), field); } /* -------------------------------------------------------------------------------------------- @@ -2160,7 +2172,7 @@ public: */ SQMOD_NODISCARD bool GetBoolean(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetBoolean(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetBoolean(); } /* -------------------------------------------------------------------------------------------- @@ -2168,7 +2180,7 @@ public: */ SQMOD_NODISCARD SQChar GetChar(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetChar(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetChar(); } /* -------------------------------------------------------------------------------------------- @@ -2176,7 +2188,7 @@ public: */ SQMOD_NODISCARD SQInteger GetInteger(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetInteger(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetInteger(); } /* -------------------------------------------------------------------------------------------- @@ -2184,7 +2196,7 @@ public: */ SQMOD_NODISCARD SQFloat GetFloat(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetFloat(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetFloat(); } /* -------------------------------------------------------------------------------------------- @@ -2192,7 +2204,7 @@ public: */ SQMOD_NODISCARD SQInteger GetInt8(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetInt8(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetInt8(); } /* -------------------------------------------------------------------------------------------- @@ -2200,7 +2212,7 @@ public: */ SQMOD_NODISCARD SQInteger GetUint8(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetUint8(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetUint8(); } /* -------------------------------------------------------------------------------------------- @@ -2208,7 +2220,7 @@ public: */ SQMOD_NODISCARD SQInteger GetInt16(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetInt16(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetInt16(); } /* -------------------------------------------------------------------------------------------- @@ -2216,7 +2228,7 @@ public: */ SQMOD_NODISCARD SQInteger GetUint16(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetUint16(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetUint16(); } /* -------------------------------------------------------------------------------------------- @@ -2224,7 +2236,7 @@ public: */ SQMOD_NODISCARD SQInteger GetInt32(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetInt32(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetInt32(); } /* -------------------------------------------------------------------------------------------- @@ -2232,7 +2244,7 @@ public: */ SQMOD_NODISCARD SQInteger GetUint32(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetUint32(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetUint32(); } /* -------------------------------------------------------------------------------------------- @@ -2240,7 +2252,7 @@ public: */ SQMOD_NODISCARD Object GetInt64(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetInt64(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetInt64(); } /* -------------------------------------------------------------------------------------------- @@ -2248,7 +2260,7 @@ public: */ SQMOD_NODISCARD Object GetUint64(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetUint64(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetUint64(); } /* -------------------------------------------------------------------------------------------- @@ -2256,7 +2268,7 @@ public: */ SQMOD_NODISCARD SQFloat GetFloat32(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetFloat32(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetFloat32(); } /* -------------------------------------------------------------------------------------------- @@ -2264,7 +2276,7 @@ public: */ SQMOD_NODISCARD SQFloat GetFloat64(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetFloat64(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetFloat64(); } /* -------------------------------------------------------------------------------------------- @@ -2272,7 +2284,7 @@ public: */ SQMOD_NODISCARD Object GetString(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetString(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetString(); } /* -------------------------------------------------------------------------------------------- @@ -2280,7 +2292,7 @@ public: */ SQMOD_NODISCARD Object GetBuffer(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetBuffer(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetBuffer(); } /* -------------------------------------------------------------------------------------------- @@ -2288,19 +2300,19 @@ public: */ SQMOD_NODISCARD Object GetBlob(const Object & field) const { - return Field(SQMOD_GET_STEPPED(*this), field).GetBlob(); + return MySQLField(SQMOD_GET_STEPPED(*this), field).GetBlob(); } }; /* ------------------------------------------------------------------------------------------------ * Allows management and interaction with a statement handle. */ -class Statement +class MySQLStatement { private: // -------------------------------------------------------------------------------------------- - StmtRef m_Handle; // Reference to the actual database statement. + MySQLStmtRef m_Handle; // Reference to the actual database statement. protected: @@ -2326,18 +2338,18 @@ protected: * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - const StmtRef & GetValid(const char * file, int32_t line) const; + const MySQLStmtRef & GetValid(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const StmtRef & GetValid() const; + SQMOD_NODISCARD const MySQLStmtRef & GetValid() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - const StmtRef & GetCreated(const char * file, int32_t line) const; + const MySQLStmtRef & GetCreated(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const StmtRef & GetCreated() const; + SQMOD_NODISCARD const MySQLStmtRef & GetCreated() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- @@ -2354,7 +2366,7 @@ public: /* -------------------------------------------------------------------------------------------- * Default constructor. */ - Statement() + MySQLStatement() : m_Handle() { /* ... */ @@ -2363,8 +2375,8 @@ public: /* -------------------------------------------------------------------------------------------- * Construct a statement under the specified connection using the specified string. */ - Statement(const ConnRef & connection, const SQChar * query) - : m_Handle(new StmtHnd()) + MySQLStatement(const MySQLConnRef & connection, const SQChar * query) + : m_Handle(new MySQLStmtHnd()) { m_Handle->Create(connection, query); } @@ -2372,32 +2384,32 @@ public: /* -------------------------------------------------------------------------------------------- * Construct a statement under the specified connection using the specified string. */ - Statement(const Connection & connection, const SQChar * query); + MySQLStatement(const MySQLConnection & connection, const SQChar * query); /* -------------------------------------------------------------------------------------------- * Copy constructor. */ - Statement(const Statement & o) = default; + MySQLStatement(const MySQLStatement & o) = default; /* -------------------------------------------------------------------------------------------- * Move constructor. */ - Statement(Statement && o) = default; + MySQLStatement(MySQLStatement && o) = default; /* -------------------------------------------------------------------------------------------- * Copy assignment operator. */ - Statement & operator = (const Statement & o) = default; + MySQLStatement & operator = (const MySQLStatement & o) = default; /* -------------------------------------------------------------------------------------------- * Move assignment operator. */ - Statement & operator = (Statement && o) = default; + MySQLStatement & operator = (MySQLStatement && o) = default; /* -------------------------------------------------------------------------------------------- * Used by the script engine to compare two instances of this type. */ - SQMOD_NODISCARD int32_t Cmp(const Statement & o) const + SQMOD_NODISCARD int32_t Cmp(const MySQLStatement & o) const { if (m_Handle.Get() == o.m_Handle.Get()) { @@ -2435,7 +2447,7 @@ public: /* -------------------------------------------------------------------------------------------- * Retrieve the associated connection handle. */ - SQMOD_NODISCARD const StmtRef & GetHandle() const + SQMOD_NODISCARD const MySQLStmtRef & GetHandle() const { return m_Handle; } @@ -2451,12 +2463,12 @@ public: /* -------------------------------------------------------------------------------------------- * Retrieve the currently associated statement connection. */ - SQMOD_NODISCARD Connection GetConnection() const; + SQMOD_NODISCARD MySQLConnection GetConnection() const; /* -------------------------------------------------------------------------------------------- * Modify the currently associated statement connection. */ - void SetConnection(const Connection & conn); + void SetConnection(const MySQLConnection & conn); /* -------------------------------------------------------------------------------------------- * Execute the statement. @@ -2471,7 +2483,7 @@ public: /* -------------------------------------------------------------------------------------------- * Execute the statement. */ - SQMOD_NODISCARD ResultSet Query(); + SQMOD_NODISCARD MySQLResultSet Query(); /* -------------------------------------------------------------------------------------------- * Assign a signed 8bit integer to a parameter. @@ -2597,73 +2609,73 @@ public: /* ------------------------------------------------------------------------------------------------ * ... */ -struct Parameter +struct MySQLParameter { /* -------------------------------------------------------------------------------------------- * Default constructor. */ - Parameter() = default; + MySQLParameter() = default; /* -------------------------------------------------------------------------------------------- * Copy constructor. */ - Parameter(const Parameter & o) = default; + MySQLParameter(const MySQLParameter & o) = default; /* -------------------------------------------------------------------------------------------- * Move constructor. */ - Parameter(Parameter && o) = default; + MySQLParameter(MySQLParameter && o) = default; /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~Parameter() = default; + ~MySQLParameter() = default; /* -------------------------------------------------------------------------------------------- * Copy assignment operator. */ - Parameter & operator = (const Parameter & o) = default; + MySQLParameter & operator = (const MySQLParameter & o) = default; /* -------------------------------------------------------------------------------------------- * Move assignment operator. */ - Parameter & operator = (Parameter && o) = default; + MySQLParameter & operator = (MySQLParameter && o) = default; }; /* ------------------------------------------------------------------------------------------------ * ... */ -struct Transaction +struct MySQLTransaction { /* -------------------------------------------------------------------------------------------- * Default constructor. */ - Transaction() = default; + MySQLTransaction() = default; /* -------------------------------------------------------------------------------------------- * Copy constructor. (disabled) */ - Transaction(const Transaction & o) = delete; + MySQLTransaction(const MySQLTransaction & o) = delete; /* -------------------------------------------------------------------------------------------- * Move constructor. (disabled) */ - Transaction(Transaction && o) = default; + MySQLTransaction(MySQLTransaction && o) = default; /* -------------------------------------------------------------------------------------------- * Destructor. */ - ~Transaction() = default; + ~MySQLTransaction() = default; /* -------------------------------------------------------------------------------------------- * Copy assignment operator. (disabled) */ - Transaction & operator = (const Transaction & o) = delete; + MySQLTransaction & operator = (const MySQLTransaction & o) = delete; /* -------------------------------------------------------------------------------------------- * Move assignment operator. (disabled) */ - Transaction & operator = (Transaction && o) = default; + MySQLTransaction & operator = (MySQLTransaction && o) = default; }; } // Namespace:: SqMod diff --git a/module/Library/SQLite.cpp b/module/Library/SQLite.cpp index 85508b28..d9f1ddb7 100644 --- a/module/Library/SQLite.cpp +++ b/module/Library/SQLite.cpp @@ -362,6 +362,15 @@ static const EnumElement g_MainEnum[] = { {_SC("WARNING_AUTOINDEX"), SQLITE_WARNING_AUTOINDEX} }; +// ------------------------------------------------------------------------------------------------ +LightObj GteSQLiteFromSession(Poco::Data::SessionImpl * session) +{ + // Create a reference counted connection handle instance + SQLiteConnRef ref(new SQLiteConnHnd(session)); + // Transform it into a connection instance and yield it as a script object + return LightObj(SqTypeIdentity< SQLiteConnection >{}, SqVM(), ref); +} + // ------------------------------------------------------------------------------------------------ static inline bool IsDigitsOnly(const SQChar * str) { @@ -374,13 +383,13 @@ static inline bool IsDigitsOnly(const SQChar * str) } // ------------------------------------------------------------------------------------------------ -Object GetConnectionObj(const ConnRef & conn) +Object GetConnectionObj(const SQLiteConnRef & conn) { return Object(new SQLiteConnection(conn)); } // ------------------------------------------------------------------------------------------------ -Object GetStatementObj(const StmtRef & stmt) +Object GetStatementObj(const SQLiteStmtRef & stmt) { return Object(new SQLiteStatement(stmt)); } @@ -602,6 +611,7 @@ SQLiteConnHnd::SQLiteConnHnd() , mFlags(0) , mName() , mVFS() + , mSession() , mMemory(false) , mTrace(false) , mProfile(false) @@ -609,6 +619,15 @@ SQLiteConnHnd::SQLiteConnHnd() /* ... */ } +// ------------------------------------------------------------------------------------------------ +SQLiteConnHnd::SQLiteConnHnd(Poco::Data::SessionImpl * session) + : SQLiteConnHnd() +{ + mSession.assign(session); + // Retrieve the internal handle property + mPtr = Poco::AnyCast< sqlite3 * >(session->getProperty("handle")); +} + // ------------------------------------------------------------------------------------------------ SQLiteConnHnd::~SQLiteConnHnd() { @@ -619,10 +638,17 @@ SQLiteConnHnd::~SQLiteConnHnd() Flush(static_cast(mQueue.size()), NullObject(), NullFunction()); // NOTE: Should we call sqlite3_interrupt(...) before closing? // Attempt to close the database - if ((sqlite3_close(mPtr)) != SQLITE_OK) + // If this connection is a pooled session then let it clean itself up + if (mSession.isNull() && (sqlite3_close(mPtr)) != SQLITE_OK) { LogErr("Unable to close SQLite connection [%s]", sqlite3_errmsg(mPtr)); } + else + { + mSession.reset(); + } + // Prevent further use of this connection + mPtr = nullptr; } } @@ -751,7 +777,7 @@ int32_t SQLiteConnHnd::Flush(uint32_t num, Object & env, Function & func) } // ------------------------------------------------------------------------------------------------ -SQLiteStmtHnd::SQLiteStmtHnd(ConnRef conn) +SQLiteStmtHnd::SQLiteStmtHnd(SQLiteConnRef conn) : mPtr(nullptr) , mStatus(SQLITE_OK) , mConn(std::move(conn)) @@ -942,13 +968,13 @@ void SQLiteConnection::ValidateCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ConnRef & SQLiteConnection::GetValid(const char * file, int32_t line) const +const SQLiteConnRef & SQLiteConnection::GetValid(const char * file, int32_t line) const { Validate(file, line); return m_Handle; } #else -const ConnRef & SQLiteConnection::GetValid() const +const SQLiteConnRef & SQLiteConnection::GetValid() const { Validate(); return m_Handle; @@ -957,13 +983,13 @@ const ConnRef & SQLiteConnection::GetValid() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const ConnRef & SQLiteConnection::GetCreated(const char * file, int32_t line) const +const SQLiteConnRef & SQLiteConnection::GetCreated(const char * file, int32_t line) const { ValidateCreated(file, line); return m_Handle; } #else -const ConnRef & SQLiteConnection::GetCreated() const +const SQLiteConnRef & SQLiteConnection::GetCreated() const { ValidateCreated(); return m_Handle; @@ -976,7 +1002,7 @@ void SQLiteConnection::Open(StackStrF & name) // Should we create a connection handle? if (!m_Handle) { - m_Handle = ConnRef(new SQLiteConnHnd()); + m_Handle = SQLiteConnRef(new SQLiteConnHnd()); } // Make sure another database isn't opened if (SQMOD_GET_VALID(*this)->mPtr != nullptr) @@ -996,7 +1022,7 @@ void SQLiteConnection::Open(StackStrF & name, int32_t flags) // Should we create a connection handle? if (!m_Handle) { - m_Handle = ConnRef(new SQLiteConnHnd()); + m_Handle = SQLiteConnRef(new SQLiteConnHnd()); } // Make sure another database isn't opened if (SQMOD_GET_VALID(*this)->mPtr != nullptr) @@ -1013,7 +1039,7 @@ void SQLiteConnection::Open(StackStrF & name, int32_t flags, StackStrF & vfs) // Should we create a connection handle? if (!m_Handle) { - m_Handle = ConnRef(new SQLiteConnHnd()); + m_Handle = SQLiteConnRef(new SQLiteConnHnd()); } // Make sure another database isn't opened if (SQMOD_GET_VALID(*this)->mPtr != nullptr) @@ -1295,13 +1321,13 @@ void SQLiteParameter::ValidateCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const StmtRef & SQLiteParameter::GetValid(const char * file, int32_t line) const +const SQLiteStmtRef & SQLiteParameter::GetValid(const char * file, int32_t line) const { Validate(file, line); return m_Handle; } #else -const StmtRef & SQLiteParameter::GetValid() const +const SQLiteStmtRef & SQLiteParameter::GetValid() const { Validate(); return m_Handle; @@ -1310,13 +1336,13 @@ const StmtRef & SQLiteParameter::GetValid() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const StmtRef & SQLiteParameter::GetCreated(const char * file, int32_t line) const +const SQLiteStmtRef & SQLiteParameter::GetCreated(const char * file, int32_t line) const { ValidateCreated(file, line); return m_Handle; } #else -const StmtRef & SQLiteParameter::GetCreated() const +const SQLiteStmtRef & SQLiteParameter::GetCreated() const { ValidateCreated(); return m_Handle; @@ -2001,13 +2027,13 @@ void SQLiteColumn::ValidateCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const StmtRef & SQLiteColumn::GetValid(const char * file, int32_t line) const +const SQLiteStmtRef & SQLiteColumn::GetValid(const char * file, int32_t line) const { Validate(file, line); return m_Handle; } #else -const StmtRef & SQLiteColumn::GetValid() const +const SQLiteStmtRef & SQLiteColumn::GetValid() const { Validate(); return m_Handle; @@ -2016,13 +2042,13 @@ const StmtRef & SQLiteColumn::GetValid() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const StmtRef & SQLiteColumn::GetCreated(const char * file, int32_t line) const +const SQLiteStmtRef & SQLiteColumn::GetCreated(const char * file, int32_t line) const { ValidateCreated(file, line); return m_Handle; } #else -const StmtRef & SQLiteColumn::GetCreated() const +const SQLiteStmtRef & SQLiteColumn::GetCreated() const { ValidateCreated(); return m_Handle; @@ -2454,13 +2480,13 @@ void SQLiteStatement::ValidateCreated() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const StmtRef & SQLiteStatement::GetValid(const char * file, int32_t line) const +const SQLiteStmtRef & SQLiteStatement::GetValid(const char * file, int32_t line) const { Validate(file, line); return m_Handle; } #else -const StmtRef & SQLiteStatement::GetValid() const +const SQLiteStmtRef & SQLiteStatement::GetValid() const { Validate(); return m_Handle; @@ -2469,13 +2495,13 @@ const StmtRef & SQLiteStatement::GetValid() const // ------------------------------------------------------------------------------------------------ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) -const StmtRef & SQLiteStatement::GetCreated(const char * file, int32_t line) const +const SQLiteStmtRef & SQLiteStatement::GetCreated(const char * file, int32_t line) const { ValidateCreated(file, line); return m_Handle; } #else -const StmtRef & SQLiteStatement::GetCreated() const +const SQLiteStmtRef & SQLiteStatement::GetCreated() const { ValidateCreated(); return m_Handle; @@ -2824,7 +2850,7 @@ SQLiteTransaction::SQLiteTransaction(const SQLiteConnection & db) } // ------------------------------------------------------------------------------------------------ -SQLiteTransaction::SQLiteTransaction(ConnRef db) +SQLiteTransaction::SQLiteTransaction(SQLiteConnRef db) : m_Handle(std::move(db)), m_Committed(false) { // Was the specified database connection valid? diff --git a/module/Library/SQLite.hpp b/module/Library/SQLite.hpp index e5ea17d6..a5083908 100644 --- a/module/Library/SQLite.hpp +++ b/module/Library/SQLite.hpp @@ -10,6 +10,10 @@ #include "Library/Chrono/Time.hpp" #include "Library/Chrono/Timestamp.hpp" +// ------------------------------------------------------------------------------------------------ +#include "Poco/AutoPtr.h" +#include "Poco/Data/SessionImpl.h" + // ------------------------------------------------------------------------------------------------ #include #include @@ -78,18 +82,18 @@ struct SQLiteStmtHnd; /* ------------------------------------------------------------------------------------------------ * Common typedefs. */ -typedef SharedPtr< SQLiteConnHnd > ConnRef; -typedef SharedPtr< SQLiteStmtHnd > StmtRef; +typedef SharedPtr< SQLiteConnHnd > SQLiteConnRef; +typedef SharedPtr< SQLiteStmtHnd > SQLiteStmtRef; /* ------------------------------------------------------------------------------------------------ * Obtain a script object from a connection handle. (meant to avoid having to include the header) */ -Object GetConnectionObj(const ConnRef & conn); +Object GetConnectionObj(const SQLiteConnRef & conn); /* ------------------------------------------------------------------------------------------------ * Obtain a script object from a statement handle. (meant to avoid having to include the header) */ -Object GetStatementObj(const StmtRef & stmt); +Object GetStatementObj(const SQLiteStmtRef & stmt); /* ------------------------------------------------------------------------------------------------ * Tests if a certain query string is empty. @@ -178,6 +182,9 @@ public: String mName; // The specified name to be used as the database file. String mVFS; // The specified virtual file system. + // -------------------------------------------------------------------------------------------- + Poco::AutoPtr< Poco::Data::SessionImpl > mSession; // POCO session when this connection comes from a pool. + // -------------------------------------------------------------------------------------------- bool mMemory; // Whether the database exists in memory and not disk. bool mTrace; // Whether tracing was activated on the database. @@ -188,6 +195,11 @@ public: */ SQLiteConnHnd(); + /* -------------------------------------------------------------------------------------------- + * Explicit constructor. + */ + explicit SQLiteConnHnd(Poco::Data::SessionImpl * session); + /* -------------------------------------------------------------------------------------------- * Copy constructor. (disabled) */ @@ -286,7 +298,7 @@ public: int32_t mStatus; // The last status code of this connection handle. // -------------------------------------------------------------------------------------------- - ConnRef mConn; // The handle to the associated database connection. + SQLiteConnRef mConn; // The handle to the associated database connection. // -------------------------------------------------------------------------------------------- String mQuery; // The query string used to create this statement. @@ -303,7 +315,7 @@ public: /* -------------------------------------------------------------------------------------------- * Default constructor. */ - explicit SQLiteStmtHnd(ConnRef conn); + explicit SQLiteStmtHnd(SQLiteConnRef conn); /* -------------------------------------------------------------------------------------------- * Copy constructor. (disabled) @@ -385,7 +397,7 @@ class SQLiteConnection private: // -------------------------------------------------------------------------------------------- - ConnRef m_Handle; // Reference to the managed connection. + SQLiteConnRef m_Handle; // Reference to the managed connection. protected: @@ -421,18 +433,18 @@ protected: * Validate the managed connection handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const ConnRef & GetValid(const char * file, int32_t line) const; + SQMOD_NODISCARD const SQLiteConnRef & GetValid(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ConnRef & GetValid() const; + SQMOD_NODISCARD const SQLiteConnRef & GetValid() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the managed connection handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const ConnRef & GetCreated(const char * file, int32_t line) const; + SQMOD_NODISCARD const SQLiteConnRef & GetCreated(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const ConnRef & GetCreated() const; + SQMOD_NODISCARD const SQLiteConnRef & GetCreated() const; #endif // _DEBUG public: @@ -479,7 +491,7 @@ public: /* -------------------------------------------------------------------------------------------- * Direct handle constructor. */ - explicit SQLiteConnection(ConnRef c) + explicit SQLiteConnection(SQLiteConnRef c) : m_Handle(std::move(c)) { /* ... */ @@ -548,7 +560,7 @@ public: /* -------------------------------------------------------------------------------------------- * Retrieve the associated connection handle. */ - SQMOD_NODISCARD const ConnRef & GetHandle() const + SQMOD_NODISCARD const SQLiteConnRef & GetHandle() const { return m_Handle; } @@ -858,7 +870,7 @@ private: // -------------------------------------------------------------------------------------------- int32_t m_Index{0}; // The index of the managed parameter. - StmtRef m_Handle{}; // Reference to the managed statement. + SQLiteStmtRef m_Handle{}; // Reference to the managed statement. protected: @@ -884,18 +896,18 @@ protected: * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const StmtRef & GetValid(const char * file, int32_t line) const; + SQMOD_NODISCARD const SQLiteStmtRef & GetValid(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const StmtRef & GetValid() const; + SQMOD_NODISCARD const SQLiteStmtRef & GetValid() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const StmtRef & GetCreated(const char * file, int32_t line) const; + SQMOD_NODISCARD const SQLiteStmtRef & GetCreated(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const StmtRef & GetCreated() const; + SQMOD_NODISCARD const SQLiteStmtRef & GetCreated() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- @@ -943,7 +955,7 @@ public: /* -------------------------------------------------------------------------------------------- * No parameter constructor. */ - explicit SQLiteParameter(StmtRef stmt) + explicit SQLiteParameter(SQLiteStmtRef stmt) : m_Index(0), m_Handle(std::move(stmt)) { /* ... */ @@ -952,7 +964,7 @@ public: /* -------------------------------------------------------------------------------------------- * Index constructor. */ - SQLiteParameter(StmtRef stmt, int32_t idx) + SQLiteParameter(SQLiteStmtRef stmt, int32_t idx) : m_Index(idx), m_Handle(std::move(stmt)) { SQMOD_VALIDATE_PARAM(*this, m_Index); @@ -961,7 +973,7 @@ public: /* -------------------------------------------------------------------------------------------- * Name constructor. */ - SQLiteParameter(const StmtRef & stmt, const SQChar * name) + SQLiteParameter(const SQLiteStmtRef & stmt, const SQChar * name) : m_Index(stmt ? sqlite3_bind_parameter_index(stmt->mPtr, name) : 0), m_Handle(stmt) { SQMOD_VALIDATE_PARAM(*this, m_Index); @@ -970,7 +982,7 @@ public: /* -------------------------------------------------------------------------------------------- * Dynamic constructor. */ - SQLiteParameter(StmtRef stmt, const Object & param) + SQLiteParameter(SQLiteStmtRef stmt, const Object & param) : m_Index(0), m_Handle(std::move(stmt)) { if (!m_Handle) @@ -1252,7 +1264,7 @@ private: // -------------------------------------------------------------------------------------------- int32_t m_Index{-1}; // The index of the managed column. - StmtRef m_Handle{}; // The statement where the column exist. + SQLiteStmtRef m_Handle{}; // The statement where the column exist. protected: @@ -1278,18 +1290,18 @@ protected: * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const StmtRef & GetValid(const char * file, int32_t line) const; + SQMOD_NODISCARD const SQLiteStmtRef & GetValid(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const StmtRef & GetValid() const; + SQMOD_NODISCARD const SQLiteStmtRef & GetValid() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const StmtRef & GetCreated(const char * file, int32_t line) const; + SQMOD_NODISCARD const SQLiteStmtRef & GetCreated(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const StmtRef & GetCreated() const; + SQMOD_NODISCARD const SQLiteStmtRef & GetCreated() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- @@ -1346,7 +1358,7 @@ public: /* -------------------------------------------------------------------------------------------- * No column constructor. */ - explicit SQLiteColumn(StmtRef stmt) + explicit SQLiteColumn(SQLiteStmtRef stmt) : m_Index(-1), m_Handle(std::move(stmt)) { /* ... */ @@ -1355,7 +1367,7 @@ public: /* -------------------------------------------------------------------------------------------- * Index constructor. */ - SQLiteColumn(StmtRef stmt, int32_t idx) + SQLiteColumn(SQLiteStmtRef stmt, int32_t idx) : m_Index(idx), m_Handle(std::move(stmt)) { SQMOD_VALIDATE_COLUMN(*this, m_Index); @@ -1364,7 +1376,7 @@ public: /* -------------------------------------------------------------------------------------------- * Name constructor. */ - SQLiteColumn(const StmtRef & stmt, const SQChar * name) + SQLiteColumn(const SQLiteStmtRef & stmt, const SQChar * name) : m_Index(stmt ? stmt->GetColumnIndex(name) : -1), m_Handle(stmt) { SQMOD_VALIDATE_COLUMN(*this, m_Index); @@ -1373,7 +1385,7 @@ public: /* -------------------------------------------------------------------------------------------- * Dynamic constructor. */ - SQLiteColumn(StmtRef stmt, const Object & column) + SQLiteColumn(SQLiteStmtRef stmt, const Object & column) : m_Index(-1), m_Handle(std::move(stmt)) { if (!m_Handle) @@ -1573,7 +1585,7 @@ class SQLiteStatement private: // -------------------------------------------------------------------------------------------- - StmtRef m_Handle; // Reference to the managed statement. + SQLiteStmtRef m_Handle; // Reference to the managed statement. protected: @@ -1599,18 +1611,18 @@ protected: * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const StmtRef & GetValid(const char * file, int32_t line) const; + SQMOD_NODISCARD const SQLiteStmtRef & GetValid(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const StmtRef & GetValid() const; + SQMOD_NODISCARD const SQLiteStmtRef & GetValid() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- * Validate the managed statement handle and throw an error if invalid. */ #if defined(_DEBUG) || defined(SQMOD_EXCEPTLOC) - SQMOD_NODISCARD const StmtRef & GetCreated(const char * file, int32_t line) const; + SQMOD_NODISCARD const SQLiteStmtRef & GetCreated(const char * file, int32_t line) const; #else - SQMOD_NODISCARD const StmtRef & GetCreated() const; + SQMOD_NODISCARD const SQLiteStmtRef & GetCreated() const; #endif // _DEBUG /* -------------------------------------------------------------------------------------------- @@ -1654,7 +1666,7 @@ public: /* -------------------------------------------------------------------------------------------- * Construct a statement under the specified connection using the specified string. */ - SQLiteStatement(const ConnRef & connection, StackStrF & query) + SQLiteStatement(const SQLiteConnRef & connection, StackStrF & query) : m_Handle(new SQLiteStmtHnd(connection)) { SQMOD_GET_VALID(*this)->Create(query.mPtr, query.mLen); @@ -1668,7 +1680,7 @@ public: /* -------------------------------------------------------------------------------------------- * Direct handle constructor. */ - explicit SQLiteStatement(StmtRef s) + explicit SQLiteStatement(SQLiteStmtRef s) : m_Handle(std::move(s)) { /* ... */ @@ -1737,7 +1749,7 @@ public: /* -------------------------------------------------------------------------------------------- * Retrieve the associated statement handle. */ - SQMOD_NODISCARD const StmtRef & GetHandle() const + SQMOD_NODISCARD const SQLiteStmtRef & GetHandle() const { return m_Handle; } @@ -2436,7 +2448,7 @@ public: /* -------------------------------------------------------------------------------------------- * Construct using the direct connection handle. */ - explicit SQLiteTransaction(ConnRef db); + explicit SQLiteTransaction(SQLiteConnRef db); /* -------------------------------------------------------------------------------------------- * Copy constructor. (disabled) @@ -2495,7 +2507,7 @@ public: private: // -------------------------------------------------------------------------------------------- - ConnRef m_Handle{}; // The database connection handle where the transaction began. + SQLiteConnRef m_Handle{}; // The database connection handle where the transaction began. bool m_Committed{false}; // Whether changes were successfully committed to the database. }; diff --git a/module/PocoLib/Data.cpp b/module/PocoLib/Data.cpp index 53a6af6a..b2476652 100644 --- a/module/PocoLib/Data.cpp +++ b/module/PocoLib/Data.cpp @@ -1,5 +1,6 @@ // ------------------------------------------------------------------------------------------------ #include "PocoLib/Data.hpp" +#include "Poco/Data/SessionImpl.h" // ------------------------------------------------------------------------------------------------ #include @@ -470,6 +471,32 @@ SqDataStatement & SqDataStatement::Into_(LightObj & obj, LightObj & def) return *this; } +// ------------------------------------------------------------------------------------------------ +extern LightObj GteSQLiteFromSession(Poco::Data::SessionImpl * session); +extern LightObj GteMySQLFromSession(Poco::Data::SessionImpl * session); + +// ------------------------------------------------------------------------------------------------ +LightObj SqDataSessionPool::GetSq() +{ + auto session = get(); + auto * session_impl = session.impl(); + auto & connector = session_impl->connectorName(); + // Is this a SQLite session? + if (connector == "sqlite") + { + return GteSQLiteFromSession(session_impl); + } + // Is this a MySQL session? + else if (connector == "mysql") + { + return GteMySQLFromSession(session_impl); + } + else + { + STHROWF("Unknown connector type {}", connector); + } +} + // ------------------------------------------------------------------------------------------------ LightObj SqDataSessionPool::GetProperty(StackStrF & name) { @@ -764,6 +791,7 @@ void Register_POCO_Data(HSQUIRRELVM vm, Table &) .Prop(_SC("IsActive"), &SqDataSessionPool::IsActive) // Member Methods .Func(_SC("Get"), &SqDataSessionPool::Get) + .Func(_SC("GetSq"), &SqDataSessionPool::GetSq) .FmtFunc(_SC("GetWithProperty"), &SqDataSessionPool::GetWithProperty) .FmtFunc(_SC("GetWithFeature"), &SqDataSessionPool::GetWithFeature) .FmtFunc(_SC("SetFeature"), &SqDataSessionPool::SetFeature) diff --git a/module/PocoLib/Data.hpp b/module/PocoLib/Data.hpp index 02380e61..d6728a29 100644 --- a/module/PocoLib/Data.hpp +++ b/module/PocoLib/Data.hpp @@ -1707,7 +1707,7 @@ protected: } SQ_UNREACHABLE // Unreachable - return LightObj(); + return {}; } }; @@ -1746,7 +1746,7 @@ struct SqDataSessionPool : public SessionPool /* -------------------------------------------------------------------------------------------- * Destroys the SessionPool. */ - ~SqDataSessionPool() = default; + ~SqDataSessionPool() override = default; /* -------------------------------------------------------------------------------------------- * Assignment operator (disabled). @@ -1766,6 +1766,11 @@ struct SqDataSessionPool : public SessionPool return LightObj(SqTypeIdentity< SqDataSession >{}, SqVM(), get()); } + /* -------------------------------------------------------------------------------------------- + * Retrieve a Session wrapped in a native/legacy implementation. + */ + LightObj GetSq(); + /* -------------------------------------------------------------------------------------------- * Retrieve a Session with requested property set. */