From 7392db256c1587ff8fe87d95c5ae5c10f854f79e Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 24 Aug 2011 13:42:04 +0200 Subject: Add support for transaction multiplexing Also delay getting a connection until after we do all the sanity checks (e.g., that there is no active transaction). Otherwise we are running risk of getting blocked rather than throwing an exception. --- odb/sqlite/transaction-impl.cxx | 35 ++++++++++++++++++++++++++++------- 1 file changed, 28 insertions(+), 7 deletions(-) (limited to 'odb/sqlite/transaction-impl.cxx') diff --git a/odb/sqlite/transaction-impl.cxx b/odb/sqlite/transaction-impl.cxx index 772b274..b425ed8 100644 --- a/odb/sqlite/transaction-impl.cxx +++ b/odb/sqlite/transaction-impl.cxx @@ -14,12 +14,38 @@ namespace odb namespace sqlite { transaction_impl:: + transaction_impl (database_type& db, lock l) + : odb::transaction_impl (db), lock_ (l) + { + } + + transaction_impl:: transaction_impl (connection_ptr c, lock l) - : odb::transaction_impl (c->database (), *c), connection_ (c) + : odb::transaction_impl (c->database (), *c), + connection_ (c), + lock_ (l) + { + } + + transaction_impl:: + ~transaction_impl () + { + } + + void transaction_impl:: + start () { + // Grab a connection if we don't already have one. + // + if (connection_ == 0) + { + connection_ = static_cast (database_).connection (); + odb::transaction_impl::connection_ = connection_.get (); + } + statement_cache& sc (connection_->statement_cache ()); - switch (l) + switch (lock_) { case deferred: { @@ -39,11 +65,6 @@ namespace odb } } - transaction_impl:: - ~transaction_impl () - { - } - void transaction_impl:: commit () { -- cgit v1.1