Commit 7e4dbf81 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

sqlite: transaction: Acquire the lock for the whole transaction lifetime

parent 547e4567
......@@ -30,7 +30,10 @@
#include <thread>
#include <unordered_map>
#include "SqliteTransaction.h"
namespace sqlite
{
class Transaction;
}
class SqliteConnection
{
......
......@@ -36,6 +36,7 @@
#include "database/SqliteConnection.h"
#include "database/SqliteErrors.h"
#include "database/SqliteTraits.h"
#include "database/SqliteTransaction.h"
#include "logging/Logger.h"
namespace sqlite
......
......@@ -31,6 +31,7 @@ thread_local Transaction* Transaction::CurrentTransaction = nullptr;
Transaction::Transaction(DBConnection dbConn)
: m_dbConn( dbConn )
, m_ctx( dbConn->acquireContext() )
{
assert( CurrentTransaction == nullptr );
LOG_DEBUG( "Starting SQLite transaction" );
......@@ -43,8 +44,6 @@ Transaction::Transaction(DBConnection dbConn)
void Transaction::commit()
{
auto ctx = m_dbConn->acquireContext();
auto chrono = std::chrono::steady_clock::now();
Statement s( m_dbConn, "COMMIT" );
s.execute();
......
......@@ -23,6 +23,7 @@
#pragma once
#include "Types.h"
#include "SqliteConnection.h"
namespace sqlite
{
......@@ -37,6 +38,7 @@ public:
private:
DBConnection m_dbConn;
SqliteConnection::RequestContext m_ctx;
static thread_local Transaction* CurrentTransaction;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment