aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/mysql/connection.cxx3
-rw-r--r--odb/mysql/database.cxx6
-rw-r--r--odb/mysql/database.hxx2
-rw-r--r--odb/mysql/database.ixx6
-rw-r--r--odb/mysql/transaction-impl.cxx23
-rw-r--r--odb/mysql/transaction-impl.hxx9
-rw-r--r--odb/mysql/transaction.hxx5
-rw-r--r--odb/mysql/transaction.ixx6
8 files changed, 44 insertions, 16 deletions
diff --git a/odb/mysql/connection.cxx b/odb/mysql/connection.cxx
index fe4996f..b783f69 100644
--- a/odb/mysql/connection.cxx
+++ b/odb/mysql/connection.cxx
@@ -77,9 +77,6 @@ namespace odb
transaction_impl* connection::
begin ()
{
- if (transaction::has_current ())
- throw already_in_transaction ();
-
return new transaction_impl (connection_ptr (inc_ref (this)));
}
diff --git a/odb/mysql/database.cxx b/odb/mysql/database.cxx
index dc78bce..d37351f 100644
--- a/odb/mysql/database.cxx
+++ b/odb/mysql/database.cxx
@@ -208,6 +208,12 @@ namespace odb
details::options::print_usage (os);
}
+ transaction_impl* database::
+ begin ()
+ {
+ return new transaction_impl (*this);
+ }
+
odb::connection* database::
connection_ ()
{
diff --git a/odb/mysql/database.hxx b/odb/mysql/database.hxx
index 37b966f..ba4ee80 100644
--- a/odb/mysql/database.hxx
+++ b/odb/mysql/database.hxx
@@ -157,7 +157,7 @@ namespace odb
}
public:
- transaction_impl*
+ virtual transaction_impl*
begin ();
public:
diff --git a/odb/mysql/database.ixx b/odb/mysql/database.ixx
index 399fbdc..3c0e6de 100644
--- a/odb/mysql/database.ixx
+++ b/odb/mysql/database.ixx
@@ -16,11 +16,5 @@ namespace odb
return connection_ptr (
static_cast<mysql::connection*> (connection_ ()));
}
-
- inline transaction_impl* database::
- begin ()
- {
- return connection ()->begin ();
- }
}
}
diff --git a/odb/mysql/transaction-impl.cxx b/odb/mysql/transaction-impl.cxx
index 86cccbe..24c511f 100644
--- a/odb/mysql/transaction-impl.cxx
+++ b/odb/mysql/transaction-impl.cxx
@@ -14,11 +14,15 @@ namespace odb
namespace mysql
{
transaction_impl::
+ transaction_impl (database_type& db)
+ : odb::transaction_impl (db)
+ {
+ }
+
+ transaction_impl::
transaction_impl (connection_ptr c)
: odb::transaction_impl (c->database (), *c), connection_ (c)
{
- if (mysql_real_query (connection_->handle (), "begin", 5) != 0)
- translate_error (*connection_);
}
transaction_impl::
@@ -27,6 +31,21 @@ namespace odb
}
void transaction_impl::
+ start ()
+ {
+ // Grab a connection if we don't already have one.
+ //
+ if (connection_ == 0)
+ {
+ connection_ = static_cast<database_type&> (database_).connection ();
+ odb::transaction_impl::connection_ = connection_.get ();
+ }
+
+ if (mysql_real_query (connection_->handle (), "begin", 5) != 0)
+ translate_error (*connection_);
+ }
+
+ void transaction_impl::
commit ()
{
connection_->clear ();
diff --git a/odb/mysql/transaction-impl.hxx b/odb/mysql/transaction-impl.hxx
index a8aa491..db87147 100644
--- a/odb/mysql/transaction-impl.hxx
+++ b/odb/mysql/transaction-impl.hxx
@@ -23,19 +23,20 @@ namespace odb
{
class LIBODB_MYSQL_EXPORT transaction_impl: public odb::transaction_impl
{
- protected:
- friend class connection;
- friend class transaction;
-
+ public:
typedef mysql::database database_type;
typedef mysql::connection connection_type;
+ transaction_impl (database_type&);
transaction_impl (connection_ptr);
virtual
~transaction_impl ();
virtual void
+ start ();
+
+ virtual void
commit ();
virtual void
diff --git a/odb/mysql/transaction.hxx b/odb/mysql/transaction.hxx
index cd666b3..90182e1 100644
--- a/odb/mysql/transaction.hxx
+++ b/odb/mysql/transaction.hxx
@@ -46,6 +46,11 @@ namespace odb
static transaction&
current ();
+ // Set the current thread's transaction.
+ //
+ static void
+ current (transaction&);
+
public:
transaction_impl&
implementation ();
diff --git a/odb/mysql/transaction.ixx b/odb/mysql/transaction.ixx
index 5846632..39fb5d1 100644
--- a/odb/mysql/transaction.ixx
+++ b/odb/mysql/transaction.ixx
@@ -37,5 +37,11 @@ namespace odb
{
return implementation ().connection ();
}
+
+ inline void transaction::
+ current (transaction& t)
+ {
+ odb::transaction::current (t);
+ }
}
}