From dadccef8613f93dc2f3cab7b69e0bdf8e7b6de87 Mon Sep 17 00:00:00 2001 From: mgrojo Date: Sun, 4 Nov 2018 23:55:24 +0100 Subject: [PATCH] Avoid deadlock and cancel dialog when using conditional formats When a conditional format is used and the table does not load all the rows at once, a deadlock ocurred when scrolling to a not yet loaded area. This avoids the deadlock by unlocking before the conditional format query is performed. Additionally the cancel-query dialog is avoided when the threading mode of SQLite is Serialize, since in that case the queries can be sent to SQLite concurrently. See discussion in PR #1503 --- src/sqlitedb.cpp | 6 +++++- src/sqlitetablemodel.cpp | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/sqlitedb.cpp b/src/sqlitedb.cpp index 274e8b14..9aaf1ab2 100644 --- a/src/sqlitedb.cpp +++ b/src/sqlitedb.cpp @@ -988,10 +988,14 @@ bool DBBrowserDB::executeMultiSQL(const QString& statement, bool dirty, bool log QByteArray DBBrowserDB::querySingleValueFromDb(const QString& sql, bool log) { - waitForDbRelease(); if(!_db) return QByteArray(); + // If the threading mode is Single-thread or Multi-thread then wait for + // the DB release. + if (sqlite3_db_mutex(_db) == nullptr) + waitForDbRelease(); + if(log) logSQL(sql, kLogMsg_App); diff --git a/src/sqlitetablemodel.cpp b/src/sqlitetablemodel.cpp index 1210211e..0c073e42 100644 --- a/src/sqlitetablemodel.cpp +++ b/src/sqlitetablemodel.cpp @@ -314,6 +314,8 @@ QVariant SqliteTableModel::data(const QModelIndex &index, int role) const else sql = QString("SELECT '%1' %2").arg(value, eachCondFormat.sqlCondition()); + // Unlock before querying from DB + lock.unlock(); if (m_db.querySingleValueFromDb(sql, false) == "1") return eachCondFormat.color(); }