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 @@ ...@@ -30,7 +30,10 @@
#include <thread> #include <thread>
#include <unordered_map> #include <unordered_map>
#include "SqliteTransaction.h" namespace sqlite
{
class Transaction;
}
class SqliteConnection class SqliteConnection
{ {
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include "database/SqliteConnection.h" #include "database/SqliteConnection.h"
#include "database/SqliteErrors.h" #include "database/SqliteErrors.h"
#include "database/SqliteTraits.h" #include "database/SqliteTraits.h"
#include "database/SqliteTransaction.h"
#include "logging/Logger.h" #include "logging/Logger.h"
namespace sqlite namespace sqlite
......
...@@ -31,6 +31,7 @@ thread_local Transaction* Transaction::CurrentTransaction = nullptr; ...@@ -31,6 +31,7 @@ thread_local Transaction* Transaction::CurrentTransaction = nullptr;
Transaction::Transaction(DBConnection dbConn) Transaction::Transaction(DBConnection dbConn)
: m_dbConn( dbConn ) : m_dbConn( dbConn )
, m_ctx( dbConn->acquireContext() )
{ {
assert( CurrentTransaction == nullptr ); assert( CurrentTransaction == nullptr );
LOG_DEBUG( "Starting SQLite transaction" ); LOG_DEBUG( "Starting SQLite transaction" );
...@@ -43,8 +44,6 @@ Transaction::Transaction(DBConnection dbConn) ...@@ -43,8 +44,6 @@ Transaction::Transaction(DBConnection dbConn)
void Transaction::commit() void Transaction::commit()
{ {
auto ctx = m_dbConn->acquireContext();
auto chrono = std::chrono::steady_clock::now(); auto chrono = std::chrono::steady_clock::now();
Statement s( m_dbConn, "COMMIT" ); Statement s( m_dbConn, "COMMIT" );
s.execute(); s.execute();
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#pragma once #pragma once
#include "Types.h" #include "Types.h"
#include "SqliteConnection.h"
namespace sqlite namespace sqlite
{ {
...@@ -37,6 +38,7 @@ public: ...@@ -37,6 +38,7 @@ public:
private: private:
DBConnection m_dbConn; DBConnection m_dbConn;
SqliteConnection::RequestContext m_ctx;
static thread_local Transaction* CurrentTransaction; 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