]> granicus.if.org Git - postgresql/commitdiff
Backport fix from HEAD that makes ecpglib give the right SQLSTATE if the connection...
authorMichael Meskes <meskes@postgresql.org>
Mon, 8 Mar 2010 13:15:51 +0000 (13:15 +0000)
committerMichael Meskes <meskes@postgresql.org>
Mon, 8 Mar 2010 13:15:51 +0000 (13:15 +0000)
src/interfaces/ecpg/ecpglib/error.c

index cce370aca65d8ed95ba8bedc8cb9e67c1426fadc..fba7bc1c72934dc41050399ba0ef295b649f3212 100644 (file)
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.19 2007/11/15 21:14:45 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.19.2.1 2010/03/08 13:15:51 meskes Exp $ */
 
 #define POSTGRES_ECPG_INTERNAL
 #include "postgres_fe.h"
@@ -172,6 +172,17 @@ ecpg_raise_backend(int line, PGresult *result, PGconn *conn, int compat)
                message = PQerrorMessage(conn);
        }
 
+       if (strcmp(sqlstate, ECPG_SQLSTATE_ECPG_INTERNAL_ERROR) == 0)
+       {
+               /* we might get here if the connection breaks down, so let's
+                * check for this instead of giving just the generic internal error */
+               if (PQstatus(conn) == CONNECTION_BAD)
+               {
+                       sqlstate = "57P02";
+                       message = "the connection to the server was lost";
+               }
+       }
+
        /* copy error message */
        snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc),
                         "'%s' in line %d.", message, line);