diff options
author | Constantin Michael <constantin@codesynthesis.com> | 2011-05-13 15:56:57 +0200 |
---|---|---|
committer | Constantin Michael <constantin@codesynthesis.com> | 2011-05-13 15:56:57 +0200 |
commit | 10a83d0453f65c41c3915c906f2d6cf9d6ff349e (patch) | |
tree | ca13498579d9f15c1265eccd3b28755454580cbd /odb/pgsql/transaction-impl.cxx | |
parent | 3faf8e7a8aa2411f207fa09fe81982615d90a726 (diff) |
Add PGresult pointer wrapper
Diffstat (limited to 'odb/pgsql/transaction-impl.cxx')
-rw-r--r-- | odb/pgsql/transaction-impl.cxx | 49 |
1 files changed, 13 insertions, 36 deletions
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 <odb/pgsql/error.hxx> #include <odb/pgsql/exceptions.hxx> #include <odb/pgsql/transaction-impl.hxx> +#include <odb/pgsql/result-ptr.hxx> 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); } } } |