@@ -916,6 +916,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
916916int id ;
917917SocketClass * sock = self -> sock ;
918918int maxlen ;
919+ BOOL msg_truncated ;
919920
920921/* ERROR_MSG_LENGTH is suffcient */
921922static char msgbuffer [ERROR_MSG_LENGTH + 1 ];
@@ -1004,6 +1005,8 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10041005self -> errormsg = "No response from backend while receiving a portal query command" ;
10051006mylog ("send_query: 'C' - %s\n" ,self -> errormsg );
10061007CC_set_no_trans (self );
1008+ if (res )
1009+ QR_Destructor (res );
10071010return NULL ;
10081011}
10091012else
@@ -1018,7 +1021,8 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10181021mylog ("send_query: setting cmdbuffer = '%s'\n" ,cmdbuffer );
10191022
10201023/* Only save the first command */
1021- QR_set_status (res ,PGRES_COMMAND_OK );
1024+ if (QR_command_successful (res ))
1025+ QR_set_status (res ,PGRES_COMMAND_OK );
10221026QR_set_command (res ,cmdbuffer );
10231027
10241028/*
@@ -1049,11 +1053,16 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10491053qlog ("Command response: '%s'\n" ,cmdbuffer );
10501054break ;
10511055case 'N' :
1052- SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
1056+ msg_truncated = SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
1057+ if (QR_command_successful (res ))
1058+ QR_set_status (res ,PGRES_NONFATAL_ERROR );
1059+ QR_set_notice (res ,cmdbuffer );/* will dup this string */
10531060qlog ("NOTICE from backend during clear: '%s'\n" ,cmdbuffer );
1061+ while (msg_truncated )
1062+ msg_truncated = SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
10541063break ;
10551064case 'E' :
1056- SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
1065+ msg_truncated = SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
10571066qlog ("ERROR from backend during clear: '%s'\n" ,cmdbuffer );
10581067
10591068/*
@@ -1071,8 +1080,10 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10711080}
10721081else
10731082self -> errornumber = CONNECTION_SERVER_REPORTED_WARNING ;
1074- QR_set_status (res ,PGRES_NONFATAL_ERROR );
1083+ QR_set_status (res ,PGRES_FATAL_ERROR );
10751084QR_set_aborted (res , TRUE);
1085+ while (msg_truncated )
1086+ msg_truncated = SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
10761087break ;
10771088}
10781089}
@@ -1088,14 +1099,17 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10881099case 'Z' :/* Backend is ready for new query (6.4) */
10891100break ;
10901101case 'N' :/* NOTICE: */
1091- SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
1092-
1093- res = QR_Constructor ();
1094- QR_set_status (res ,PGRES_NONFATAL_ERROR );
1102+ msg_truncated = SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
1103+ if (!res )
1104+ res = QR_Constructor ();
1105+ if (QR_command_successful (res ))
1106+ QR_set_status (res ,PGRES_NONFATAL_ERROR );
10951107QR_set_notice (res ,cmdbuffer );/* will dup this string */
10961108
10971109mylog ("~~~ NOTICE: '%s'\n" ,cmdbuffer );
10981110qlog ("NOTICE from backend during send_query: '%s'\n" ,cmdbuffer );
1111+ while (msg_truncated )
1112+ msg_truncated = SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
10991113
11001114continue ;/* dont return a result -- continue
11011115 * reading */
@@ -1107,20 +1121,22 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
11071121{
11081122self -> errornumber = CONNECTION_BACKEND_CRAZY ;
11091123self -> errormsg = "Unexpected protocol character from backend (send_query - I)" ;
1110- res = QR_Constructor ();
1124+ if (!res )
1125+ res = QR_Constructor ();
11111126QR_set_status (res ,PGRES_FATAL_ERROR );
11121127return res ;
11131128}
11141129else
11151130{
11161131/* We return the empty query */
1117- res = QR_Constructor ();
1132+ if (!res )
1133+ res = QR_Constructor ();
11181134QR_set_status (res ,PGRES_EMPTY_QUERY );
11191135return res ;
11201136}
11211137break ;
11221138case 'E' :
1123- SOCK_get_string (sock ,msgbuffer ,ERROR_MSG_LENGTH );
1139+ msg_truncated = SOCK_get_string (sock ,msgbuffer ,ERROR_MSG_LENGTH );
11241140
11251141/* Remove a newline */
11261142if (msgbuffer [0 ]!= '\0' && msgbuffer [strlen (msgbuffer )- 1 ]== '\n' )
@@ -1132,20 +1148,22 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
11321148qlog ("ERROR from backend during send_query: '%s'\n" ,self -> errormsg );
11331149
11341150/* We should report that an error occured. Zoltan */
1135- res = QR_Constructor ();
1151+ if (!res )
1152+ res = QR_Constructor ();
11361153
11371154if (!strncmp (self -> errormsg ,"FATAL" ,5 ))
11381155{
11391156self -> errornumber = CONNECTION_SERVER_REPORTED_ERROR ;
11401157CC_set_no_trans (self );
1141- QR_set_status (res ,PGRES_FATAL_ERROR );
11421158}
11431159else
11441160{
11451161self -> errornumber = CONNECTION_SERVER_REPORTED_WARNING ;
1146- QR_set_status (res ,PGRES_NONFATAL_ERROR );
11471162}
1163+ QR_set_status (res ,PGRES_FATAL_ERROR );
11481164QR_set_aborted (res , TRUE);
1165+ while (msg_truncated )
1166+ msg_truncated = SOCK_get_string (sock ,cmdbuffer ,ERROR_MSG_LENGTH );
11491167
11501168return res ;/* instead of NULL. Zoltan */
11511169
@@ -1188,19 +1206,25 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
11881206
11891207return result_in ;
11901208case 'D' :/* Copy in command began successfully */
1191- res = QR_Constructor ();
1192- QR_set_status (res ,PGRES_COPY_IN );
1209+ if (!res )
1210+ res = QR_Constructor ();
1211+ if (QR_command_successful (res ))
1212+ QR_set_status (res ,PGRES_COPY_IN );
11931213return res ;
11941214case 'B' :/* Copy out command began successfully */
1195- res = QR_Constructor ();
1196- QR_set_status (res ,PGRES_COPY_OUT );
1215+ if (!res )
1216+ res = QR_Constructor ();
1217+ if (QR_command_successful (res ))
1218+ QR_set_status (res ,PGRES_COPY_OUT );
11971219return res ;
11981220default :
11991221self -> errornumber = CONNECTION_BACKEND_CRAZY ;
12001222self -> errormsg = "Unexpected protocol character from backend (send_query)" ;
12011223CC_set_no_trans (self );
12021224
12031225mylog ("send_query: error - %s\n" ,self -> errormsg );
1226+ if (res )
1227+ QR_Destructor (res );
12041228return NULL ;
12051229}
12061230}