SocketApi: Properly manage the database connections.

Removed the fishy closeDb() method of SqlQuery again.
This commit is contained in:
Klaas Freitag 2014-10-20 17:31:00 +02:00
parent f0dc3725e8
commit 26f068bcab
4 changed files with 11 additions and 12 deletions

View file

@ -286,11 +286,4 @@ void SqlQuery::reset()
SQLITE_DO(sqlite3_reset(_stmt));
}
void SqlQuery::closeDb()
{
if( _db) {
SQLITE_DO(sqlite3_close(_db) );
_db = 0;
}
}
} // namespace Mirall

View file

@ -57,9 +57,6 @@ public:
quint64 int64Value(int index);
QByteArray baValue(int index);
// use only in rare cases, invalidates the internal db object.
void closeDb();
bool isSelect();
bool isPragma();
bool exec();

View file

@ -229,10 +229,16 @@ void SocketApi::slotUnregisterPath( const QString& alias )
SqlQuery *h = _dbQueries[f];
if( h ) {
h->finish();
h->closeDb();
}
_dbQueries.remove(f);
}
if( _openDbs.contains(f) ) {
SqlDatabase *db = _openDbs[f];
if( db ) {
db->close();
}
_openDbs.remove(f);
}
}
}
@ -393,7 +399,9 @@ SqlQuery* SocketApi::getSqlQuery( Folder *folder )
if( fi.exists() ) {
SqlDatabase *db = new SqlDatabase;
if( db->open(dbFileName) ) {
if( db && db->open(dbFileName) ) {
_openDbs.insert(folder, db);
SqlQuery *query = new SqlQuery(*db);
rc = query->prepare(sql);

View file

@ -86,6 +86,7 @@ private:
QList<SocketType*> _listeners;
c_strlist_t *_excludes;
QHash<Folder*, SqlQuery*> _dbQueries;
QHash<Folder*, SqlDatabase*> _openDbs;
};
}