Skip to content

Commit e691c79

Browse files
committed
Fixed a bug in Qt 5.9.6
1 parent e941eef commit e691c79

File tree

3 files changed

+28
-18
lines changed

3 files changed

+28
-18
lines changed

sqlitecipher/sqlitecipher.cpp

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Q_DECLARE_OPAQUE_POINTER(sqlite3_stmt*)
8181
sqlite3_key(d->access, password.toUtf8().constData(), password.size()); \
8282
int result = sqlite3_exec(d->access, QStringLiteral("SELECT count(*) FROM sqlite_master LIMIT 1").toUtf8().constData(), nullptr, nullptr, nullptr); \
8383
if (result != SQLITE_OK) { \
84-
if (d->access) { sqlite3_close(d->access); d->access = 0; } \
84+
if (d->access) { sqlite3_close(d->access); d->access = nullptr; } \
8585
setLastError(qMakeError(d->access, tr("Invalid password. Maybe cipher not match?"), QSqlError::ConnectionError)); setOpenError(true); return false; \
8686
} \
8787
} while (0)
@@ -158,7 +158,7 @@ class SQLiteCipherDriverPrivate : public QSqlDriverPrivate
158158
{
159159
Q_DECLARE_PUBLIC(SQLiteCipherDriver)
160160
public:
161-
inline SQLiteCipherDriverPrivate() : QSqlDriverPrivate(), access(0) {}
161+
inline SQLiteCipherDriverPrivate() : QSqlDriverPrivate(), access(nullptr) {}
162162
sqlite3 *access;
163163
QList <SQLiteResult *> results;
164164
QStringList notificationid;
@@ -187,7 +187,7 @@ class SQLiteResultPrivate : public QSqlCachedResultPrivate
187187

188188
SQLiteResultPrivate::SQLiteResultPrivate(SQLiteResult *q, const SQLiteCipherDriver *drv)
189189
: QSqlCachedResultPrivate(q, drv),
190-
stmt(0),
190+
stmt(nullptr),
191191
skippedStatus(false),
192192
skipRow(false)
193193
{
@@ -211,7 +211,7 @@ void SQLiteResultPrivate::finalize()
211211
return;
212212

213213
sqlite3_finalize(stmt);
214-
stmt = 0;
214+
stmt = nullptr;
215215
}
216216

217217
void SQLiteResultPrivate::initColumns(bool emptyResultset)
@@ -263,7 +263,11 @@ void SQLiteResultPrivate::initColumns(bool emptyResultset)
263263
}
264264
}
265265

266+
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
267+
QSqlField fld(colName, fieldType);
268+
#else
266269
QSqlField fld(colName, fieldType, tableName);
270+
#endif
267271
fld.setSqlType(stp);
268272
rInf.append(fld);
269273
}
@@ -419,7 +423,7 @@ bool SQLiteResult::prepare(const QString &query)
419423

420424
setSelect(false);
421425

422-
const void *pzTail = NULL;
426+
const void *pzTail = nullptr;
423427

424428
#if (SQLITE_VERSION_NUMBER >= 3003011)
425429
int res = sqlite3_prepare16_v2(d->drv_d_func()->access, query.constData(), (query.size() + 1) * sizeof(QChar),
@@ -462,7 +466,7 @@ static QString timespecToString(const QDateTime &dateTime)
462466
return QStringLiteral("Z");
463467
case Qt::OffsetFromUTC:
464468
return secondsToOffset(dateTime.offsetFromUtc());
465-
#if QT_CONFIG(timezone)
469+
#ifdef TIMEZONE_ENABLED
466470
case Qt::TimeZone:
467471
return secondsToOffset(dateTime.timeZone().offsetFromUtc(dateTime));
468472
#endif
@@ -681,7 +685,7 @@ QVariant SQLiteResult::handle() const
681685

682686
/////////////////////////////////////////////////////////
683687

684-
#if QT_CONFIG(regularexpression)
688+
#ifdef REGULAR_EXPRESSION_ENABLED
685689
static void _q_regexp(sqlite3_context* context, int argc, sqlite3_value** argv)
686690
{
687691
if (Q_UNLIKELY(argc != 2)) {
@@ -842,7 +846,7 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
842846
int sqlcipherHmacPgno = 1;
843847
int sqlcipherHmacSaltMask = 0x3a;
844848

845-
#if QT_CONFIG(regularexpression)
849+
#ifdef REGULAR_EXPRESSION_ENABLED
846850
static const QLatin1String regexpConnectOption = QLatin1String("QSQLITE_ENABLE_REGEXP");
847851
bool defineRegexp = false;
848852
int regexpCacheSize = 25;
@@ -978,7 +982,7 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
978982
} else if (option == QLatin1String("QSQLITE_REMOVE_KEY")) {
979983
keyOp = REMOVE_KEY;
980984
}
981-
#if QT_CONFIG(regularexpression)
985+
#ifdef REGULAR_EXPRESSION_ENABLED
982986
else if (option.startsWith(regexpConnectOption)) {
983987
QString regOption = option.mid(regexpConnectOption.size());
984988
if (regOption.isEmpty()) {
@@ -1008,11 +1012,11 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
10081012

10091013
setOpen(true);
10101014
setOpenError(false);
1011-
#if QT_CONFIG(regularexpression)
1015+
#ifdef REGULAR_EXPRESSION_ENABLED
10121016
if (defineRegexp) {
10131017
auto cache = new QCache<QString, QRegularExpression>(regexpCacheSize);
1014-
sqlite3_create_function_v2(d->access, "regexp", 2, SQLITE_UTF8, cache, &_q_regexp, NULL,
1015-
NULL, &_q_regexp_cleanup);
1018+
sqlite3_create_function_v2(d->access, "regexp", 2, SQLITE_UTF8, cache, &_q_regexp, nullptr,
1019+
nullptr, &_q_regexp_cleanup);
10161020
}
10171021
#endif
10181022
if (cipher > 0) {
@@ -1092,7 +1096,7 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
10921096
} else {
10931097
if (d->access) {
10941098
sqlite3_close(d->access);
1095-
d->access = 0;
1099+
d->access = nullptr;
10961100
}
10971101

10981102
setLastError(qMakeError(d->access, tr("Error opening database"), QSqlError::ConnectionError));
@@ -1115,12 +1119,12 @@ void SQLiteCipherDriver::close()
11151119

11161120
if (d->access && (d->notificationid.count() > 0)) {
11171121
d->notificationid.clear();
1118-
sqlite3_update_hook(d->access, NULL, NULL);
1122+
sqlite3_update_hook(d->access, nullptr, nullptr);
11191123
}
11201124

11211125
if (sqlite3_close(d->access) != SQLITE_OK)
11221126
setLastError(qMakeError(d->access, tr("Error closing database"), QSqlError::ConnectionError));
1123-
d->access = 0;
1127+
d->access = nullptr;
11241128
setOpen(false);
11251129
setOpenError(false);
11261130
}
@@ -1226,7 +1230,11 @@ static QSqlIndex qGetTableInfo(QSqlQuery &q, const QString &tableName, bool only
12261230
if (onlyPIndex && !isPk)
12271231
continue;
12281232
QString typeName = q.value(2).toString().toLower();
1233+
#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
1234+
QSqlField fld(q.value(1).toString(), qGetColumnType(typeName));
1235+
#else
12291236
QSqlField fld(q.value(1).toString(), qGetColumnType(typeName), tableName);
1237+
#endif
12301238
if (isPk && (typeName == QLatin1String("integer")))
12311239
// INTEGER PRIMARY KEY fields are auto-generated in sqlite
12321240
// INT PRIMARY KEY is not the same as INTEGER PRIMARY KEY!
@@ -1326,7 +1334,7 @@ bool SQLiteCipherDriver::unsubscribeFromNotification(const QString &name)
13261334

13271335
d->notificationid.removeAll(name);
13281336
if (d->notificationid.isEmpty())
1329-
sqlite3_update_hook(d->access, NULL, NULL);
1337+
sqlite3_update_hook(d->access, nullptr, nullptr);
13301338

13311339
return true;
13321340
}

sqlitecipher/sqlitecipher_global.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#if QT_CONFIG(timezone)
5656
#define TIMEZONE_ENABLED
5757
#endif
58-
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
58+
#else
5959
#ifndef QT_NO_REGULAREXPRESSION
6060
#define REGULAR_EXPRESSION_ENABLED
6161
#endif

testapp/main.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ int main(int argc, char *argv[])
3939
query.exec("insert into mapping values (6, 'FFF')");
4040
query.exec("insert into mapping values (7, 'GGG')");
4141
query.exec("select * from mapping where name regexp '(a|A)$'");
42-
while (query.next()) {
42+
if (query.next()) {
4343
qDebug() << "Regexp result: " << query.value(0).toInt() << ": " << query.value(1).toString();
44+
} else {
45+
qDebug() << "This plugin does not support regexp.";
4446
}
4547
qDebug() << "----------" << endl;
4648
query.exec("select id, name from mapping");

0 commit comments

Comments
 (0)