mirror of
https://github.com/VCMP-SqMod/SqMod.git
synced 2025-06-15 22:57:12 +02:00
Allow session pool to be used with legacy database wrappers (experimental).
This commit is contained in:
@ -1,5 +1,6 @@
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include "PocoLib/Data.hpp"
|
||||
#include "Poco/Data/SessionImpl.h"
|
||||
|
||||
// ------------------------------------------------------------------------------------------------
|
||||
#include <sqratConst.h>
|
||||
@ -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)
|
||||
|
@ -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.
|
||||
*/
|
||||
|
Reference in New Issue
Block a user