forked from qt-creator/qt-creator
Sqlite: Fix that prepare is not checking that the database is locked
The database has to be locked because otherwise it is not thread save. Because Sqlite connections are already called in different threads this has to be enforced. The easiest way to lock a database is to put it in a transaction. It should be ok without locking so long the connection is only called from one thread but I prefer to enforce it because I have already seen code was preparing a statement not on initialization stage where it is highly unlikely that there is more than one thread pre connection but in the middle of the code. Because preparing is much more expensive than a lock I prefer to enfore a lock here. Change-Id: Id0b47f8d615a6697bb807392cafbe976bdd37233 Reviewed-by: Vikas Pachdha <vikas.pachdha@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -95,7 +95,8 @@ TEST_F(SqliteDatabase, CreateDatabaseWithLockingModeNormal)
|
||||
|
||||
Sqlite::Database database{path, JournalMode::Wal, Sqlite::LockingMode::Normal};
|
||||
|
||||
ASSERT_THAT(database.lockingMode(), Sqlite::LockingMode::Normal);
|
||||
ASSERT_THAT(Sqlite::withImmediateTransaction(database, [&] { return database.lockingMode(); }),
|
||||
Sqlite::LockingMode::Normal);
|
||||
}
|
||||
|
||||
TEST_F(SqliteDatabase, ExclusivelyLockedDatabaseIsLockedForSecondConnection)
|
||||
|
||||
Reference in New Issue
Block a user