diff options
author | Constantin Michael <constantin@codesynthesis.com> | 2011-05-11 10:58:27 +0200 |
---|---|---|
committer | Constantin Michael <constantin@codesynthesis.com> | 2011-05-11 10:58:27 +0200 |
commit | 78e81069aadc609aee1e4b8137516d9cfce47b0a (patch) | |
tree | 98c7c4f7e4e728bb32e8f420ab3aa937ba2a3445 /odb/pgsql/transaction-impl.cxx | |
parent | 3cdf7c4e3f6b085b4b386d4da64f3fbf396375a3 (diff) |
Add transaction implementation
Diffstat (limited to 'odb/pgsql/transaction-impl.cxx')
-rw-r--r-- | odb/pgsql/transaction-impl.cxx | 80 |
1 files changed, 80 insertions, 0 deletions
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 <constantin@codesynthesis.com> +// copyright : Copyright (c) 2009-2011 Code Synthesis Tools CC +// license : GNU GPL v2; see accompanying LICENSE file + +#include <cassert> + +#include <libpq-fe.h> + +#include <odb/pgsql/database.hxx> +#include <odb/pgsql/connection.hxx> +#include <odb/pgsql/error.hxx> +#include <odb/pgsql/exceptions.hxx> +#include <odb/pgsql/transaction-impl.hxx> + +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 (); + } + } +} |