aboutsummaryrefslogtreecommitdiff
path: root/odb/sqlite/transaction-impl.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/sqlite/transaction-impl.cxx')
-rw-r--r--odb/sqlite/transaction-impl.cxx84
1 files changed, 56 insertions, 28 deletions
diff --git a/odb/sqlite/transaction-impl.cxx b/odb/sqlite/transaction-impl.cxx
index aabb900..6485f7e 100644
--- a/odb/sqlite/transaction-impl.cxx
+++ b/odb/sqlite/transaction-impl.cxx
@@ -1,5 +1,4 @@
// file : odb/sqlite/transaction-impl.cxx
-// copyright : Copyright (c) 2009-2019 Code Synthesis Tools CC
// license : GNU GPL v2; see accompanying LICENSE file
#include <sqlite3.h>
@@ -7,7 +6,6 @@
#include <odb/sqlite/database.hxx>
#include <odb/sqlite/connection.hxx>
#include <odb/sqlite/statement.hxx>
-#include <odb/sqlite/statement-cache.hxx>
#include <odb/sqlite/transaction-impl.hxx>
namespace odb
@@ -44,23 +42,23 @@ namespace odb
odb::transaction_impl::connection_ = connection_.get ();
}
- statement_cache& sc (connection_->statement_cache ());
+ connection_type& mc (connection_->main_connection ());
switch (lock_)
{
case deferred:
{
- sc.begin_statement ().execute ();
+ mc.begin_statement ().execute ();
break;
}
case immediate:
{
- sc.begin_immediate_statement ().execute ();
+ mc.begin_immediate_statement ().execute ();
break;
}
case exclusive:
{
- sc.begin_exclusive_statement ().execute ();
+ mc.begin_exclusive_statement ().execute ();
break;
}
}
@@ -83,7 +81,7 @@ namespace odb
//
try
{
- c_->statement_cache ().rollback_statement ().execute ();
+ c_->rollback_statement ().execute ();
}
catch (...) {}
}
@@ -96,21 +94,22 @@ namespace odb
void transaction_impl::
commit ()
{
- // Invalidate query results.
- //
- connection_->invalidate_results ();
+ connection_type& mc (connection_->main_connection ());
- // Reset active statements. Active statements will prevent COMMIT
- // from completing (write statements) or releasing the locks (read
- // statements). Normally, a statement is automatically reset on
- // completion, however, if an exception is thrown, that may not
- // happen.
+ // Invalidate query results and reset active statements.
+ //
+ // Active statements will prevent COMMIT from completing (write
+ // statements) or releasing the locks (read statements). Normally, a
+ // statement is automatically reset on completion, however, if an
+ // exception is thrown, that may not happen.
+ //
+ // Note: must be done via the main connection.
//
- connection_->clear ();
+ mc.clear ();
{
- commit_guard cg (*connection_);
- connection_->statement_cache ().commit_statement ().execute ();
+ commit_guard cg (mc);
+ mc.commit_statement ().execute ();
cg.release ();
}
@@ -122,23 +121,52 @@ namespace odb
void transaction_impl::
rollback ()
{
- // Invalidate query results.
- //
- connection_->invalidate_results ();
+ connection_type& mc (connection_->main_connection ());
- // Reset active statements. Active statements will prevent ROLLBACK
- // from completing (write statements) or releasing the locks (read
- // statements). Normally, a statement is automatically reset on
- // completion, however, if an exception is thrown, that may not
- // happen.
+ // Invalidate query results and reset active statements (the same
+ // reasoning as in commit()).
+ //
+ // Note: must be done via the main connection.
//
- connection_->clear ();
+ mc.clear ();
- connection_->statement_cache ().rollback_statement ().execute ();
+ mc.rollback_statement ().execute ();
// Release the connection.
//
connection_.reset ();
}
+
+ odb::connection& transaction_impl::
+ connection (odb::database* pdb)
+ {
+ if (pdb == 0)
+ return *connection_;
+
+ // Pick the corresponding connection for main/attached database.
+ //
+ database_type& db (static_cast<database_type&> (*pdb));
+
+ assert (&db.main_database () ==
+ &static_cast<database_type&> (database_).main_database ());
+
+ return db.schema ().empty ()
+ ? connection_->main_connection ()
+ : *static_cast<attached_connection_factory&> (*db.factory_).attached_connection_;
+ }
+
+ // Store transaction tracer in the main connection.
+ //
+ void transaction_impl::
+ tracer (odb::tracer* t)
+ {
+ connection_->main_connection ().transaction_tracer_ = t;
+ }
+
+ odb::tracer* transaction_impl::
+ tracer () const
+ {
+ return connection_->main_connection ().transaction_tracer_;
+ }
}
}