int id;
SocketClass *sock = self->sock;
int maxlen;
+ BOOL msg_truncated;
/* ERROR_MSG_LENGTH is suffcient */
static char msgbuffer[ERROR_MSG_LENGTH + 1];
self->errormsg = "No response from backend while receiving a portal query command";
mylog("send_query: 'C' - %s\n", self->errormsg);
CC_set_no_trans(self);
+ if (res)
+ QR_Destructor(res);
return NULL;
}
else
mylog("send_query: setting cmdbuffer = '%s'\n", cmdbuffer);
/* Only save the first command */
- QR_set_status(res, PGRES_COMMAND_OK);
+ if (QR_command_successful(res))
+ QR_set_status(res, PGRES_COMMAND_OK);
QR_set_command(res, cmdbuffer);
/*
qlog("Command response: '%s'\n", cmdbuffer);
break;
case 'N':
- SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
+ msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
+ if (QR_command_successful(res))
+ QR_set_status(res, PGRES_NONFATAL_ERROR);
+ QR_set_notice(res, cmdbuffer); /* will dup this string */
qlog("NOTICE from backend during clear: '%s'\n", cmdbuffer);
+ while (msg_truncated)
+ msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
break;
case 'E':
- SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
+ msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
qlog("ERROR from backend during clear: '%s'\n", cmdbuffer);
/*
}
else
self->errornumber = CONNECTION_SERVER_REPORTED_WARNING;
- QR_set_status(res, PGRES_NONFATAL_ERROR);
+ QR_set_status(res, PGRES_FATAL_ERROR);
QR_set_aborted(res, TRUE);
+ while (msg_truncated)
+ msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
break;
}
}
case 'Z': /* Backend is ready for new query (6.4) */
break;
case 'N': /* NOTICE: */
- SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
-
- res = QR_Constructor();
- QR_set_status(res, PGRES_NONFATAL_ERROR);
+ msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
+ if (!res)
+ res = QR_Constructor();
+ if (QR_command_successful(res))
+ QR_set_status(res, PGRES_NONFATAL_ERROR);
QR_set_notice(res, cmdbuffer); /* will dup this string */
mylog("~~~ NOTICE: '%s'\n", cmdbuffer);
qlog("NOTICE from backend during send_query: '%s'\n", cmdbuffer);
+ while (msg_truncated)
+ msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
continue; /* dont return a result -- continue
* reading */
{
self->errornumber = CONNECTION_BACKEND_CRAZY;
self->errormsg = "Unexpected protocol character from backend (send_query - I)";
- res = QR_Constructor();
+ if (!res)
+ res = QR_Constructor();
QR_set_status(res, PGRES_FATAL_ERROR);
return res;
}
else
{
/* We return the empty query */
- res = QR_Constructor();
+ if (!res)
+ res = QR_Constructor();
QR_set_status(res, PGRES_EMPTY_QUERY);
return res;
}
break;
case 'E':
- SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
+ msg_truncated = SOCK_get_string(sock, msgbuffer, ERROR_MSG_LENGTH);
/* Remove a newline */
if (msgbuffer[0] != '\0' && msgbuffer[strlen(msgbuffer) - 1] == '\n')
qlog("ERROR from backend during send_query: '%s'\n", self->errormsg);
/* We should report that an error occured. Zoltan */
- res = QR_Constructor();
+ if (!res)
+ res = QR_Constructor();
if (!strncmp(self->errormsg, "FATAL", 5))
{
self->errornumber = CONNECTION_SERVER_REPORTED_ERROR;
CC_set_no_trans(self);
- QR_set_status(res, PGRES_FATAL_ERROR);
}
else
{
self->errornumber = CONNECTION_SERVER_REPORTED_WARNING;
- QR_set_status(res, PGRES_NONFATAL_ERROR);
}
+ QR_set_status(res, PGRES_FATAL_ERROR);
QR_set_aborted(res, TRUE);
+ while (msg_truncated)
+ msg_truncated = SOCK_get_string(sock, cmdbuffer, ERROR_MSG_LENGTH);
return res; /* instead of NULL. Zoltan */
return result_in;
case 'D': /* Copy in command began successfully */
- res = QR_Constructor();
- QR_set_status(res, PGRES_COPY_IN);
+ if (!res)
+ res = QR_Constructor();
+ if (QR_command_successful(res))
+ QR_set_status(res, PGRES_COPY_IN);
return res;
case 'B': /* Copy out command began successfully */
- res = QR_Constructor();
- QR_set_status(res, PGRES_COPY_OUT);
+ if (!res)
+ res = QR_Constructor();
+ if (QR_command_successful(res))
+ QR_set_status(res, PGRES_COPY_OUT);
return res;
default:
self->errornumber = CONNECTION_BACKEND_CRAZY;
CC_set_no_trans(self);
mylog("send_query: error - %s\n", self->errormsg);
+ if (res)
+ QR_Destructor(res);
return NULL;
}
}