// Copyright (C) 2016 The Qt Company Ltd. // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #pragma once #include "sqlitebasestatement.h" namespace Sqlite { template class ReadWriteStatement final : protected StatementImplementation { friend class DatabaseBackend; using Base = StatementImplementation; public: ReadWriteStatement(Utils::SmallStringView sqlStatement, Database &database, const source_location &sourceLocation = source_location::current()) : Base{sqlStatement, database, sourceLocation} { Base::checkBindingParameterCount(BindParameterCount, sourceLocation); Base::checkColumnCount(ResultCount, sourceLocation); } using Base::execute; using Base::optionalValue; using Base::readCallback; using Base::readTo; using Base::toValue; using Base::value; using Base::values; using Base::write; template auto valueWithTransaction(const source_location &sourceLocation, const QueryTypes &...queryValues) { return withImmediateTransaction( Base::database(), [&] { return Base::template value(sourceLocation, queryValues...); }, sourceLocation); } template auto valueWithTransaction(const QueryTypes &...queryValues) { static constexpr auto sourceLocation = source_location::current(); return valueWithTransaction(sourceLocation, queryValues...); } template auto optionalValueWithTransaction(const source_location &sourceLocation, const QueryTypes &...queryValues) { return withImmediateTransaction( Base::database(), [&] { return Base::template optionalValue(sourceLocation, queryValues...); }, sourceLocation); } template auto optionalValueWithTransaction(const QueryTypes &...queryValues) { static constexpr auto sourceLocation = source_location::current(); return optionalValueWithTransaction(sourceLocation, queryValues...); } template auto valuesWithTransaction(const source_location &sourceLocation, const QueryTypes &...queryValues) { return withImmediateTransaction( Base::database(), [&] { return Base::template values(sourceLocation, queryValues...); }, sourceLocation); } template auto valuesWithTransaction(const QueryTypes &...queryValues) { static constexpr auto sourceLocation = source_location::current(); return valuesWithTransaction(sourceLocation, queryValues...); } template void readCallbackWithTransaction(Callable &&callable, const source_location &sourceLocation, const QueryTypes &...queryValues) { withImmediateTransaction( Base::database(), [&] { Base::readCallback(std::forward(callable), sourceLocation, queryValues...); }, sourceLocation); } template void readCallbackWithTransaction(Callable &&callable, const QueryTypes &...queryValues) { static constexpr auto sourceLocation = source_location::current(); readCallbackWithTransaction(callable, sourceLocation, queryValues...); } template void readToWithTransaction(Container &container, const source_location &sourceLocation, const QueryTypes &...queryValues) { withImmediateTransaction( Base::database(), [&] { Base::readTo(container, sourceLocation, queryValues...); }, sourceLocation); } template void readToWithTransaction(Container &container, const QueryTypes &...queryValues) { static constexpr auto sourceLocation = source_location::current(); readToWithTransaction(container, sourceLocation, queryValues...); } void executeWithTransaction(const source_location &sourceLocation = source_location::current()) { withImmediateTransaction(Base::database(), [&] { Base::execute(sourceLocation); }, sourceLocation); } }; } // namespace Sqlite