From ca3885de2a2dde8965a5df670e360bce2d887bc0 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Mon, 25 Nov 2013 15:07:58 +0100 Subject: [PATCH] Fix some SQL error and warning Such as: Error opening the db: "Driver not loaded Driver not loaded" or QSqlDatabasePrivate::removeDatabase: connection '...' is still in use, all queries will cease to wor We need to clear the QSqlDatabase _db handle before calling removeDatabase. And we also need to give a different name to different folder database, just to be sure --- src/mirall/syncjournaldb.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/mirall/syncjournaldb.cpp b/src/mirall/syncjournaldb.cpp index 6fad9e84da..dff57ec804 100644 --- a/src/mirall/syncjournaldb.cpp +++ b/src/mirall/syncjournaldb.cpp @@ -24,7 +24,6 @@ #include "syncjournalfilerecord.h" #define QSQLITE "QSQLITE" -#define SYNCJOURNALDB_CONNECTION_NAME "SyncJournalDbConnection" namespace Mirall { @@ -105,9 +104,7 @@ bool SyncJournalDb::checkConnect() } // Add the connection - if (!QSqlDatabase::connectionNames().contains(SYNCJOURNALDB_CONNECTION_NAME)) { - _db = QSqlDatabase::addDatabase( QSQLITE, SYNCJOURNALDB_CONNECTION_NAME ); - } + _db = QSqlDatabase::addDatabase( QSQLITE, _dbFile); // Open the file _db.setDatabaseName(_dbFile); @@ -261,9 +258,9 @@ void SyncJournalDb::close() _deleteFileRecordRecursively.reset(0); _blacklistQuery.reset(0); - _db.removeDatabase(SYNCJOURNALDB_CONNECTION_NAME); - _db.setDatabaseName(QString()); _db.close(); + _db = QSqlDatabase(); // avoid the warning QSqlDatabasePrivate::removeDatabase: connection [...] still in use + QSqlDatabase::removeDatabase(_dbFile); } @@ -752,7 +749,7 @@ void SyncJournalDb::commit(const QString& context, bool startTrans ) SyncJournalDb::~SyncJournalDb() { - commitTransaction(); + close(); }