2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
2022-12-21 10:12:09 +01:00
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-09-21 11:43:59 +02:00
|
|
|
#include "sqlitebasestatement.h"
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2017-07-26 16:02:24 +02:00
|
|
|
namespace Sqlite {
|
|
|
|
|
|
2021-12-07 17:28:38 +01:00
|
|
|
template<int ResultCount = 0, int BindParameterCount = 0>
|
|
|
|
|
class ReadWriteStatement final
|
|
|
|
|
: protected StatementImplementation<BaseStatement, ResultCount, BindParameterCount>
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2017-09-18 10:21:45 +02:00
|
|
|
friend class DatabaseBackend;
|
2021-12-07 17:28:38 +01:00
|
|
|
using Base = StatementImplementation<BaseStatement, ResultCount, BindParameterCount>;
|
2017-07-26 18:43:07 +02:00
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
public:
|
2021-03-24 18:10:55 +01:00
|
|
|
ReadWriteStatement(Utils::SmallStringView sqlStatement, Database &database)
|
|
|
|
|
: Base{sqlStatement, database}
|
|
|
|
|
{
|
2021-12-07 17:28:38 +01:00
|
|
|
Base::checkBindingParameterCount(BindParameterCount);
|
2021-03-24 18:10:55 +01:00
|
|
|
Base::checkColumnCount(ResultCount);
|
|
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2021-03-24 18:10:55 +01:00
|
|
|
using Base::execute;
|
2021-04-29 19:33:07 +02:00
|
|
|
using Base::optionalValue;
|
2021-03-24 18:10:55 +01:00
|
|
|
using Base::readCallback;
|
|
|
|
|
using Base::readTo;
|
|
|
|
|
using Base::toValue;
|
|
|
|
|
using Base::value;
|
|
|
|
|
using Base::values;
|
|
|
|
|
using Base::write;
|
2021-04-29 18:50:48 +02:00
|
|
|
|
|
|
|
|
template<typename ResultType, typename... QueryTypes>
|
|
|
|
|
auto valueWithTransaction(const QueryTypes &...queryValues)
|
|
|
|
|
{
|
|
|
|
|
ImmediateTransaction transaction{Base::database()};
|
|
|
|
|
|
|
|
|
|
auto resultValue = Base::template value<ResultType>(queryValues...);
|
|
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
|
|
|
|
|
return resultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-29 19:33:07 +02:00
|
|
|
template<typename ResultType, typename... QueryTypes>
|
|
|
|
|
auto optionalValueWithTransaction(const QueryTypes &...queryValues)
|
|
|
|
|
{
|
|
|
|
|
ImmediateTransaction transaction{Base::database()};
|
|
|
|
|
|
|
|
|
|
auto resultValue = Base::template optionalValue<ResultType>(queryValues...);
|
|
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
|
|
|
|
|
return resultValue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-29 18:50:48 +02:00
|
|
|
template<typename ResultType, typename... QueryTypes>
|
|
|
|
|
auto valuesWithTransaction(std::size_t reserveSize, const QueryTypes &...queryValues)
|
|
|
|
|
{
|
|
|
|
|
ImmediateTransaction 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)
|
|
|
|
|
{
|
|
|
|
|
ImmediateTransaction transaction{Base::database()};
|
|
|
|
|
|
|
|
|
|
Base::readCallback(std::forward<Callable>(callable), queryValues...);
|
|
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
template<typename Container, typename... QueryTypes>
|
|
|
|
|
void readToWithTransaction(Container &container, const QueryTypes &...queryValues)
|
|
|
|
|
{
|
|
|
|
|
ImmediateTransaction transaction{Base::database()};
|
|
|
|
|
|
|
|
|
|
Base::readTo(container, queryValues...);
|
|
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void executeWithTransaction()
|
|
|
|
|
{
|
|
|
|
|
ImmediateTransaction transaction{Base::database()};
|
|
|
|
|
|
|
|
|
|
Base::execute();
|
|
|
|
|
|
|
|
|
|
transaction.commit();
|
|
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
};
|
2017-07-26 16:02:24 +02:00
|
|
|
|
|
|
|
|
} // namespace Sqlite
|