diff options
author | Bill King <bill.king@nokia.com> | 2010-02-09 03:14:50 (GMT) |
---|---|---|
committer | Bill King <bill.king@nokia.com> | 2010-02-09 03:14:50 (GMT) |
commit | 72f3caa5d7821b93a4e807fb61c5cda9f2c6f393 (patch) | |
tree | 62d6612926f7bbcce8a1a28cbdb1a382339aa566 /src/sql/drivers/sqlite/qsql_sqlite.cpp | |
parent | ff222b3ece43664a4f599c8a6b0275d2aa72cc4d (diff) | |
download | Qt-72f3caa5d7821b93a4e807fb61c5cda9f2c6f393.zip Qt-72f3caa5d7821b93a4e807fb61c5cda9f2c6f393.tar.gz Qt-72f3caa5d7821b93a4e807fb61c5cda9f2c6f393.tar.bz2 |
(sqlite) Allow shared cache mode
This modification is needed to allow performance optimisations
necessary for QML.
Reviewed-by: Warwick Allison
Diffstat (limited to 'src/sql/drivers/sqlite/qsql_sqlite.cpp')
-rw-r--r-- | src/sql/drivers/sqlite/qsql_sqlite.cpp | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/src/sql/drivers/sqlite/qsql_sqlite.cpp b/src/sql/drivers/sqlite/qsql_sqlite.cpp index 9fff552..d3be304 100644 --- a/src/sql/drivers/sqlite/qsql_sqlite.cpp +++ b/src/sql/drivers/sqlite/qsql_sqlite.cpp @@ -500,32 +500,6 @@ bool QSQLiteDriver::hasFeature(DriverFeature f) const return false; } -static int qGetSqliteTimeout(QString opts) -{ - enum { DefaultTimeout = 5000 }; - - opts.remove(QLatin1Char(' ')); - foreach(QString option, opts.split(QLatin1Char(';'))) { - if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) { - bool ok; - int nt = option.mid(21).toInt(&ok); - if (ok) - return nt; - } - } - return DefaultTimeout; -} - -static int qGetSqliteOpenMode(QString opts) -{ - opts.remove(QLatin1Char(' ')); - foreach(QString option, opts.split(QLatin1Char(';'))) { - if (option == QLatin1String("QSQLITE_OPEN_READONLY")) - return SQLITE_OPEN_READONLY; - } - return SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE; -} - /* SQLite dbs have no user name, passwords, hosts or ports. just file names. @@ -537,9 +511,26 @@ bool QSQLiteDriver::open(const QString & db, const QString &, const QString &, c if (db.isEmpty()) return false; + 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) { + if (option.startsWith(QLatin1String("QSQLITE_BUSY_TIMEOUT="))) { + bool ok; + 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_ENABLE_SHARED_CACHE")) + sharedCache = true; + } + + sqlite3_enable_shared_cache(sharedCache); - if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, qGetSqliteOpenMode(conOpts), NULL) == SQLITE_OK) { - sqlite3_busy_timeout(d->access, qGetSqliteTimeout(conOpts)); + if (sqlite3_open_v2(db.toUtf8().constData(), &d->access, openMode, NULL) == SQLITE_OK) { + sqlite3_busy_timeout(d->access, timeOut); setOpen(true); setOpenError(false); return true; |