diff options
Diffstat (limited to 'odb/pgsql/transaction-impl.cxx')
-rw-r--r-- | odb/pgsql/transaction-impl.cxx | 29 |
1 files changed, 24 insertions, 5 deletions
diff --git a/odb/pgsql/transaction-impl.cxx b/odb/pgsql/transaction-impl.cxx index 81aaf08..c3ce31d 100644 --- a/odb/pgsql/transaction-impl.cxx +++ b/odb/pgsql/transaction-impl.cxx @@ -19,14 +19,15 @@ namespace odb namespace pgsql { 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) { - result_ptr r (PQexec (connection_->handle (), "begin")); - PGresult* h (r.get ()); - - if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) - translate_error (*connection_, h); } transaction_impl:: @@ -35,6 +36,24 @@ 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 (); + } + + result_ptr r (PQexec (connection_->handle (), "begin")); + PGresult* h (r.get ()); + + if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) + translate_error (*connection_, h); + } + + void transaction_impl:: commit () { result_ptr r (PQexec (connection_->handle (), "commit")); |