From cbf166d0ab01ce277f9f2a317fd6dabf876e7d04 Mon Sep 17 00:00:00 2001 From: Rob Hoelz Date: Tue, 22 Apr 2014 00:11:25 -0500 Subject: [PATCH] Don't add the database before verification The local storage facility exposed to QML has a bug; if you attempt to open a versioned connection, the version is wrong, and you try to handle that error, the connection is still stored in a connection pool, but in an unopened state. The next time you attempt to connect, no matter if you have the version right or not, the database handle will complain about being unopened. See also http://qt-project.org/forums/viewthread/38458/ Task-number: QTBUG-38543 Change-Id: I921b94621009f4968144e1cc513c17b4924a792a Reviewed-by: Lars Knoll Reviewed-by: Alan Alpert (Personal) <416365416c@gmail.com> --- src/imports/localstorage/plugin.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/imports/localstorage/plugin.cpp b/src/imports/localstorage/plugin.cpp index 7a7649c..d5dbeeb 100644 --- a/src/imports/localstorage/plugin.cpp +++ b/src/imports/localstorage/plugin.cpp @@ -694,7 +694,6 @@ void QQuickLocalStorage::openDatabaseSync(QQmlV4Function *args) V4THROW_SQL2(SQLEXCEPTION_VERSION_ERR, QQmlEngine::tr("SQL: database version mismatch")); } else { created = !QFile::exists(basename+QLatin1String(".sqlite")); - database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid); if (created) { ini.setValue(QLatin1String("Name"), dbname); if (dbcreationCallback) @@ -710,6 +709,7 @@ void QQuickLocalStorage::openDatabaseSync(QQmlV4Function *args) } version = ini.value(QLatin1String("Version")).toString(); } + database = QSqlDatabase::addDatabase(QLatin1String("QSQLITE"), dbid); database.setDatabaseName(basename+QLatin1String(".sqlite")); } if (!database.isOpen()) -- 2.7.4