aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/sqlite/sqlitestatement.cpp
blob: 4b8e3338a4b9f166897163faa03bf4a96acd5d72 (plain)
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
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** 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
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://www.qt.io/licensing.  For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file.  Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/

#include "sqlitestatement.h"

#include <QMutex>
#include <QWaitCondition>
#include <QVariant>
#include <QtGlobal>

#include "sqlite3.h"

#include "sqlitedatabasebackend.h"
#include "sqliteexception.h"

#if defined(__GNUC__)
#  pragma GCC diagnostic ignored "-Wignored-qualifiers"
#endif

SqliteStatement::SqliteStatement(const Utf8String &sqlStatementUtf8)
    : compiledStatement(nullptr, deleteCompiledStatement),
      bindingParameterCount(0),
      columnCount_(0),
      isReadyToFetchValues(false)
{
    prepare(sqlStatementUtf8);
    setBindingParameterCount();
    setBindingColumnNamesFromStatement();
    setColumnCount();
}

void SqliteStatement::deleteCompiledStatement(sqlite3_stmt *compiledStatement)
{
    if (compiledStatement)
        sqlite3_finalize(compiledStatement);
}

class UnlockNotification {

public:
    UnlockNotification() : fired(false) {};

    static void unlockNotifyCallBack(void **arguments, int argumentCount)
    {
        for (int index = 0; index < argumentCount; index++) {
          UnlockNotification *unlockNotification = static_cast<UnlockNotification *>(arguments[index]);
          unlockNotification->wakeupWaitCondition();
        }
    }

    void wakeupWaitCondition()
    {
        mutex.lock();
        fired = 1;
        waitCondition.wakeAll();
        mutex.unlock();
    }

    void wait()
    {
        mutex.lock();

        if (!fired) {
            waitCondition.wait(&mutex);
        }

        mutex.unlock();
    }

private:
    bool fired;
    QWaitCondition waitCondition;
    QMutex mutex;
};

void SqliteStatement::waitForUnlockNotify() const
{
    UnlockNotification unlockNotification;
    int resultCode = sqlite3_unlock_notify(sqliteDatabaseHandle(), UnlockNotification::unlockNotifyCallBack, &unlockNotification);

    if (resultCode == SQLITE_OK)
        unlockNotification.wait();
    else
        throwException("SqliteStatement::waitForUnlockNotify: database is in a dead lock!");
}

void SqliteStatement::reset() const
{
    int resultCode = sqlite3_reset(compiledStatement.get());
    if (resultCode != SQLITE_OK)
        throwException("SqliteStatement::reset: can't reset statement!");

    isReadyToFetchValues = false;
}

bool SqliteStatement::next() const
{
    int resultCode;

    do {
        resultCode = sqlite3_step(compiledStatement.get());
        if (resultCode == SQLITE_LOCKED) {
            waitForUnlockNotify();
            sqlite3_reset(compiledStatement.get());
        }

    } while (resultCode == SQLITE_LOCKED);

    setIfIsReadyToFetchValues(resultCode);

    return checkForStepError(resultCode);
}

void SqliteStatement::step() const
{
    next();
}

void SqliteStatement::write(const RowDictionary &rowDictionary)
{
    bind(rowDictionary);
    step();
    reset();
}

void SqliteStatement::writeUnchecked(const RowDictionary &rowDictionary)
{
    bindUnchecked(rowDictionary);
    step();
    reset();
}

int SqliteStatement::columnCount() const
{
    return columnCount_;
}

Utf8StringVector SqliteStatement::columnNames() const
{
    Utf8StringVector columnNames;
    int columnCount = SqliteStatement::columnCount();
    columnNames.reserve(columnCount);
    for (int columnIndex = 0; columnIndex < columnCount; columnIndex++)
        columnNames.append(Utf8String(sqlite3_column_origin_name(compiledStatement.get(), columnIndex), -1));

    return columnNames;
}

void SqliteStatement::bind(int index, int value)
{
     int resultCode = sqlite3_bind_int(compiledStatement.get(), index, value);
     if (resultCode != SQLITE_OK)
         throwException("SqliteStatement::bind: cant' bind 32 bit integer!");
}

void SqliteStatement::bind(int index, qint64 value)
{
     int resultCode = sqlite3_bind_int64(compiledStatement.get(), index, value);
     if (resultCode != SQLITE_OK)
         throwException("SqliteStatement::bind: cant' bind 64 bit integer!");
}

void SqliteStatement::bind(int index, double value)
{
    int resultCode = sqlite3_bind_double(compiledStatement.get(), index, value);
    if (resultCode != SQLITE_OK)
        throwException("SqliteStatement::bind: cant' bind double!");
}

void SqliteStatement::bind(int index, const QString &text)
{
    int resultCode;
    if (databaseTextEncoding() == Utf8) {
        QByteArray textUtf8 = text.toUtf8();
        resultCode = sqlite3_bind_text(compiledStatement.get(), index, textUtf8.constData(), textUtf8.size(), SQLITE_TRANSIENT);
    } else {
        resultCode = sqlite3_bind_text16(compiledStatement.get(), index, text.constData(), text.size() * 2, SQLITE_TRANSIENT);
    }

    if (resultCode != SQLITE_OK)
        throwException("SqliteStatement::bind: cant' not bind text!");
}

void SqliteStatement::bind(int index, const QByteArray &blob)
{
    sqlite3_bind_blob(compiledStatement.get(), index, blob.constData(), blob.size(), SQLITE_TRANSIENT);
}

void SqliteStatement::bind(int index, const QVariant &value)
{
    checkBindingIndex(index);

    switch (value.type()) {
        case QVariant::Bool:
        case QVariant::Int:
            bind(index, value.toInt());
            break;
        case QVariant::UInt:
        case QVariant::LongLong:
        case QVariant::ULongLong:
            bind(index, value.toLongLong());
            break;
        case QVariant::Double:
            bind(index, value.toDouble());
            break;
        case QVariant::String:
            bind(index, value.toString());
            break;
        case QVariant::ByteArray:
            bind(index, value.toByteArray());
            break;
        default:
            sqlite3_bind_null(compiledStatement.get(), index);
    }
}

template <typename Type>
void SqliteStatement::bind(const Utf8String &name, const Type &value)
{
    int index = bindingIndexForName(name);
    checkBindingName(index);
    bind(index, value);
}

template SQLITE_EXPORT void SqliteStatement::bind(const Utf8String &name, const int &value);
template SQLITE_EXPORT void SqliteStatement::bind(const Utf8String &name, const qint64 &value);
template SQLITE_EXPORT void SqliteStatement::bind(const Utf8String &name, const double &value);
template SQLITE_EXPORT void SqliteStatement::bind(const Utf8String &name, const QString &text);
template SQLITE_EXPORT void SqliteStatement::bind(const Utf8String &name, const QByteArray &blob);
template SQLITE_EXPORT void SqliteStatement::bind(const Utf8String &name, const QVariant &value);

int SqliteStatement::bindingIndexForName(const Utf8String &name)
{
    return  sqlite3_bind_parameter_index(compiledStatement.get(), name.constData());
}

void SqliteStatement::bind(const RowDictionary &rowDictionary)
{
    checkBindingValueMapIsEmpty(rowDictionary);

    int columnIndex = 1;
    foreach (const Utf8String &columnName, bindingColumnNames_) {
        checkParameterCanBeBound(rowDictionary, columnName);
        QVariant value = rowDictionary.value(columnName);
        bind(columnIndex, value);
        columnIndex += 1;
    }
}

void SqliteStatement::bindUnchecked(const RowDictionary &rowDictionary)
{
    checkBindingValueMapIsEmpty(rowDictionary);

    int columnIndex = 1;
    foreach (const Utf8String &columnName, bindingColumnNames_) {
        if (rowDictionary.contains(columnName)) {
            QVariant value = rowDictionary.value(columnName);
            bind(columnIndex, value);
        }
        columnIndex += 1;
    }
}

void SqliteStatement::setBindingColumnNames(const Utf8StringVector &bindingColumnNames)
{
    bindingColumnNames_ = bindingColumnNames;
}

const Utf8StringVector &SqliteStatement::bindingColumnNames() const
{
    return bindingColumnNames_;
}

void SqliteStatement::execute(const Utf8String &sqlStatementUtf8)
{
    SqliteStatement statement(sqlStatementUtf8);
    statement.step();
}

void SqliteStatement::prepare(const Utf8String &sqlStatementUtf8)
{
    int resultCode;

    do {
        sqlite3_stmt *sqliteStatement = nullptr;
        resultCode = sqlite3_prepare_v2(sqliteDatabaseHandle(), sqlStatementUtf8.constData(), sqlStatementUtf8.byteSize(), &sqliteStatement, nullptr);
        compiledStatement.reset(sqliteStatement);

        if (resultCode == SQLITE_LOCKED)
            waitForUnlockNotify();

    } while (resultCode == SQLITE_LOCKED);

    checkForPrepareError(resultCode);
}

sqlite3 *SqliteStatement::sqliteDatabaseHandle()
{
return SqliteDatabaseBackend::sqliteDatabaseHandle();
}

TextEncoding SqliteStatement::databaseTextEncoding()
{
    if (SqliteDatabaseBackend::threadLocalInstance())
        return SqliteDatabaseBackend::threadLocalInstance()->textEncoding();

    throwException("SqliteStatement::databaseTextEncoding: database backend instance is null!");

    Q_UNREACHABLE();
}

bool SqliteStatement::checkForStepError(int resultCode) const
{
    switch (resultCode) {
        case SQLITE_ROW: return true;
        case SQLITE_DONE: return false;
        case SQLITE_BUSY: throwException("SqliteStatement::stepStatement: database engine was unable to acquire the database locks!");
        case SQLITE_ERROR : throwException("SqliteStatement::stepStatement: run-time error (such as a constraint violation) has occurred!");
        case SQLITE_MISUSE:  throwException("SqliteStatement::stepStatement: was called inappropriately!");
        case SQLITE_CONSTRAINT:  throwException("SqliteStatement::stepStatement: contraint prevent insert or update!");
    }

    throwException("SqliteStatement::stepStatement: unknown error has happen!");

    Q_UNREACHABLE();
}

void SqliteStatement::checkForPrepareError(int resultCode) const
{
    switch (resultCode) {
        case SQLITE_OK: return;
        case SQLITE_BUSY: throwException("SqliteStatement::prepareStatement: database engine was unable to acquire the database locks!");
        case SQLITE_ERROR : throwException("SqliteStatement::prepareStatement: run-time error (such as a constraint violation) has occurred!");
        case SQLITE_MISUSE:  throwException("SqliteStatement::prepareStatement: was called inappropriately!");
    }

    throwException("SqliteStatement::prepareStatement: unknown error has happen!");
}

void SqliteStatement::setIfIsReadyToFetchValues(int resultCode) const
{
    if (resultCode == SQLITE_ROW)
        isReadyToFetchValues = true;
    else
        isReadyToFetchValues = false;

}

void SqliteStatement::checkIfIsReadyToFetchValues() const
{
    if (!isReadyToFetchValues)
        throwException("SqliteStatement::value: there are no values to fetch!");
}

void SqliteStatement::checkColumnsAreValid(const QVector<int> &columns) const
{
    foreach (int column, columns) {
        if (column < 0 || column >= columnCount_)
            throwException("SqliteStatement::values: column index out of bound!");
    }
}

void SqliteStatement::checkColumnIsValid(int column) const
{
    if (column < 0 || column >= columnCount_)
        throwException("SqliteStatement::values: column index out of bound!");
}

void SqliteStatement::checkBindingIndex(int index) const
{
    if (index <= 0 || index > bindingParameterCount)
        throwException("SqliteStatement::bind: binding index is out of bound!");
}

void SqliteStatement::checkBindingName(int index) const
{
    if (index <= 0 || index > bindingParameterCount)
        throwException("SqliteStatement::bind: binding name are not exists in this statement!");
}

void SqliteStatement::checkParameterCanBeBound(const RowDictionary &rowDictionary, const Utf8String &columnName)
{
    if (!rowDictionary.contains(columnName))
        throwException("SqliteStatement::bind: Not all parameters are bound!");
}

void SqliteStatement::setBindingParameterCount()
{
    bindingParameterCount = sqlite3_bind_parameter_count(compiledStatement.get());
}

Utf8String chopFirstLetter(const char *rawBindingName)
{
    QByteArray bindingName(rawBindingName);
    bindingName = bindingName.mid(1);

    return Utf8String::fromByteArray(bindingName);
}

void SqliteStatement::setBindingColumnNamesFromStatement()
{
    for (int index = 1; index <= bindingParameterCount; index++) {
        Utf8String bindingName = chopFirstLetter(sqlite3_bind_parameter_name(compiledStatement.get(), index));
        bindingColumnNames_.append(bindingName);
    }
}

void SqliteStatement::setColumnCount()
{
    columnCount_ = sqlite3_column_count(compiledStatement.get());
}

void SqliteStatement::checkBindingValueMapIsEmpty(const RowDictionary &rowDictionary) const
{
    if (rowDictionary.isEmpty())
        throwException("SqliteStatement::bind: can't bind empty row!");
}

bool SqliteStatement::isReadOnlyStatement() const
{
    return sqlite3_stmt_readonly(compiledStatement.get());
}

void SqliteStatement::throwException(const char *whatHasHappened)
{
    throw SqliteException(whatHasHappened, sqlite3_errmsg(sqliteDatabaseHandle()));
}

QString SqliteStatement::columnName(int column) const
{
    return QString::fromUtf8(sqlite3_column_name(compiledStatement.get(), column));
}

static bool columnIsBlob(sqlite3_stmt *sqlStatment, int column)
{
    return sqlite3_column_type(sqlStatment, column) == SQLITE_BLOB;
}

static QByteArray byteArrayForColumn(sqlite3_stmt *sqlStatment, int column)
{
    if (columnIsBlob(sqlStatment, column)) {
        const char *blob =  static_cast<const char*>(sqlite3_column_blob(sqlStatment, column));
        int size = sqlite3_column_bytes(sqlStatment, column);

        return QByteArray(blob, size);
    }

    return QByteArray();
}

static QString textForColumn(sqlite3_stmt *sqlStatment, int column)
{
    const QChar *text =  static_cast<const QChar*>(sqlite3_column_text16(sqlStatment, column));
    int size = sqlite3_column_bytes16(sqlStatment, column) / 2;

    return QString(text, size);
}

static Utf8String utf8TextForColumn(sqlite3_stmt *sqlStatment, int column)
{
    const char *text =  reinterpret_cast<const char*>(sqlite3_column_text(sqlStatment, column));
    int size = sqlite3_column_bytes(sqlStatment, column);

    return Utf8String(text, size);
}


static Utf8String convertedToUtf8StringForColumn(sqlite3_stmt *sqlStatment, int column)
{
    int dataType = sqlite3_column_type(sqlStatment, column);
    switch (dataType) {
        case SQLITE_INTEGER: return Utf8String::fromByteArray(QByteArray::number(sqlite3_column_int64(sqlStatment, column)));
        case SQLITE_FLOAT: return Utf8String::fromByteArray(QByteArray::number(sqlite3_column_double(sqlStatment, column)));
        case SQLITE_BLOB: return Utf8String();
        case SQLITE3_TEXT: return utf8TextForColumn(sqlStatment, column);
        case SQLITE_NULL: return Utf8String();
    }

    Q_UNREACHABLE();
}


static QVariant variantForColumn(sqlite3_stmt *sqlStatment, int column)
{
    int dataType = sqlite3_column_type(sqlStatment, column);
    switch (dataType) {
        case SQLITE_INTEGER: return QVariant::fromValue(sqlite3_column_int64(sqlStatment, column));
        case SQLITE_FLOAT: return QVariant::fromValue(sqlite3_column_double(sqlStatment, column));
        case SQLITE_BLOB: return QVariant::fromValue(byteArrayForColumn(sqlStatment, column));
        case SQLITE3_TEXT: return QVariant::fromValue(textForColumn(sqlStatment, column));
        case SQLITE_NULL: return QVariant();
    }

    Q_UNREACHABLE();
}

template<>
int SqliteStatement::value<int>(int column) const
{
    checkIfIsReadyToFetchValues();
    checkColumnIsValid(column);
    return sqlite3_column_int(compiledStatement.get(), column);
}

template<>
qint64 SqliteStatement::value<qint64>(int column) const
{
    checkIfIsReadyToFetchValues();
    checkColumnIsValid(column);
    return sqlite3_column_int64(compiledStatement.get(), column);
}

template<>
double SqliteStatement::value<double>(int column) const
{
    checkIfIsReadyToFetchValues();
    checkColumnIsValid(column);
    return sqlite3_column_double(compiledStatement.get(), column);
}

template<>
QByteArray SqliteStatement::value<QByteArray>(int column) const
{
    checkIfIsReadyToFetchValues();
    checkColumnIsValid(column);
    return byteArrayForColumn(compiledStatement.get(), column);
}

template<>
Utf8String SqliteStatement::value<Utf8String>(int column) const
{
    checkIfIsReadyToFetchValues();
    checkColumnIsValid(column);
    return convertedToUtf8StringForColumn(compiledStatement.get(), column);
}

template<>
QString SqliteStatement::value<QString>(int column) const
{
    checkIfIsReadyToFetchValues();
    checkColumnIsValid(column);
    return textForColumn(compiledStatement.get(), column);
}

template<>
QVariant SqliteStatement::value<QVariant>(int column) const
{
    checkIfIsReadyToFetchValues();
    checkColumnIsValid(column);
    return variantForColumn(compiledStatement.get(), column);
}

template <typename ContainerType>
 ContainerType SqliteStatement::columnValues(const QVector<int> &columnIndices) const
{
    typedef typename ContainerType::value_type ElementType;
    ContainerType valueContainer;
    valueContainer.reserve(columnIndices.count());
    for (int columnIndex : columnIndices)
        valueContainer += value<ElementType>(columnIndex);

    return valueContainer;
}

QMap<QString, QVariant> SqliteStatement::rowColumnValueMap() const
{
    QMap<QString, QVariant> values;

    reset();

    if (next()) {
        for (int column = 0; column < columnCount(); column++)
            values.insert(columnName(column), variantForColumn(compiledStatement.get(), column));
    }

    return values;
}

QMap<QString, QVariant> SqliteStatement::twoColumnValueMap() const
{
    QMap<QString, QVariant> values;

    reset();

    while (next())
        values.insert(textForColumn(compiledStatement.get(), 0), variantForColumn(compiledStatement.get(), 1));

    return values;
}

template <typename ContainerType>
ContainerType SqliteStatement::values(const QVector<int> &columns, int size) const
{
    checkColumnsAreValid(columns);

    ContainerType resultValues;
    resultValues.reserve(size);

    reset();

    while (next()) {
        resultValues += columnValues<ContainerType>(columns);
    }

    return resultValues;
}

template SQLITE_EXPORT QVector<QVariant> SqliteStatement::values<QVector<QVariant>>(const QVector<int> &columnIndices, int size) const;
template SQLITE_EXPORT QVector<Utf8String> SqliteStatement::values<QVector<Utf8String>>(const QVector<int> &columnIndices, int size) const;

template <typename ContainerType>
ContainerType SqliteStatement::values(int column) const
{
    typedef typename ContainerType::value_type ElementType;
    ContainerType resultValues;

    reset();

    while (next()) {
        resultValues += value<ElementType>(column);
    }

    return resultValues;
}

template SQLITE_EXPORT QVector<qint64> SqliteStatement::values<QVector<qint64>>(int column) const;
template SQLITE_EXPORT QVector<double> SqliteStatement::values<QVector<double>>(int column) const;
template SQLITE_EXPORT QVector<QByteArray> SqliteStatement::values<QVector<QByteArray>>(int column) const;
template SQLITE_EXPORT Utf8StringVector SqliteStatement::values<Utf8StringVector>(int column) const;
template SQLITE_EXPORT QVector<QString> SqliteStatement::values<QVector<QString>>(int column) const;

template <typename Type>
Type SqliteStatement::toValue(const Utf8String &sqlStatementUtf8)
{
    SqliteStatement statement(sqlStatementUtf8);

    statement.next();

    return statement.value<Type>(0);
}

template SQLITE_EXPORT int SqliteStatement::toValue<int>(const Utf8String &sqlStatementUtf8);
template SQLITE_EXPORT qint64 SqliteStatement::toValue<qint64>(const Utf8String &sqlStatementUtf8);
template SQLITE_EXPORT double SqliteStatement::toValue<double>(const Utf8String &sqlStatementUtf8);
template SQLITE_EXPORT QString SqliteStatement::toValue<QString>(const Utf8String &sqlStatementUtf8);
template SQLITE_EXPORT QByteArray SqliteStatement::toValue<QByteArray>(const Utf8String &sqlStatementUtf8);
template SQLITE_EXPORT Utf8String SqliteStatement::toValue<Utf8String>(const Utf8String &sqlStatementUtf8);
template SQLITE_EXPORT QVariant SqliteStatement::toValue<QVariant>(const Utf8String &sqlStatementUtf8);