From 78e81069aadc609aee1e4b8137516d9cfce47b0a Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Wed, 11 May 2011 10:58:27 +0200 Subject: Add transaction implementation --- odb/pgsql/transaction-impl.cxx | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 odb/pgsql/transaction-impl.cxx (limited to 'odb/pgsql/transaction-impl.cxx') diff --git a/odb/pgsql/transaction-impl.cxx b/odb/pgsql/transaction-impl.cxx new file mode 100644 index 0000000..2d2a988 --- /dev/null +++ b/odb/pgsql/transaction-impl.cxx @@ -0,0 +1,80 @@ +// file : odb/pgsql/transaction-impl.cxx +// author : Constantin Michael +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include + +#include + +#include +#include +#include +#include +#include + +namespace odb +{ + namespace pgsql + { + transaction_impl:: + transaction_impl (database_type& db) + : odb::transaction_impl (db), connection_ (db.connection ()) + { + PGresult* r (PQexec (connection_->handle (), "begin")); + + if (!r) + translate_result_error (*connection_); + + ExecStatusType s (PQresultStatus (r)); + + if (PGRES_COMMAND_OK != s) + translate_result_error (*connection_, r, s); + } + + transaction_impl:: + ~transaction_impl () + { + } + + void transaction_impl:: + commit () + { + // connection_->clear (); + + PGresult* r (PQexec (connection_->handle (), "commit")); + + if (!r) + translate_result_error (*connection_); + + ExecStatusType s (PQresultStatus (r)); + + if (PGRES_COMMAND_OK != s) + translate_result_error (*connection_, r, s); + + // Release the connection. + // + // connection_.reset (); + } + + void transaction_impl:: + rollback () + { + // connection_->clear (); + + PGresult* r (PQexec (connection_->handle (), "rollback")); + + if (!r) + translate_result_error (*connection_); + + ExecStatusType s (PQresultStatus (r)); + + if (PGRES_COMMAND_OK != s) + translate_result_error (*connection_, r, s); + + // Release the connection. + // + //connection_.reset (); + } + } +} -- cgit v1.1