From 09a1767ffe39e6c8ffe28012bd12b84725bce613 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Wed, 3 Feb 2021 16:54:36 +0200 Subject: [PATCH] Add Exec[Async] shotrcuts to session. --- module/PocoLib/Data.cpp | 28 ++++++++++++++++++++++++++++ module/PocoLib/Data.hpp | 10 ++++++++++ 2 files changed, 38 insertions(+) diff --git a/module/PocoLib/Data.cpp b/module/PocoLib/Data.cpp index 0d033645..1d12e1e0 100644 --- a/module/PocoLib/Data.cpp +++ b/module/PocoLib/Data.cpp @@ -111,6 +111,32 @@ SqDataStatement SqDataSession::GetStatement(StackStrF & data) return SqDataStatement(*this, data); } +// ------------------------------------------------------------------------------------------------ +SqDataSession & SqDataSession::Execute(StackStrF & query) +{ + // Create a statement instance + Statement stmt(impl()->createStatementImpl()); + // Add the query to the + stmt << (query); + // Execute it + stmt.execute(); + // Allow chaining + return *this; +} + +// ------------------------------------------------------------------------------------------------ +SqDataSession & SqDataSession::ExecuteAsync(StackStrF & query) +{ + // Create a statement instance + Statement stmt(impl()->createStatementImpl()); + // Add the query to the + stmt << (query); + // Execute it + stmt.executeAsync(); + // Allow chaining + return *this; +} + // ------------------------------------------------------------------------------------------------ void SqDataStatement::UseEx(LightObj & obj, const std::string & name, Poco::Data::AbstractBinding::Direction dir) { @@ -426,6 +452,8 @@ void Register_POCO_Data(HSQUIRRELVM vm, Table &) .FmtFunc(_SC("GetFeature"), &SqDataSession::GetFeature) .FmtFunc(_SC("SetProperty"), &SqDataSession::SetProperty) .FmtFunc(_SC("GetProperty"), &SqDataSession::GetProperty) + .FmtFunc(_SC("Execute"), &SqDataSession::Execute) + .FmtFunc(_SC("ExecuteAsync"), &SqDataSession::ExecuteAsync) // Static Functions .StaticFunc(_SC("GetURI"), &SqDataSession::BuildURI) // Static Values diff --git a/module/PocoLib/Data.hpp b/module/PocoLib/Data.hpp index 0d97cce3..b1d939e7 100644 --- a/module/PocoLib/Data.hpp +++ b/module/PocoLib/Data.hpp @@ -788,6 +788,16 @@ struct SqDataSession : public Session * Look up the value of a property. */ SQMOD_NODISCARD SqDataStatement GetStatement(StackStrF & data); + + /* -------------------------------------------------------------------------------------------- + * Create a statement and execute the given query immediately. + */ + SqDataSession & Execute(StackStrF & query); + + /* -------------------------------------------------------------------------------------------- + * Create a statement and execute the given query whenever possible. + */ + SqDataSession & ExecuteAsync(StackStrF & query); }; /* ------------------------------------------------------------------------------------------------