forked from qt-creator/qt-creator
Sqlite: Add locking for sqlite transactions
If you use the database in a multi-threaded environment, you must always your statements in transactions. For read-only statements, you use DeferredTransaction and write statements you use ImmediateTransaction. If you mix read and write statements you have to use ImmediateTransaction. Don't use DeferredTransaction because it leads to undefined behavior. Change-Id: Ida298a20f33423c8da09e768a7b658dd8e918f46 Reviewed-by: Tim Jenssen <tim.jenssen@qt.io> Reviewed-by: Marco Bubke <marco.bubke@qt.io>
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
|
||||
#include <utils/smallstring.h>
|
||||
|
||||
#include <mutex>
|
||||
#include <vector>
|
||||
|
||||
namespace Sqlite {
|
||||
@@ -38,11 +39,13 @@ namespace Sqlite {
|
||||
class SQLITE_EXPORT Database
|
||||
{
|
||||
template <typename Database>
|
||||
friend class SqliteAbstractTransaction;
|
||||
friend class SqliteStatement;
|
||||
friend class SqliteBackend;
|
||||
friend class AbstractTransaction;
|
||||
friend class Statement;
|
||||
friend class Backend;
|
||||
|
||||
public:
|
||||
using MutexType = std::mutex;
|
||||
|
||||
Database();
|
||||
Database(Utils::PathString &&databaseFilePath);
|
||||
|
||||
@@ -79,12 +82,13 @@ public:
|
||||
|
||||
private:
|
||||
void initializeTables();
|
||||
|
||||
std::mutex &databaseMutex() { return m_databaseMutex; }
|
||||
|
||||
private:
|
||||
Utils::PathString m_databaseFilePath;
|
||||
DatabaseBackend m_databaseBackend;
|
||||
std::vector<Table> m_sqliteTables;
|
||||
Utils::PathString m_databaseFilePath;
|
||||
std::mutex m_databaseMutex;
|
||||
JournalMode m_journalMode = JournalMode::Wal;
|
||||
OpenMode m_openMode = OpenMode::ReadWrite;
|
||||
bool m_isOpen = false;
|
||||
|
||||
Reference in New Issue
Block a user