From 9fce9a7250f63a2a3cceeb0aac7b22d5dd7e6915 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Tue, 30 Aug 2011 16:10:02 +0200 Subject: Implement uniform handle management across all databases Also use the auto_handle template instead of the raw handle in connection, statement, and result classes. This removes a lot of brittle "exception safety guarantee" code that we had in those classes. --- odb/pgsql/connection.cxx | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) (limited to 'odb/pgsql/connection.cxx') diff --git a/odb/pgsql/connection.cxx b/odb/pgsql/connection.cxx index be88446..6f0feaf 100644 --- a/odb/pgsql/connection.cxx +++ b/odb/pgsql/connection.cxx @@ -16,7 +16,6 @@ #include #include #include -#include using namespace std; @@ -33,17 +32,12 @@ namespace odb connection (database_type& db) : odb::connection (db), db_ (db) { - handle_ = PQconnectdb (db.conninfo ().c_str ()); + handle_.reset (PQconnectdb (db.conninfo ().c_str ())); if (handle_ == 0) throw bad_alloc (); else if (PQstatus (handle_) == CONNECTION_BAD) - { - std::string m (PQerrorMessage (handle_)); - PQfinish (handle_); - - throw database_exception (m); - } + throw database_exception (PQerrorMessage (handle_)); init (); } @@ -77,11 +71,6 @@ namespace odb connection:: ~connection () { - // Deallocate prepared statements before we close the connection. - // - statement_cache_.reset (); - - PQfinish (handle_); } transaction_impl* connection:: @@ -97,8 +86,7 @@ namespace odb // string str (s, n); - result_ptr r (PQexec (handle_, str.c_str ())); - PGresult* h (r.get ()); + auto_handle h (PQexec (handle_, str.c_str ())); unsigned long long count (0); -- cgit v1.1