Subject: | connection failure reported as 'data exception' (22000) |
After a libpq-function has been executed in dbdimp.c, the
_sqlstate-routine is used to fill the sqlstate-buffer of an
implementation database handle structure with a sensible SQLSTATE
value, based on the PGresult returned by the original call
and the PG_DIAG_SQLSTATE value which can be queried from it.
In absence of this information, the code tries to map the
PQresultStatus-value associated with the PGresult to a SQLSTATE
on its own. In particular, a status-value of PGRES_FATAL_ERROR will be
translated to a 'data exception'-code (22000). This is the default
action if no other information was available, including the case
where the PGresult * passed to _sqlstate was NULL. But returning a
NULL PGresult * is the way libpq-routines signal a connection failure
to their callers. Using SQLSTATE 08006 ('connection failure') seems
more appropriate for this case.
The attached file contains a patch changing the code to do so.
Subject: | 08006.txt |
Index: DBD-Pg/dbdimp.c
===================================================================
RCS file: /sysdata/cvs/DBD-Pg/dbdimp.c,v
retrieving revision 1.1.1.1
retrieving revision 1.1.1.1.4.1
diff -u -r1.1.1.1 -r1.1.1.1.4.1
--- DBD-Pg/dbdimp.c 1 Apr 2009 15:18:00 -0000 1.1.1.1
+++ DBD-Pg/dbdimp.c 2 Apr 2009 11:28:59 -0000 1.1.1.1.4.1
@@ -377,6 +377,12 @@
strncpy(imp_dbh->sqlstate, "01000", 6); /* WARNING */
break;
case PGRES_FATAL_ERROR:
+ if (!result) {
+ /* CONNECTION FAILURE */
+ strncpy(imp_dbh->sqlstate, "08006", 6);
+ break;
+ }
+
default:
strncpy(imp_dbh->sqlstate, "22000", 6); /* DATA EXCEPTION */
break;