Skip to content

Commit

Permalink
Fixed a bug in Qt 5.9.6
Browse files Browse the repository at this point in the history
  • Loading branch information
devbean committed Aug 16, 2018
1 parent e941eef commit e691c79
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 18 deletions.
40 changes: 24 additions & 16 deletions sqlitecipher/sqlitecipher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Q_DECLARE_OPAQUE_POINTER(sqlite3_stmt*)
sqlite3_key(d->access, password.toUtf8().constData(), password.size()); \
int result = sqlite3_exec(d->access, QStringLiteral("SELECT count(*) FROM sqlite_master LIMIT 1").toUtf8().constData(), nullptr, nullptr, nullptr); \
if (result != SQLITE_OK) { \
if (d->access) { sqlite3_close(d->access); d->access = 0; } \
if (d->access) { sqlite3_close(d->access); d->access = nullptr; } \
setLastError(qMakeError(d->access, tr("Invalid password. Maybe cipher not match?"), QSqlError::ConnectionError)); setOpenError(true); return false; \
} \
} while (0)
Expand Down Expand Up @@ -158,7 +158,7 @@ class SQLiteCipherDriverPrivate : public QSqlDriverPrivate
{
Q_DECLARE_PUBLIC(SQLiteCipherDriver)
public:
inline SQLiteCipherDriverPrivate() : QSqlDriverPrivate(), access(0) {}
inline SQLiteCipherDriverPrivate() : QSqlDriverPrivate(), access(nullptr) {}
sqlite3 *access;
QList <SQLiteResult *> results;
QStringList notificationid;
Expand Down Expand Up @@ -187,7 +187,7 @@ class SQLiteResultPrivate : public QSqlCachedResultPrivate

SQLiteResultPrivate::SQLiteResultPrivate(SQLiteResult *q, const SQLiteCipherDriver *drv)
: QSqlCachedResultPrivate(q, drv),
stmt(0),
stmt(nullptr),
skippedStatus(false),
skipRow(false)
{
Expand All @@ -211,7 +211,7 @@ void SQLiteResultPrivate::finalize()
return;

sqlite3_finalize(stmt);
stmt = 0;
stmt = nullptr;
}

void SQLiteResultPrivate::initColumns(bool emptyResultset)
Expand Down Expand Up @@ -263,7 +263,11 @@ void SQLiteResultPrivate::initColumns(bool emptyResultset)
}
}

#if QT_VERSION < QT_VERSION_CHECK(5, 10, 0)
QSqlField fld(colName, fieldType);
#else
QSqlField fld(colName, fieldType, tableName);
#endif
fld.setSqlType(stp);
rInf.append(fld);
}
Expand Down Expand Up @@ -419,7 +423,7 @@ bool SQLiteResult::prepare(const QString &query)

setSelect(false);

const void *pzTail = NULL;
const void *pzTail = nullptr;

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

/////////////////////////////////////////////////////////

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

#if QT_CONFIG(regularexpression)
#ifdef REGULAR_EXPRESSION_ENABLED
static const QLatin1String regexpConnectOption = QLatin1String("QSQLITE_ENABLE_REGEXP");
bool defineRegexp = false;
int regexpCacheSize = 25;
Expand Down Expand Up @@ -978,7 +982,7 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
} else if (option == QLatin1String("QSQLITE_REMOVE_KEY")) {
keyOp = REMOVE_KEY;
}
#if QT_CONFIG(regularexpression)
#ifdef REGULAR_EXPRESSION_ENABLED
else if (option.startsWith(regexpConnectOption)) {
QString regOption = option.mid(regexpConnectOption.size());
if (regOption.isEmpty()) {
Expand Down Expand Up @@ -1008,11 +1012,11 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString

setOpen(true);
setOpenError(false);
#if QT_CONFIG(regularexpression)
#ifdef REGULAR_EXPRESSION_ENABLED
if (defineRegexp) {
auto cache = new QCache<QString, QRegularExpression>(regexpCacheSize);
sqlite3_create_function_v2(d->access, "regexp", 2, SQLITE_UTF8, cache, &_q_regexp, NULL,
NULL, &_q_regexp_cleanup);
sqlite3_create_function_v2(d->access, "regexp", 2, SQLITE_UTF8, cache, &_q_regexp, nullptr,
nullptr, &_q_regexp_cleanup);
}
#endif
if (cipher > 0) {
Expand Down Expand Up @@ -1092,7 +1096,7 @@ bool SQLiteCipherDriver::open(const QString & db, const QString &, const QString
} else {
if (d->access) {
sqlite3_close(d->access);
d->access = 0;
d->access = nullptr;
}

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

if (d->access && (d->notificationid.count() > 0)) {
d->notificationid.clear();
sqlite3_update_hook(d->access, NULL, NULL);
sqlite3_update_hook(d->access, nullptr, nullptr);
}

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

d->notificationid.removeAll(name);
if (d->notificationid.isEmpty())
sqlite3_update_hook(d->access, NULL, NULL);
sqlite3_update_hook(d->access, nullptr, nullptr);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion sqlitecipher/sqlitecipher_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
#if QT_CONFIG(timezone)
#define TIMEZONE_ENABLED
#endif
#elif (QT_VERSION >= QT_VERSION_CHECK(5, 10, 0))
#else
#ifndef QT_NO_REGULAREXPRESSION
#define REGULAR_EXPRESSION_ENABLED
#endif
Expand Down
4 changes: 3 additions & 1 deletion testapp/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ int main(int argc, char *argv[])
query.exec("insert into mapping values (6, 'FFF')");
query.exec("insert into mapping values (7, 'GGG')");
query.exec("select * from mapping where name regexp '(a|A)$'");
while (query.next()) {
if (query.next()) {
qDebug() << "Regexp result: " << query.value(0).toInt() << ": " << query.value(1).toString();
} else {
qDebug() << "This plugin does not support regexp.";
}
qDebug() << "----------" << endl;
query.exec("select id, name from mapping");
Expand Down

0 comments on commit e691c79

Please sign in to comment.