// 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 ReadStatement final : protected StatementImplementation { using Base = StatementImplementation; public: ReadStatement(Utils::SmallStringView sqlStatement, Database &database, const source_location &sourceLocation = source_location::current()) : Base{sqlStatement, database, sourceLocation} { checkIsReadOnlyStatement(sourceLocation); Base::checkBindingParameterCount(BindParameterCount, sourceLocation); Base::checkColumnCount(ResultCount, sourceLocation); } using Base::optionalValue; using Base::range; using Base::rangeWithTransaction; using Base::readCallback; using Base::readTo; using Base::toValue; using Base::value; using Base::values; template auto valueWithTransaction(const source_location &sourceLocation, const QueryTypes &...queryValues) { return withImplicitTransaction(Base::database(), [&] { return Base::template value(sourceLocation, queryValues...); }); } 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 withImplicitTransaction(Base::database(), [&] { return Base::template optionalValue(sourceLocation, queryValues...); }); } 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 withImplicitTransaction(Base::database(), [&] { return Base::template values(sourceLocation, queryValues...); }); } 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) { withImplicitTransaction(Base::database(), [&] { Base::readCallback(std::forward(callable), sourceLocation, queryValues...); }); } 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) { withImplicitTransaction(Base::database(), [&] { Base::readTo(container, sourceLocation, queryValues...); }); } template void readToWithTransaction(Container &container, const QueryTypes &...queryValues) { static constexpr auto sourceLocation = source_location::current(); readToWithTransaction(container, sourceLocation, queryValues...); } protected: void checkIsReadOnlyStatement(const source_location &sourceLocation) { if (!Base::isReadOnlyStatement()) throw NotReadOnlySqlStatement(sourceLocation); } }; template ReadStatement(ReadStatement &) -> ReadStatement; template ReadStatement(const ReadStatement &) -> ReadStatement; } // namespace Sqlite