[DBD::Pg] Better handling of failed libpq connections. Should fix the bug where a SQLSTATE of 08000 is expected but not returned.

dbdpg-commits-gENoVmVU/[email protected] Fri, 8 Feb 2013 13:53:07 -0500
Newsgroups gmane.comp.db.postgresql.dbdpg.cvs
Message-ID <[email protected]>
Committed by Stephen Keller <Stephen.Keller-HKixBCOQz3hWk0Htik3J/[email protected]>

Better handling of failed libpq connections. Should fix the bug where a SQLSTATE of 08000 is expected but not returned.

---
 dbdimp.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)

diff --git a/dbdimp.c b/dbdimp.c
index d8f4f88..a63e7b7 100644
--- a/dbdimp.c
+++ b/dbdimp.c
@@ -403,7 +403,9 @@ static ExecStatusType _sqlstate(pTHX_ imp_dbh_t * imp_dbh, PGresult * result)
 			strncpy(imp_dbh->sqlstate, "01000", 6); /* WARNING */
 			break;
 		case PGRES_FATAL_ERROR:
-			if (!result) { /* libpq returned null - some sort of connection problem */
+			/* libpq returned an actual PGRES_FATAL_ERROR result or null indicating
+			   some sort of connection problem. */
+			if ((result && PGRES_FATAL_ERROR == PQresultStatus(result)) || !result ) {
 				strncpy(imp_dbh->sqlstate, "08000", 6); /* CONNECTION EXCEPTION */
 				break;
 			}
-- 
1.7.1