diff options
author | Marco Bubke <marco.bubke@qt.io> | 2023-05-21 14:00:57 +0200 |
---|---|---|
committer | Marco Bubke <marco.bubke@qt.io> | 2023-05-30 11:20:00 +0000 |
commit | 8330d4463ac8fd174373e06ea2cd68c55ad4a3d8 (patch) | |
tree | 1f3b4e143d40009b6ad01d7d655fe71e834f6b32 /src/libs/sqlite | |
parent | 9773e523ced8410f20ffc17427983904fae5a028 (diff) |
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>
Diffstat (limited to 'src/libs/sqlite')
-rw-r--r-- | src/libs/sqlite/sqlitebasestatement.cpp | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/src/libs/sqlite/sqlitebasestatement.cpp b/src/libs/sqlite/sqlitebasestatement.cpp index 91b417bea1..d9d677c395 100644 --- a/src/libs/sqlite/sqlitebasestatement.cpp +++ b/src/libs/sqlite/sqlitebasestatement.cpp @@ -274,6 +274,9 @@ void BaseStatement::bind(int index, ValueView value) void BaseStatement::prepare(Utils::SmallStringView sqlStatement) { + if (!m_database.isLocked()) + throw DatabaseIsNotLocked{}; + int resultCode; do { |