diff -Nacr a/connection.c b/connection.c *** a/connection.c 2016-07-30 21:58:16.000000000 +0900 --- b/connection.c 2016-10-19 16:42:52.000000000 +0900 *************** *** 852,858 **** if (PQstatus(self->pqconn) == CONNECTION_BAD) { ! CC_set_errornumber(self, CONNECTION_SERVER_REPORTED_ERROR); abort_opt = CONN_DEAD; } else --- 852,858 ---- if (PQstatus(self->pqconn) == CONNECTION_BAD) { ! CC_set_errornumber(self, CONNECTION_COMMUNICATION_ERROR); abort_opt = CONN_DEAD; } else diff -Nacr a/statement.c b/statement.c *** a/statement.c 2016-07-30 21:58:16.000000000 +0900 --- b/statement.c 2016-10-19 16:43:00.000000000 +0900 *************** *** 170,175 **** --- 170,177 ---- }; static QResultClass *libpq_bind_and_exec(StatementClass *stmt); + static void SC_set_errorinfo(StatementClass *self, QResultClass *res); + RETCODE SQL_API PGAPI_AllocStmt(HDBC hdbc, *************** *** 1617,1645 **** (self->currTuple)++; /* all is well */ else { ! ConnectionClass *conn = SC_get_conn(self); ! ! mylog("%s: error\n", func); ! switch (conn->status) ! { ! case CONN_NOT_CONNECTED: ! case CONN_DOWN: ! SC_set_error(self, STMT_BAD_ERROR, "Error fetching next row", func); ! break; ! default: ! switch (QR_get_rstatus(res)) ! { ! case PORES_NO_MEMORY_ERROR: ! SC_set_error(self, STMT_NO_MEMORY_ERROR, "memory allocation error???", __FUNCTION__); ! break; ! case PORES_BAD_RESPONSE: ! SC_set_error(self, STMT_COMMUNICATION_ERROR, "communication error occured", __FUNCTION__); ! break; ! default: ! SC_set_error(self, STMT_EXEC_ERROR, "Error fetching next row", __FUNCTION__); ! break; ! } ! } return SQL_ERROR; } } --- 1619,1625 ---- (self->currTuple)++; /* all is well */ else { ! SC_set_errorinfo(self, res); return SQL_ERROR; } } *************** *** 2044,2065 **** else if (was_nonfatal) SC_set_errornumber(self, STMT_INFO_ONLY); else ! { ! switch (QR_get_rstatus(res)) ! { ! case PORES_NO_MEMORY_ERROR: ! SC_set_errornumber(self, STMT_NO_MEMORY_ERROR); ! break; ! case PORES_BAD_RESPONSE: ! SC_set_errornumber(self, STMT_COMMUNICATION_ERROR); ! break; ! case PORES_INTERNAL_ERROR: ! SC_set_errornumber(self, STMT_INTERNAL_ERROR); ! break; ! default: ! SC_set_errornumber(self, STMT_ERROR_TAKEN_FROM_BACKEND); ! } ! } /* set cursor before the first tuple in the list */ self->currTuple = -1; SC_set_current_col(self, -1); --- 2024,2030 ---- else if (was_nonfatal) SC_set_errornumber(self, STMT_INFO_ONLY); else ! SC_set_errorinfo(self, res); /* set cursor before the first tuple in the list */ self->currTuple = -1; SC_set_current_col(self, -1); *************** *** 2969,2971 **** --- 2934,2965 ---- LEAVE_COMMON_CS; return shouldCancel; } + + static void + SC_set_errorinfo(StatementClass *self, QResultClass *res) + { + ConnectionClass *conn = SC_get_conn(self); + + if (conn->status == CONN_NOT_CONNECTED || conn->status == CONN_DOWN) + { + SC_set_error(self, STMT_COMMUNICATION_ERROR, "The connection has been lost", __FUNCTION__); + return; + } + + switch (QR_get_rstatus(res)) + { + case PORES_NO_MEMORY_ERROR: + SC_set_error(self, STMT_NO_MEMORY_ERROR, "memory allocation error???", __FUNCTION__); + break; + case PORES_BAD_RESPONSE: + SC_set_error(self, STMT_COMMUNICATION_ERROR, "communication error occured", __FUNCTION__); + break; + case PORES_INTERNAL_ERROR: + SC_set_error(self, STMT_INTERNAL_ERROR, "Internal error fetching next row", __FUNCTION__); + break; + default: + SC_set_error(self, STMT_EXEC_ERROR, "Error fetching next row", __FUNCTION__); + break; + } + } +