Sqlite: Add *WithTransaction fetcher

There are many simply fetch functions which can now be simplified.

Change-Id: Ibf542ee8b07a1b06ea3dae695da1f69065e9dd71
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
This commit is contained in:
Marco Bubke
2021-04-29 18:50:48 +02:00
parent 5fda083436
commit c78d1c171f
3 changed files with 205 additions and 0 deletions

View File

@@ -50,6 +50,50 @@ public:
using Base::value;
using Base::values;
template<typename ResultType, typename... QueryTypes>
auto valueWithTransaction(const QueryTypes &...queryValues)
{
DeferredTransaction transaction{Base::database()};
auto resultValue = Base::template value<ResultType>(queryValues...);
transaction.commit();
return resultValue;
}
template<typename ResultType, typename... QueryTypes>
auto valuesWithTransaction(std::size_t reserveSize, const QueryTypes &...queryValues)
{
DeferredTransaction transaction{Base::database()};
auto resultValues = Base::template values<ResultType>(reserveSize, queryValues...);
transaction.commit();
return resultValues;
}
template<typename Callable, typename... QueryTypes>
void readCallbackWithTransaction(Callable &&callable, const QueryTypes &...queryValues)
{
DeferredTransaction transaction{Base::database()};
Base::readCallback(std::forward<Callable>(callable), queryValues...);
transaction.commit();
}
template<typename Container, typename... QueryTypes>
void readToWithTransaction(Container &container, const QueryTypes &...queryValues)
{
DeferredTransaction transaction{Base::database()};
Base::readTo(container, queryValues...);
transaction.commit();
}
protected:
void checkIsReadOnlyStatement()
{