2015-06-01 18:51:55 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2015-06-01 18:51:55 +02:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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-03-24 18:10:55 +01:00
|
|
|
template<int ResultCount>
|
|
|
|
|
class ReadStatement final : protected StatementImplementation<BaseStatement, ResultCount>
|
2015-06-01 18:51:55 +02:00
|
|
|
{
|
2021-03-24 18:10:55 +01:00
|
|
|
using Base = StatementImplementation<BaseStatement, ResultCount>;
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
public:
|
2021-03-24 18:10:55 +01:00
|
|
|
ReadStatement(Utils::SmallStringView sqlStatement, Database &database)
|
|
|
|
|
: Base{sqlStatement, database}
|
|
|
|
|
{
|
|
|
|
|
checkIsReadOnlyStatement();
|
|
|
|
|
Base::checkColumnCount(ResultCount);
|
|
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2021-04-29 19:33:07 +02:00
|
|
|
using Base::optionalValue;
|
2021-04-21 14:31:36 +02:00
|
|
|
using Base::range;
|
|
|
|
|
using Base::rangeWithTransaction;
|
2021-03-24 18:10:55 +01:00
|
|
|
using Base::readCallback;
|
|
|
|
|
using Base::readTo;
|
|
|
|
|
using Base::toValue;
|
|
|
|
|
using Base::value;
|
|
|
|
|
using Base::values;
|
2015-06-01 18:51:55 +02:00
|
|
|
|
2021-04-29 18:50:48 +02:00
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-29 19:33:07 +02:00
|
|
|
template<typename ResultType, typename... QueryTypes>
|
|
|
|
|
auto optionalValueWithTransaction(const QueryTypes &...queryValues)
|
|
|
|
|
{
|
|
|
|
|
DeferredTransaction 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)
|
|
|
|
|
{
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-01 18:51:55 +02:00
|
|
|
protected:
|
2021-03-24 18:10:55 +01:00
|
|
|
void checkIsReadOnlyStatement()
|
|
|
|
|
{
|
|
|
|
|
if (!Base::isReadOnlyStatement())
|
|
|
|
|
throw NotReadOnlySqlStatement(
|
|
|
|
|
"SqliteStatement::SqliteReadStatement: is not read only statement!");
|
|
|
|
|
}
|
2015-06-01 18:51:55 +02:00
|
|
|
};
|
2017-07-26 16:02:24 +02:00
|
|
|
|
2021-03-24 18:10:55 +01:00
|
|
|
template<int ResultCount>
|
|
|
|
|
ReadStatement(ReadStatement<ResultCount> &) -> ReadStatement<ResultCount>;
|
|
|
|
|
template<int ResultCount>
|
|
|
|
|
ReadStatement(const ReadStatement<ResultCount> &) -> ReadStatement<ResultCount>;
|
|
|
|
|
|
2017-07-26 16:02:24 +02:00
|
|
|
} // namespace Sqlite
|