1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
|
// 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 "sqlite3_fwd.h"
#include "sqliteglobal.h"
#include "sourcelocation.h"
#include "sqliteblob.h"
#include "sqliteexception.h"
#include "sqliteids.h"
#include "sqlitetracing.h"
#include "sqlitetransaction.h"
#include "sqlitevalue.h"
#include <utils/smallstringvector.h>
#include <nanotrace/nanotracehr.h>
#include <utils/span.h>
#include <cstdint>
#include <exception>
#include <functional>
#include <memory>
#include <optional>
#include <tuple>
#include <type_traits>
#include <vector>
using std::int64_t;
namespace Sqlite {
class Database;
class DatabaseBackend;
enum class Type : char { Invalid, Integer, Float, Text, Blob, Null };
class SQLITE_EXPORT BaseStatement
{
public:
using Database = ::Sqlite::Database;
explicit BaseStatement(Utils::SmallStringView sqlStatement,
Database &database,
const source_location &sourceLocation);
BaseStatement(const BaseStatement &) = delete;
BaseStatement &operator=(const BaseStatement &) = delete;
BaseStatement(BaseStatement &&) = default;
bool next(const source_location &sourceLocation) const;
void step(const source_location &sourceLocation) const;
void reset() const noexcept;
Type fetchType(int column) const;
int fetchIntValue(int column) const;
long fetchLongValue(int column) const;
long long fetchLongLongValue(int column) const;
double fetchDoubleValue(int column) const;
Utils::SmallStringView fetchSmallStringViewValue(int column) const;
ValueView fetchValueView(int column) const;
BlobView fetchBlobValue(int column) const;
template<typename Type>
Type fetchValue(int column) const;
void bindNull(int index, const source_location &sourceLocation);
void bind(int index, NullValue, const source_location &sourceLocation);
void bind(int index, int value, const source_location &sourceLocation);
void bind(int index, long long value, const source_location &sourceLocation);
void bind(int index, double value, const source_location &sourceLocation);
void bind(int index, void *pointer, const source_location &sourceLocation);
void bind(int index, Utils::span<const int> values, const source_location &sourceLocation);
void bind(int index, Utils::span<const long long> values, const source_location &sourceLocation);
void bind(int index, Utils::span<const double> values, const source_location &sourceLocation);
void bind(int index, Utils::span<const char *> values, const source_location &sourceLocation);
void bind(int index, Utils::SmallStringView value, const source_location &sourceLocation);
void bind(int index, const Value &value, const source_location &sourceLocation);
void bind(int index, ValueView value, const source_location &sourceLocation);
void bind(int index, BlobView blobView, const source_location &sourceLocation);
template<typename Type, typename std::enable_if_t<Type::IsBasicId::value, bool> = true>
void bind(int index, Type id, const source_location &sourceLocation)
{
if (!id.isNull())
bind(index, id.internalId(), sourceLocation);
else
bindNull(index, sourceLocation);
}
template<typename Enumeration, std::enable_if_t<std::is_enum_v<Enumeration>, bool> = true>
void bind(int index, Enumeration enumeration, const source_location &sourceLocation)
{
bind(index, Utils::to_underlying(enumeration), sourceLocation);
}
void bind(int index, uint value, const source_location &sourceLocation)
{
bind(index, static_cast<long long>(value), sourceLocation);
}
void bind(int index, long value, const source_location &sourceLocation)
{
bind(index, static_cast<long long>(value), sourceLocation);
}
void prepare(Utils::SmallStringView sqlStatement, const source_location &sourceLocation);
void waitForUnlockNotify(const source_location &sourceLocation) const;
sqlite3 *sqliteDatabaseHandle(const source_location &sourceLocation) const;
void setIfIsReadyToFetchValues(int resultCode) const;
void checkBindingName(int index) const;
void checkBindingParameterCount(int bindingParameterCount,
const source_location &sourceLocation) const;
void checkColumnCount(int columnCount, const source_location &sourceLocation) const;
bool isReadOnlyStatement() const;
QString columnName(int column) const;
Database &database() const { return m_database; }
protected:
~BaseStatement() = default;
std::uintptr_t handle() const
{
return reinterpret_cast<std::uintptr_t>(m_compiledStatement.get());
}
private:
struct Deleter
{
SQLITE_EXPORT void operator()(sqlite3_stmt *statement);
};
private:
std::unique_ptr<sqlite3_stmt, Deleter> m_compiledStatement;
Database &m_database;
};
template<>
SQLITE_EXPORT int BaseStatement::fetchValue<int>(int column) const;
template<>
SQLITE_EXPORT long BaseStatement::fetchValue<long>(int column) const;
template<>
SQLITE_EXPORT long long BaseStatement::fetchValue<long long>(int column) const;
template<>
SQLITE_EXPORT double BaseStatement::fetchValue<double>(int column) const;
extern template SQLITE_EXPORT Utils::SmallStringView BaseStatement::fetchValue<Utils::SmallStringView>(
int column) const;
extern template SQLITE_EXPORT Utils::SmallString BaseStatement::fetchValue<Utils::SmallString>(
int column) const;
extern template SQLITE_EXPORT Utils::PathString BaseStatement::fetchValue<Utils::PathString>(
int column) const;
template<typename BaseStatement, int ResultCount, int BindParameterCount>
class StatementImplementation : public BaseStatement
{
struct Resetter;
public:
using BaseStatement::BaseStatement;
StatementImplementation(StatementImplementation &&) = default;
void execute(const source_location &sourceLocation = source_location::current())
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{
"execute",
sqliteHighLevelCategory(),
keyValue("sqlite statement", BaseStatement::handle()),
};
Resetter resetter{this};
BaseStatement::next(sourceLocation);
}
template<typename... ValueType>
void bindValues(const source_location &sourceLocation, const ValueType &...values)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"bind",
sqliteHighLevelCategory(),
keyValue("sqlite statement", BaseStatement::handle())};
static_assert(BindParameterCount == sizeof...(values), "Wrong binding parameter count!");
int index = 0;
(BaseStatement::bind(++index, values, sourceLocation), ...);
}
template<typename... ValueType>
void write(const source_location &sourceLocation, const ValueType &...values)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"write",
sqliteHighLevelCategory(),
keyValue("sqlite statement", BaseStatement::handle())};
Resetter resetter{this};
bindValues(sourceLocation, values...);
BaseStatement::next(sourceLocation);
}
template<typename... ValueType>
void write(const ValueType &...values)
{
static constexpr auto sourceLocation = source_location::current();
write(sourceLocation, values...);
}
template<typename T>
struct is_container : std::false_type
{};
template<typename... Args>
struct is_container<std::vector<Args...>> : std::true_type
{};
template<typename... Args>
struct is_container<QList<Args...>> : std::true_type
{};
template<typename T, qsizetype Prealloc>
struct is_container<QVarLengthArray<T, Prealloc>> : std::true_type
{};
template<typename T>
struct is_small_container : std::false_type
{};
template<typename T, qsizetype Prealloc>
struct is_small_container<QVarLengthArray<T, Prealloc>> : std::true_type
{};
template<typename Container,
std::size_t capacity = 32,
typename std::enable_if_t<is_container<Container>::value, bool> = true,
typename... QueryTypes>
auto values(const source_location &sourceLocation, const QueryTypes &...queryValues)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"values",
sqliteHighLevelCategory(),
keyValue("sqlite statement", BaseStatement::handle())};
Resetter resetter{this};
Container resultValues;
using size_tupe = typename Container::size_type;
if constexpr (!is_small_container<Container>::value)
resultValues.reserve(static_cast<size_tupe>(std::max(capacity, m_maximumResultCount)));
bindValues(sourceLocation, queryValues...);
while (BaseStatement::next(sourceLocation))
emplaceBackValues(resultValues);
setMaximumResultCount(static_cast<std::size_t>(resultValues.size()));
return resultValues;
}
template<typename Container,
std::size_t capacity = 32,
typename std::enable_if_t<is_container<Container>::value, bool> = true,
typename... QueryTypes>
auto values(const QueryTypes &...queryValues)
{
static constexpr auto sourceLocation = source_location::current();
return value<Container, capacity>(sourceLocation, queryValues...);
}
template<typename ResultType,
std::size_t capacity = 32,
template<typename...> typename Container = std::vector,
typename std::enable_if_t<!is_container<ResultType>::value, bool> = true,
typename... QueryTypes>
auto values(const source_location &sourceLocation, const QueryTypes &...queryValues)
{
return values<Container<ResultType>, capacity>(sourceLocation, queryValues...);
}
template<typename ResultType,
std::size_t capacity = 32,
template<typename...> typename Container = std::vector,
typename std::enable_if_t<!is_container<ResultType>::value, bool> = true,
typename... QueryTypes>
auto values(const QueryTypes &...queryValues)
{
static constexpr auto sourceLocation = source_location::current();
return values<ResultType, capacity, Container>(sourceLocation, queryValues...);
}
template<typename ResultType, typename... QueryTypes>
auto value(const source_location &sourceLocation, const QueryTypes &...queryValues)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"value",
sqliteHighLevelCategory(),
keyValue("sqlite statement", BaseStatement::handle())};
Resetter resetter{this};
ResultType resultValue{};
bindValues(sourceLocation, queryValues...);
if (BaseStatement::next(sourceLocation))
resultValue = createValue<ResultType>();
return resultValue;
}
template<typename ResultType, typename... QueryTypes>
auto value(const QueryTypes &...queryValues)
{
static constexpr auto sourceLocation = source_location::current();
return value<ResultType>(sourceLocation, queryValues...);
}
template<typename ResultType, typename... QueryTypes>
auto optionalValue(const source_location &sourceLocation, const QueryTypes &...queryValues)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"optionalValue",
sqliteHighLevelCategory(),
keyValue("sqlite statement", BaseStatement::handle())};
Resetter resetter{this};
std::optional<ResultType> resultValue;
bindValues(sourceLocation, queryValues...);
if (BaseStatement::next(sourceLocation))
resultValue = createOptionalValue<std::optional<ResultType>>();
return resultValue;
}
template<typename ResultType, typename... QueryTypes>
auto optionalValue(const QueryTypes &...queryValues)
{
static constexpr auto sourceLocation = source_location::current();
return optionalValue<ResultType>(sourceLocation, queryValues...);
}
template<typename Type>
static auto toValue(Utils::SmallStringView sqlStatement,
Database &database,
const source_location &sourceLocation = source_location::current())
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"toValue", sqliteHighLevelCategory()};
StatementImplementation statement(sqlStatement, database, sourceLocation);
statement.checkColumnCount(1, sourceLocation);
statement.next(sourceLocation);
return statement.template fetchValue<Type>(0);
}
template<typename Callable, typename... QueryTypes>
void readCallback(Callable &&callable,
const source_location &sourceLocation,
const QueryTypes &...queryValues)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"readCallback",
sqliteHighLevelCategory(),
keyValue("sqlite statement", BaseStatement::handle())};
Resetter resetter{this};
bindValues(sourceLocation, queryValues...);
while (BaseStatement::next(sourceLocation)) {
auto control = callCallable(callable);
if (control == CallbackControl::Abort)
break;
}
}
template<typename Callable, typename... QueryTypes>
void readCallback(Callable &&callable, const QueryTypes &...queryValues)
{
static constexpr auto sourceLocation = source_location::current();
readCallback(callable, sourceLocation, queryValues...);
}
template<typename Container, typename... QueryTypes>
void readTo(Container &container,
const source_location &sourceLocation,
const QueryTypes &...queryValues)
{
using NanotraceHR::keyValue;
NanotraceHR::Tracer tracer{"readTo",
sqliteHighLevelCategory(),
keyValue("sqlite statement", BaseStatement::handle())};
Resetter resetter{this};
bindValues(sourceLocation, queryValues...);
while (BaseStatement::next(sourceLocation))
emplaceBackValues(container);
}
template<typename Container, typename... QueryTypes>
void readTo(Container &container, const QueryTypes &...queryValues)
{
static constexpr auto sourceLocation = source_location::current();
readTo(container, sourceLocation, queryValues...);
}
template<typename ResultType, typename... QueryTypes>
auto range(const source_location &sourceLocation, const QueryTypes &...queryValues)
{
return SqliteResultRange<ResultType>{*this, sourceLocation, queryValues...};
}
template<typename ResultType, typename... QueryTypes>
auto range(const QueryTypes &...queryValues)
{
static constexpr auto sourceLocation = source_location::current();
return SqliteResultRange<ResultType>{*this, sourceLocation, queryValues...};
}
template<typename ResultType, typename... QueryTypes>
auto rangeWithTransaction(const source_location &sourceLocation, const QueryTypes &...queryValues)
{
return SqliteResultRangeWithTransaction<ResultType>{*this, sourceLocation, queryValues...};
}
template<typename ResultType, typename... QueryTypes>
auto rangeWithTransaction(const QueryTypes &...queryValues)
{
static constexpr auto sourceLocation = source_location::current();
return SqliteResultRangeWithTransaction<ResultType>{*this, sourceLocation, queryValues...};
}
template<typename ResultType>
class BaseSqliteResultRange
{
public:
class SqliteResultSentinel
{};
class SqliteResultIteratator
{
public:
using iterator_category = std::input_iterator_tag;
using difference_type = int;
using value_type = ResultType;
using pointer = ResultType *;
using reference = ResultType &;
SqliteResultIteratator() = default;
SqliteResultIteratator(StatementImplementation &statement,
const source_location &sourceLocation)
: m_statement{&statement}
, m_sourceLocation{&sourceLocation}
, m_hasNext{m_statement->next(sourceLocation)}
{}
SqliteResultIteratator(StatementImplementation &statement,
const source_location &sourceLocation,
bool hasNext)
: m_statement{&statement}
, m_sourceLocation{&sourceLocation}
, m_hasNext{hasNext}
{}
SqliteResultIteratator(const SqliteResultIteratator &) = delete;
SqliteResultIteratator &operator=(const SqliteResultIteratator &) = delete;
SqliteResultIteratator(SqliteResultIteratator &&other) noexcept
: m_statement{other.m_statement}
, m_sourceLocation{other.m_sourceLocation}
, m_hasNext{std::exchange(other.m_hasNext, false)}
{}
SqliteResultIteratator &operator=(SqliteResultIteratator &&other) noexcept
{
m_statement = other.m_statement;
m_sourceLocation = other.m_sourceLocation;
m_hasNext = std::exchange(other.m_hasNext, false);
}
SqliteResultIteratator &operator++()
{
m_hasNext = m_statement->next(*m_sourceLocation);
return *this;
}
friend bool operator==(const SqliteResultIteratator &first, SqliteResultSentinel)
{
return !first.m_hasNext;
}
friend bool operator!=(const SqliteResultIteratator &first, SqliteResultSentinel)
{
return first.m_hasNext;
}
void operator++(int) { m_hasNext = m_statement->next(*m_sourceLocation); }
value_type operator*() const { return m_statement->createValue<ResultType>(); }
public:
StatementImplementation *m_statement = nullptr;
const source_location *m_sourceLocation = nullptr;
bool m_hasNext = false;
};
using value_type = ResultType;
using iterator = SqliteResultIteratator;
using const_iterator = iterator;
template<typename... QueryTypes>
BaseSqliteResultRange(StatementImplementation &statement, const source_location &sourceLocation)
: m_statement{statement}
, m_sourceLocation{sourceLocation}
{}
BaseSqliteResultRange(const BaseSqliteResultRange &) = default;
BaseSqliteResultRange(BaseSqliteResultRange &&) = default;
BaseSqliteResultRange &operator=(const BaseSqliteResultRange &) = default;
BaseSqliteResultRange &operator=(BaseSqliteResultRange &&) = default;
iterator begin() & { return iterator{m_statement, m_sourceLocation}; }
auto end() & { return SqliteResultSentinel{}; }
const_iterator begin() const & { return iterator{m_statement}; }
auto end() const & { return SqliteResultSentinel{}; }
private:
using TracerCategory = std::decay_t<decltype(sqliteHighLevelCategory())>;
StatementImplementation &m_statement;
const source_location &m_sourceLocation;
NanotraceHR::Tracer<TracerCategory, typename TracerCategory::IsActive> tracer{
"range",
sqliteHighLevelCategory(),
NanotraceHR::keyValue("sqlite statement", m_statement.handle())};
};
template<typename ResultType>
class SqliteResultRange : public BaseSqliteResultRange<ResultType>
{
public:
template<typename... QueryTypes>
SqliteResultRange(StatementImplementation &statement,
const source_location &sourceLocation,
const QueryTypes &...queryValues)
: BaseSqliteResultRange<ResultType>{statement, sourceLocation}
, resetter{&statement}
{
statement.bindValues(sourceLocation, queryValues...);
}
private:
Resetter resetter;
};
template<typename ResultType>
class SqliteResultRangeWithTransaction : public BaseSqliteResultRange<ResultType>
{
public:
template<typename... QueryTypes>
SqliteResultRangeWithTransaction(StatementImplementation &statement,
const source_location &sourceLocation,
const QueryTypes &...queryValues)
: BaseSqliteResultRange<ResultType>{statement, sourceLocation}
, m_transaction{statement.database(), sourceLocation}
, resetter{&statement}
, sourceLocation{sourceLocation}
{
statement.bindValues(sourceLocation, queryValues...);
}
~SqliteResultRangeWithTransaction()
{
resetter.reset();
if (!std::uncaught_exceptions()) {
m_transaction.commit(sourceLocation);
}
}
private:
DeferredTransaction<typename BaseStatement::Database> m_transaction;
Resetter resetter;
source_location sourceLocation;
};
protected:
~StatementImplementation() = default;
private:
struct Resetter
{
Resetter(StatementImplementation *statement)
: statement(statement)
{
#ifndef QT_NO_DEBUG
if (statement && !statement->database().isLocked())
throw DatabaseIsNotLocked{};
#endif
}
Resetter(Resetter &) = delete;
Resetter &operator=(Resetter &) = delete;
Resetter(Resetter &&other) noexcept
: statement{std::exchange(other.statement, nullptr)}
{}
Resetter &operator=(Resetter &&other) noexcept
{
statement = std::exchange(other.statement, nullptr);
return *this;
}
void reset() noexcept
{
if (statement)
statement->reset();
statement = nullptr;
}
~Resetter() noexcept { reset(); }
StatementImplementation *statement = nullptr;
};
struct ValueGetter
{
ValueGetter(StatementImplementation &statement, int column)
: statement(statement)
, column(column)
{}
explicit operator bool() const { return statement.fetchIntValue(column); }
operator int() const { return statement.fetchIntValue(column); }
operator long() const { return statement.fetchLongValue(column); }
operator long long() const { return statement.fetchLongLongValue(column); }
operator double() const { return statement.fetchDoubleValue(column); }
operator Utils::SmallStringView() { return statement.fetchSmallStringViewValue(column); }
operator BlobView() { return statement.fetchBlobValue(column); }
operator ValueView() { return statement.fetchValueView(column); }
template<typename ConversionType, typename = std::enable_if_t<ConversionType::IsBasicId::value>>
constexpr operator ConversionType()
{
if (statement.fetchType(column) == Type::Integer) {
if constexpr (std::is_same_v<typename ConversionType::DatabaseType, int>)
return ConversionType::create(statement.fetchIntValue(column));
else
return ConversionType::create(statement.fetchLongLongValue(column));
}
return ConversionType{};
}
template<typename Enumeration, std::enable_if_t<std::is_enum_v<Enumeration>, bool> = true>
constexpr operator Enumeration()
{
return static_cast<Enumeration>(statement.fetchLongLongValue(column));
}
StatementImplementation &statement;
int column;
};
template<typename ContainerType, int... ColumnIndices>
void emplaceBackValues(ContainerType &container, std::integer_sequence<int, ColumnIndices...>)
{
container.emplace_back(ValueGetter(*this, ColumnIndices)...);
}
template<typename ContainerType>
void emplaceBackValues(ContainerType &container)
{
emplaceBackValues(container, std::make_integer_sequence<int, ResultCount>{});
}
template<typename ResultOptionalType, int... ColumnIndices>
ResultOptionalType createOptionalValue(std::integer_sequence<int, ColumnIndices...>)
{
return ResultOptionalType(std::in_place, ValueGetter(*this, ColumnIndices)...);
}
template<typename ResultOptionalType>
ResultOptionalType createOptionalValue()
{
return createOptionalValue<ResultOptionalType>(std::make_integer_sequence<int, ResultCount>{});
}
template<typename ResultType, int... ColumnIndices>
ResultType createValue(std::integer_sequence<int, ColumnIndices...>)
{
return ResultType(ValueGetter(*this, ColumnIndices)...);
}
template<typename ResultType>
ResultType createValue()
{
return createValue<ResultType>(std::make_integer_sequence<int, ResultCount>{});
}
template<typename Callable, typename... Arguments>
CallbackControl invokeCallable(Callable &&callable, Arguments &&...arguments)
{
if constexpr (std::is_void_v<std::invoke_result_t<Callable, Arguments...>>) {
std::invoke(std::forward<Callable>(callable), std::forward<Arguments>(arguments)...);
return CallbackControl::Continue;
} else {
return std::invoke(std::forward<Callable>(callable),
std::forward<Arguments>(arguments)...);
}
}
template<typename Callable, int... ColumnIndices>
CallbackControl callCallable(Callable &&callable, std::integer_sequence<int, ColumnIndices...>)
{
return invokeCallable(std::forward<Callable>(callable), ValueGetter(*this, ColumnIndices)...);
}
template<typename Callable>
CallbackControl callCallable(Callable &&callable)
{
return callCallable(std::forward<Callable>(callable),
std::make_integer_sequence<int, ResultCount>{});
}
void setMaximumResultCount(std::size_t count)
{
m_maximumResultCount = std::max(m_maximumResultCount, count);
}
public:
std::size_t m_maximumResultCount = 0;
};
} // namespace Sqlite
|