Commit ea8620c7 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Check whether there's already an open database connection

parent 663255d0
......@@ -84,13 +84,17 @@ bool KisResourceCacheDb::initialize(const QString &location) const
QSqlError KisResourceCacheDb::Private::initDb(const QString &location)
{
QSqlDatabase db = QSqlDatabase::addDatabase(dbDriver);
if (!QSqlDatabase::connectionNames().isEmpty()) {
return QSqlError();
}
QDir dbLocation(location);
if (!dbLocation.exists()) {
dbLocation.mkpath(dbLocation.path());
}
QSqlDatabase db = QSqlDatabase::addDatabase(dbDriver);
db.setDatabaseName(location + "/" + ResourceCacheDbFilename);
if (!db.open()) {
......
......@@ -57,6 +57,10 @@ void TestResourceCacheDb::testCreateDatabase()
Q_FOREACH(const QString &table, tables) {
QVERIFY2(dbTables.contains(table), table.toLatin1());
}
res = cacheDb.initialize(QStandardPaths::writableLocation(QStandardPaths::AppDataLocation));
QVERIFY(res);
QVERIFY(cacheDb.isValid());
}
void TestResourceCacheDb::testLookupTables()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment