error sqlstate. This change makes it return a correct value..
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.23 2009/06/11 14:49:13 momjian Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/ecpglib/error.c,v 1.24 2010/03/05 13:57:08 meskes Exp $ */
#define POSTGRES_ECPG_INTERNAL
#include "postgres_fe.h"
message = PQerrorMessage(conn);
}
+ if (sqlstate == ECPG_SQLSTATE_ECPG_INTERNAL_ERROR)
+ {
+ /* 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 = ecpg_gettext("the connection to the server was lost");
+ }
+ }
+
/* copy error message */
snprintf(sqlca->sqlerrm.sqlerrmc, sizeof(sqlca->sqlerrm.sqlerrmc), "%s on line %d", message, line);
sqlca->sqlerrm.sqlerrml = strlen(sqlca->sqlerrm.sqlerrmc);
else
sqlca->sqlcode = ECPG_PGSQL;
- ecpg_log("raising sqlstate %.*s (sqlcode %d) on line %d: %s\n",
- sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, line, sqlca->sqlerrm.sqlerrmc);
+ ecpg_log("raising sqlstate %.*s (sqlcode %d): %s\n",
+ sizeof(sqlca->sqlstate), sqlca->sqlstate, sqlca->sqlcode, sqlca->sqlerrm.sqlerrmc);
/* free all memory we have allocated for the user */
ECPGfree_auto_mem();
{
if (results == NULL)
{
- ecpg_log("ecpg_check_PQresult on line %d: %s", lineno, PQerrorMessage(connection));
+ ecpg_log("ecpg_check_PQresult on line %d: no result - %s", lineno, PQerrorMessage(connection));
ecpg_raise_backend(lineno, NULL, connection, compat);
return (false);
}
case PGRES_NONFATAL_ERROR:
case PGRES_FATAL_ERROR:
case PGRES_BAD_RESPONSE:
- ecpg_log("ecpg_check_PQresult on line %d: %s", lineno, PQresultErrorMessage(results));
+ ecpg_log("ecpg_check_PQresult on line %d: bad response - %s", lineno, PQresultErrorMessage(results));
ecpg_raise_backend(lineno, results, connection, compat);
PQclear(results);
return (false);
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 32: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_check_PQresult on line 32: ERROR: duplicate key value violates unique constraint "test_pkey"
+[NO_PID]: ecpg_check_PQresult on line 32: bad response - ERROR: duplicate key value violates unique constraint "test_pkey"
DETAIL: Key (i)=(7) already exists.
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlstate 23505 (sqlcode -239) on line 32: duplicate key value violates unique constraint "test_pkey" on line 32
+[NO_PID]: raising sqlstate 23505 (sqlcode -239): duplicate key value violates unique constraint "test_pkey" on line 32
[NO_PID]: sqlca: code: -239, state: 23505
[NO_PID]: ECPGtrans on line 34: action "rollback"; connection "regress1"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 40: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_check_PQresult on line 40: ERROR: more than one row returned by a subquery used as an expression
+[NO_PID]: ecpg_check_PQresult on line 40: bad response - ERROR: more than one row returned by a subquery used as an expression
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlstate 21000 (sqlcode -284) on line 40: more than one row returned by a subquery used as an expression on line 40
+[NO_PID]: raising sqlstate 21000 (sqlcode -284): more than one row returned by a subquery used as an expression on line 40
[NO_PID]: sqlca: code: -284, state: 21000
[NO_PID]: ECPGtrans on line 41: action "rollback"; connection "regress1"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 39: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_check_PQresult on line 39: ERROR: relation "nonexistant" does not exist
+[NO_PID]: ecpg_check_PQresult on line 39: bad response - ERROR: relation "nonexistant" does not exist
LINE 1: select * from nonexistant
^
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlstate 42P01 (sqlcode -400) on line 39: relation "nonexistant" does not exist on line 39
+[NO_PID]: raising sqlstate 42P01 (sqlcode -400): relation "nonexistant" does not exist on line 39
[NO_PID]: sqlca: code: -400, state: 42P01
SQL error: relation "nonexistant" does not exist on line 39
[NO_PID]: ECPGtrans on line 40: action "rollback"; connection "regress1"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 43: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_check_PQresult on line 43: ERROR: relation "nonexistant" does not exist
+[NO_PID]: ecpg_check_PQresult on line 43: bad response - ERROR: relation "nonexistant" does not exist
LINE 1: select * from nonexistant
^
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlstate 42P01 (sqlcode -400) on line 43: relation "nonexistant" does not exist on line 43
+[NO_PID]: raising sqlstate 42P01 (sqlcode -400): relation "nonexistant" does not exist on line 43
[NO_PID]: sqlca: code: -400, state: 42P01
Error in statement 'select':
SQL error: relation "nonexistant" does not exist on line 43
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 47: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_check_PQresult on line 47: ERROR: relation "nonexistant" does not exist
+[NO_PID]: ecpg_check_PQresult on line 47: bad response - ERROR: relation "nonexistant" does not exist
LINE 1: select * from nonexistant
^
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlstate 42P01 (sqlcode -400) on line 47: relation "nonexistant" does not exist on line 47
+[NO_PID]: raising sqlstate 42P01 (sqlcode -400): relation "nonexistant" does not exist on line 47
[NO_PID]: sqlca: code: -400, state: 42P01
Found another error
SQL error: relation "nonexistant" does not exist on line 47
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 51: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_check_PQresult on line 51: ERROR: relation "nonexistant" does not exist
+[NO_PID]: ecpg_check_PQresult on line 51: bad response - ERROR: relation "nonexistant" does not exist
LINE 1: select * from nonexistant
^
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlstate 42P01 (sqlcode -400) on line 51: relation "nonexistant" does not exist on line 51
+[NO_PID]: raising sqlstate 42P01 (sqlcode -400): relation "nonexistant" does not exist on line 51
[NO_PID]: sqlca: code: -400, state: 42P01
[NO_PID]: ECPGtrans on line 52: action "rollback"; connection "regress1"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 55: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_check_PQresult on line 55: ERROR: relation "nonexistant" does not exist
+[NO_PID]: ecpg_check_PQresult on line 55: bad response - ERROR: relation "nonexistant" does not exist
LINE 1: select * from nonexistant
^
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlstate 42P01 (sqlcode -400) on line 55: relation "nonexistant" does not exist on line 55
+[NO_PID]: raising sqlstate 42P01 (sqlcode -400): relation "nonexistant" does not exist on line 55
[NO_PID]: sqlca: code: -400, state: 42P01
[NO_PID]: ECPGtrans on line 59: action "rollback"; connection "regress1"
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: sqlca: code: 0, state: 00000
[NO_PID]: ecpg_execute on line 53: using PQexec
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: ecpg_check_PQresult on line 53: ERROR: cannot drop "my_table" because it is being used by active queries in this session
+[NO_PID]: ecpg_check_PQresult on line 53: bad response - ERROR: cannot drop "my_table" because it is being used by active queries in this session
[NO_PID]: sqlca: code: 0, state: 00000
-[NO_PID]: raising sqlstate 55006 (sqlcode -400) on line 53: cannot drop "my_table" because it is being used by active queries in this session on line 53
+[NO_PID]: raising sqlstate 55006 (sqlcode -400): cannot drop "my_table" because it is being used by active queries in this session on line 53
[NO_PID]: sqlca: code: -400, state: 55006
SQL error: cannot drop "my_table" because it is being used by active queries in this session on line 53
[NO_PID]: ecpg_finish: connection regress1 closed