diff --git a/src/database.cpp b/src/database.cpp index e45c97b7..99236a35 100644 --- a/src/database.cpp +++ b/src/database.cpp @@ -47,6 +47,8 @@ void Database::closeDatabase(const QString &connectionName) bool Database::migrate() { + setWalMode(); + int dbversion = version(); if (dbversion < 1) TRUE_OR_RETURN(migrateTo1()); @@ -200,6 +202,26 @@ int Database::version() return -1; } +void Database::setWalMode() +{ + bool ok = false; + QSqlQuery query; + query.prepare(QStringLiteral("PRAGMA journal_mode;")); + execute(query); + if (query.next()) { + ok = (query.value(0).toString() == QStringLiteral("wal")); + } + + if (!ok) { + query.prepare(QStringLiteral("PRAGMA journal_mode=WAL;")); + execute(query); + if (query.next()) { + ok = (query.value(0).toString() == QStringLiteral("wal")); + } + qDebug() << "Activating WAL mode on database:" << (ok ? "ok" : "not ok!"); + } +} + void Database::cleanup() { // TODO: create database sanity checks, or, alternatively, create database scrub routine diff --git a/src/database.h b/src/database.h index 68170b14..5cd745c4 100644 --- a/src/database.h +++ b/src/database.h @@ -43,6 +43,7 @@ private: bool migrateTo5(); bool migrateTo6(); void cleanup(); + void setWalMode(); inline static const QString m_dbName = QStringLiteral("database.db3"); };