diff -Nacr a/connection.c b/connection.c
*** a/connection.c	Mon Oct 17 19:01:56 2016
--- b/connection.c	Mon Oct 24 12:01:55 2016
***************
*** 776,783 ****
  	/*
  	 *	If the error is continuable after rollback?
  	 */
! 	if (PQstatus(self->pqconn) == CONNECTION_BAD ||
! 	    (errseverity && strcmp(errseverity, "FATAL") == 0)) /* no */
  	{
  		CC_set_errornumber(self, CONNECTION_SERVER_REPORTED_SEVERITY_FATAL);
  		CC_on_abort(self, CONN_DEAD); /* give up the connection */
--- 776,787 ----
  	/*
  	 *	If the error is continuable after rollback?
  	 */
! 	if (PQstatus(self->pqconn) == CONNECTION_BAD)
! 	{
! 		CC_set_errornumber(self, CONNECTION_COMMUNICATION_ERROR);
! 		CC_on_abort(self, CONN_DEAD); /* give up the connection */
! 	}
! 	else if (errseverity && strcmp(errseverity, "FATAL") == 0) /* no */
  	{
  		CC_set_errornumber(self, CONNECTION_SERVER_REPORTED_SEVERITY_FATAL);
  		CC_on_abort(self, CONN_DEAD); /* give up the connection */
***************
*** 1586,1592 ****
  	if (!PQsendQuery(self->pqconn, query_buf))
  	{
  		char *errmsg = PQerrorMessage(self->pqconn);
! 		CC_set_error(self, CONNECTION_SERVER_NOT_REACHED, errmsg, func);
  		goto cleanup;
  	}
  	PQsetSingleRowMode(self->pqconn);
--- 1590,1596 ----
  	if (!PQsendQuery(self->pqconn, query_buf))
  	{
  		char *errmsg = PQerrorMessage(self->pqconn);
! 		CC_set_error(self, CONNECTION_COMMUNICATION_ERROR, errmsg, func);
  		goto cleanup;
  	}
  	PQsetSingleRowMode(self->pqconn);
diff -Nacr a/statement.c b/statement.c
*** a/statement.c	Mon Oct 17 19:01:56 2016
--- b/statement.c	Mon Oct 24 12:00:50 2016
***************
*** 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;
+ 	}
+ }
+ 
