diff options
author | Tobias Koenig <[email protected]> | 2013-11-30 14:40:11 +0100 |
---|---|---|
committer | The Qt Project <[email protected]> | 2013-12-01 14:46:56 +0100 |
commit | 4f28464ab7dfe9f18cd72fc022257e66a8e2b279 (patch) | |
tree | 2175779d56c4890fd7a846381ccd422410caf3cc /src/sql/drivers/sqlite/qsql_sqlite.cpp | |
parent | 1b07e4e31537f4814523f2788cb99c131651e06f (diff) |
Fix evaluation of SQLite driver options
Ensure that the options, which are passed to the SQLite driver, are
evaluated in the correct order and do not overwrite each other.
According to http://www.sqlite.org/c3ref/open.html the
SQLITE_OPEN_READONLY and (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE) are
mutual exclusive, but SQLITE_OPEN_URI can be combined with both of them.
Task-number: QTBUG-35186
[ChangeLog][QtSql][QSQLITE] Fixed evaluation of driver options
Change-Id: I8e74fe1ce43b9118b15f7b13fc71670bdcd73f68
Reviewed-by: Giuseppe D'Angelo <[email protected]>
Reviewed-by: Mark Brand <[email protected]>
Diffstat (limited to 'src/sql/drivers/sqlite/qsql_sqlite.cpp')
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index 27bc80e63fb..c98d6438fc3 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -599,24 +599,32 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c if (db.isEmpty()) return false; + + int timeOut = 5000; bool sharedCache = false; - int openMode = SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, timeOut=5000; - QStringList opts=QString(conOpts).remove(QLatin1Char(' ')).split(QLatin1Char(';')); - foreach(const QString &option, opts) { + bool openReadOnlyOption = false; + bool openUriOption = false; + + const QStringList opts = QString(conOpts).remove(QLatin1Char(' ')).split(QLatin1Char(';')); + foreach (const QString &option, opts) { if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) { bool ok; - int nt = option.mid(21).toInt(&ok); + const int nt = option.mid(21).toInt(&ok); if (ok) timeOut = nt; - } - if (option == QLatin1String("QSQLITE_OPEN_READONLY")) - openMode = SQLITE_OPEN_READONLY; - if (option == QLatin1String("QSQLITE_OPEN_URI")) - openMode |= SQLITE_OPEN_URI; - if (option == QLatin1String("QSQLITE_ENABLE_SHARED_CACHE")) + } else if (option == QLatin1String("QSQLITE_OPEN_READONLY")) { + openReadOnlyOption = true; + } else if (option == QLatin1String("QSQLITE_OPEN_URI")) { + openUriOption = true; + } else if (option == QLatin1String("QSQLITE_ENABLE_SHARED_CACHE")) { sharedCache = true; + } } + int openMode = (openReadOnlyOption ? SQLITE_OPEN_READONLY : (SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE)); + if (openUriOption) + openMode |= SQLITE_OPEN_URI; + sqlite3_enable_shared_cache(sharedCache); if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, openMode, NULL) == SQLITE_OK) { |