From 10a83d0453f65c41c3915c906f2d6cf9d6ff349e Mon Sep 17 00:00:00 2001 From: Constantin Michael Date: Fri, 13 May 2011 15:56:57 +0200 Subject: Add PGresult pointer wrapper --- odb/pgsql/transaction-impl.cxx | 49 +++++++++++------------------------------- 1 file changed, 13 insertions(+), 36 deletions(-) (limited to 'odb/pgsql/transaction-impl.cxx') diff --git a/odb/pgsql/transaction-impl.cxx b/odb/pgsql/transaction-impl.cxx index 2d2a988..eb93361 100644 --- a/odb/pgsql/transaction-impl.cxx +++ b/odb/pgsql/transaction-impl.cxx @@ -12,6 +12,7 @@ #include #include #include +#include namespace odb { @@ -21,15 +22,11 @@ namespace odb transaction_impl (database_type& db) : odb::transaction_impl (db), connection_ (db.connection ()) { - PGresult* r (PQexec (connection_->handle (), "begin")); + result_ptr r (PQexec (connection_->handle (), "begin")); + PGresult* h (r.get ()); - if (!r) - translate_result_error (*connection_); - - ExecStatusType s (PQresultStatus (r)); - - if (PGRES_COMMAND_OK != s) - translate_result_error (*connection_, r, s); + if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) + translate_error (*connection_, h); } transaction_impl:: @@ -40,41 +37,21 @@ namespace odb void transaction_impl:: commit () { - // connection_->clear (); - - PGresult* r (PQexec (connection_->handle (), "commit")); - - if (!r) - translate_result_error (*connection_); - - ExecStatusType s (PQresultStatus (r)); + result_ptr r (PQexec (connection_->handle (), "commit")); + PGresult* h (r.get ()); - if (PGRES_COMMAND_OK != s) - translate_result_error (*connection_, r, s); - - // Release the connection. - // - // connection_.reset (); + if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) + translate_error (*connection_, h); } 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); + result_ptr r (PQexec (connection_->handle (), "rollback")); + PGresult* h (r.get ()); - // Release the connection. - // - //connection_.reset (); + if (!h || PGRES_COMMAND_OK != PQresultStatus (h)) + translate_error (*connection_, h); } } } -- cgit v1.1