aboutsummaryrefslogtreecommitdiff
path: root/odb/pgsql/error.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'odb/pgsql/error.cxx')
-rw-r--r--odb/pgsql/error.cxx59
1 files changed, 34 insertions, 25 deletions
diff --git a/odb/pgsql/error.cxx b/odb/pgsql/error.cxx
index 5d34fde..ba8451e 100644
--- a/odb/pgsql/error.cxx
+++ b/odb/pgsql/error.cxx
@@ -15,11 +15,12 @@ namespace odb
namespace pgsql
{
void
- translate_error (connection& c, PGresult* r)
+ translate_error (connection& c, PGresult* r,
+ size_t pos, multiple_exceptions* mex)
{
if (!r)
{
- if (CONNECTION_BAD == PQstatus (c.handle ()))
+ if (PQstatus (c.handle ()) == CONNECTION_BAD)
{
c.mark_failed ();
throw connection_lost ();
@@ -28,50 +29,58 @@ namespace odb
throw bad_alloc ();
}
- string msg;
- {
- // Can be NULL in case of PGRES_BAD_RESPONSE.
- //
- const char* m (PQresultErrorMessage (r));
- msg = (m != 0 ? m : "bad server response");
-
- // Get rid of a trailing newline if there is one.
- //
- string::size_type n (msg.size ());
- if (n != 0 && msg[n - 1] == '\n')
- msg.resize (n - 1);
- }
-
+ // Note that we expect the caller to handle PGRES_PIPELINE_ABORTED since
+ // it's not really an error but rather an indication that no attempt was
+ // made to execute this statement.
+ //
+ string ss;
switch (PQresultStatus (r))
{
case PGRES_BAD_RESPONSE:
{
- throw database_exception (msg);
+ throw database_exception ("bad server response");
}
case PGRES_FATAL_ERROR:
{
- string ss;
- {
- const char* s (PQresultErrorField (r, PG_DIAG_SQLSTATE));
- ss = (s != 0 ? s : "?????");
- }
+ const char* s (PQresultErrorField (r, PG_DIAG_SQLSTATE));
+ ss = (s != 0 ? s : "?????");
// Deadlock detected.
//
if (ss == "40001" || ss == "40P01")
throw deadlock ();
- else if (CONNECTION_BAD == PQstatus (c.handle ()))
+ else if (PQstatus (c.handle ()) == CONNECTION_BAD)
{
c.mark_failed ();
throw connection_lost ();
}
- else
- throw database_exception (ss, msg);
+ break;
}
default:
assert (false);
break;
}
+
+ string msg;
+ {
+ // Can be NULL in case of PGRES_BAD_RESPONSE.
+ //
+ const char* m (PQresultErrorMessage (r));
+ msg = (m != 0 ? m : "bad server response");
+
+ // Get rid of the trailing newline if there is one.
+ //
+ string::size_type n (msg.size ());
+ if (n != 0 && msg[n - 1] == '\n')
+ msg.resize (n - 1);
+ }
+
+ if (mex == 0)
+ throw database_exception (ss, msg);
+ else
+ // In PosgreSQL all errors are fatal.
+ //
+ mex->insert (pos, database_exception (ss, msg), true);
}
}
}