forked from qt-creator/qt-creator
Sqlite: Add exception if statement is called outside of a lock
Sometimes it is really hard to trace if sqlite statement is called outside of a database connection lock. So we know throw an exception in the unit test. So we get failing tests. Change-Id: I71485b9473075751a2fb771ce7e2954e28d8413e Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
@@ -70,6 +70,8 @@ Database::Database(Utils::PathString &&databaseFilePath,
|
||||
: m_databaseBackend(*this)
|
||||
, m_busyTimeout(busyTimeout)
|
||||
{
|
||||
std::lock_guard lock{*this};
|
||||
|
||||
setJournalMode(journalMode);
|
||||
open(std::move(databaseFilePath));
|
||||
|
||||
@@ -94,7 +96,6 @@ void Database::open()
|
||||
else
|
||||
m_databaseBackend.registerBusyHandler();
|
||||
registerTransactionStatements();
|
||||
initializeTables();
|
||||
m_isOpen = true;
|
||||
}
|
||||
|
||||
@@ -127,18 +128,6 @@ bool Database::isOpen() const
|
||||
return m_isOpen;
|
||||
}
|
||||
|
||||
Table &Database::addTable()
|
||||
{
|
||||
m_sqliteTables.emplace_back();
|
||||
|
||||
return m_sqliteTables.back();
|
||||
}
|
||||
|
||||
const std::vector<Table> &Database::tables() const
|
||||
{
|
||||
return m_sqliteTables;
|
||||
}
|
||||
|
||||
void Database::setDatabaseFilePath(Utils::PathString &&databaseFilePath)
|
||||
{
|
||||
m_databaseFilePath = std::move(databaseFilePath);
|
||||
@@ -189,20 +178,6 @@ void Database::execute(Utils::SmallStringView sqlStatement)
|
||||
m_databaseBackend.execute(sqlStatement);
|
||||
}
|
||||
|
||||
void Database::initializeTables()
|
||||
{
|
||||
try {
|
||||
ExclusiveTransaction transaction(*this);
|
||||
|
||||
for (Table &table : m_sqliteTables)
|
||||
table.initialize(*this);
|
||||
|
||||
transaction.commit();
|
||||
} catch (const StatementIsBusy &) {
|
||||
initializeTables();
|
||||
}
|
||||
}
|
||||
|
||||
void Database::registerTransactionStatements()
|
||||
{
|
||||
m_statements = std::make_unique<Statements>(*this);
|
||||
@@ -257,9 +232,16 @@ void Database::sessionRollback()
|
||||
void Database::lock()
|
||||
{
|
||||
m_databaseMutex.lock();
|
||||
#ifdef UNIT_TESTS
|
||||
m_isLocked = true;
|
||||
#endif
|
||||
}
|
||||
|
||||
void Database::unlock()
|
||||
{
|
||||
#ifdef UNIT_TESTS
|
||||
m_isLocked = false;
|
||||
#endif
|
||||
m_databaseMutex.unlock();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user