From dce9ac4635ec667a27712ad4b0251c1a2ca5df06 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Thu, 1 Dec 2011 12:09:07 +0200 Subject: Detect and mark connection as failed --- odb/pgsql/error.cxx | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'odb/pgsql/error.cxx') diff --git a/odb/pgsql/error.cxx b/odb/pgsql/error.cxx index 149654d..ae9cbc2 100644 --- a/odb/pgsql/error.cxx +++ b/odb/pgsql/error.cxx @@ -17,26 +17,15 @@ namespace odb namespace pgsql { void - translate_error (connection& c) - { - PGconn* h (c.handle ()); - - assert (CONNECTION_BAD == PQstatus (h)); - - if (const char* m = PQerrorMessage (h)) - throw database_exception (m); - else - throw database_exception ("unknown error"); - } - - void - translate_error (connection& c, - PGresult* r) + translate_error (connection& c, PGresult* r) { if (!r) { if (CONNECTION_BAD == PQstatus (c.handle ())) + { + c.mark_failed (); throw connection_lost (); + } else throw bad_alloc (); } @@ -66,8 +55,10 @@ namespace odb throw deadlock (); else if (CONNECTION_BAD == PQstatus (c.handle ())) + { + c.mark_failed (); throw connection_lost (); - + } else throw database_exception (ss, error_message); } -- cgit v1.1