forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/4.14'
Change-Id: I214b8d59e8ff7fe0511cd6116ec7725ddc4376ee
This commit is contained in:
@@ -37,9 +37,10 @@
|
||||
#include <utils/span.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
#include <type_traits>
|
||||
|
||||
using std::int64_t;
|
||||
|
||||
@@ -319,6 +320,40 @@ public:
|
||||
return statement.template fetchValue<Type>(0);
|
||||
}
|
||||
|
||||
template<int ResultTypeCount = 1, typename Callable, typename... QueryTypes>
|
||||
void readCallback(Callable &&callable, const QueryTypes &...queryValues)
|
||||
{
|
||||
BaseStatement::checkColumnCount(ResultTypeCount);
|
||||
|
||||
Resetter resetter{*this};
|
||||
|
||||
bindValues(queryValues...);
|
||||
|
||||
while (BaseStatement::next()) {
|
||||
auto control = callCallable<ResultTypeCount>(callable);
|
||||
|
||||
if (control == CallbackControl::Abort)
|
||||
break;
|
||||
}
|
||||
|
||||
resetter.reset();
|
||||
}
|
||||
|
||||
template<int ResultTypeCount = 1, typename Container, typename... QueryTypes>
|
||||
void readTo(Container &container, const QueryTypes &...queryValues)
|
||||
{
|
||||
BaseStatement::checkColumnCount(ResultTypeCount);
|
||||
|
||||
Resetter resetter{*this};
|
||||
|
||||
bindValues(queryValues...);
|
||||
|
||||
while (BaseStatement::next())
|
||||
pushBackToContainer<ResultTypeCount>(container);
|
||||
|
||||
resetter.reset();
|
||||
}
|
||||
|
||||
protected:
|
||||
~StatementImplementation() = default;
|
||||
|
||||
@@ -401,6 +436,30 @@ private:
|
||||
return assignValue<ResultOptionalType>(std::make_integer_sequence<int, ResultTypeCount>{});
|
||||
}
|
||||
|
||||
template<typename Callable, int... ColumnIndices>
|
||||
CallbackControl callCallable(Callable &&callable, std::integer_sequence<int, ColumnIndices...>)
|
||||
{
|
||||
return std::invoke(callable, ValueGetter(*this, ColumnIndices)...);
|
||||
}
|
||||
|
||||
template<int ResultTypeCount, typename Callable>
|
||||
CallbackControl callCallable(Callable &&callable)
|
||||
{
|
||||
return callCallable(callable, std::make_integer_sequence<int, ResultTypeCount>{});
|
||||
}
|
||||
|
||||
template<typename Container, int... ColumnIndices>
|
||||
void pushBackToContainer(Container &container, std::integer_sequence<int, ColumnIndices...>)
|
||||
{
|
||||
container.push_back(Container::value_type(ValueGetter(*this, ColumnIndices)...));
|
||||
}
|
||||
|
||||
template<int ResultTypeCount, typename Container>
|
||||
void pushBackToContainer(Container &container)
|
||||
{
|
||||
pushBackToContainer(container, std::make_integer_sequence<int, ResultTypeCount>{});
|
||||
}
|
||||
|
||||
template<typename ValueType>
|
||||
void bindValuesByIndex(int index, const ValueType &value)
|
||||
{
|
||||
|
||||
@@ -68,4 +68,6 @@ enum class ChangeType : int { Delete = 9, Insert = 18, Update = 23 };
|
||||
|
||||
enum class byte : unsigned char {};
|
||||
|
||||
enum class CallbackControl : unsigned char { Continue, Abort };
|
||||
|
||||
} // namespace Sqlite
|
||||
|
||||
@@ -34,9 +34,11 @@ class SQLITE_EXPORT ReadStatement final : protected StatementImplementation<Base
|
||||
public:
|
||||
explicit ReadStatement(Utils::SmallStringView sqlStatement, Database &database);
|
||||
|
||||
using StatementImplementation::readCallback;
|
||||
using StatementImplementation::readTo;
|
||||
using StatementImplementation::toValue;
|
||||
using StatementImplementation::value;
|
||||
using StatementImplementation::values;
|
||||
using StatementImplementation::toValue;
|
||||
|
||||
protected:
|
||||
void checkIsReadOnlyStatement();
|
||||
|
||||
@@ -37,9 +37,11 @@ public:
|
||||
ReadWriteStatement(Utils::SmallStringView sqlStatement, Database &database);
|
||||
|
||||
using StatementImplementation::execute;
|
||||
using StatementImplementation::readCallback;
|
||||
using StatementImplementation::readTo;
|
||||
using StatementImplementation::toValue;
|
||||
using StatementImplementation::value;
|
||||
using StatementImplementation::values;
|
||||
using StatementImplementation::toValue;
|
||||
using StatementImplementation::write;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user