@@ -916,6 +916,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
916
916
int id ;
917
917
SocketClass * sock = self -> sock ;
918
918
int maxlen ;
919
+ BOOL msg_truncated ;
919
920
920
921
/* ERROR_MSG_LENGTH is suffcient */
921
922
static char msgbuffer [ERROR_MSG_LENGTH + 1 ];
@@ -1004,6 +1005,8 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
1004
1005
self -> errormsg = "No response from backend while receiving a portal query command" ;
1005
1006
mylog ("send_query: 'C' - %s\n" , self -> errormsg );
1006
1007
CC_set_no_trans (self );
1008
+ if (res )
1009
+ QR_Destructor (res );
1007
1010
return NULL ;
1008
1011
}
1009
1012
else
@@ -1018,7 +1021,8 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
1018
1021
mylog ("send_query: setting cmdbuffer = '%s'\n" , cmdbuffer );
1019
1022
1020
1023
/* 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 );
1022
1026
QR_set_command (res , cmdbuffer );
1023
1027
1024
1028
/*
@@ -1049,11 +1053,16 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
1049
1053
qlog ("Command response: '%s'\n" , cmdbuffer );
1050
1054
break ;
1051
1055
case '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 */
1053
1060
qlog ("NOTICE from backend during clear: '%s'\n" , cmdbuffer );
1061
+ while (msg_truncated )
1062
+ msg_truncated = SOCK_get_string (sock , cmdbuffer , ERROR_MSG_LENGTH );
1054
1063
break ;
1055
1064
case 'E' :
1056
- SOCK_get_string (sock , cmdbuffer , ERROR_MSG_LENGTH );
1065
+ msg_truncated = SOCK_get_string (sock , cmdbuffer , ERROR_MSG_LENGTH );
1057
1066
qlog ("ERROR from backend during clear: '%s'\n" , cmdbuffer );
1058
1067
1059
1068
/*
@@ -1071,8 +1080,10 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
1071
1080
}
1072
1081
else
1073
1082
self -> errornumber = CONNECTION_SERVER_REPORTED_WARNING ;
1074
- QR_set_status (res , PGRES_NONFATAL_ERROR );
1083
+ QR_set_status (res , PGRES_FATAL_ERROR );
1075
1084
QR_set_aborted (res , TRUE);
1085
+ while (msg_truncated )
1086
+ msg_truncated = SOCK_get_string (sock , cmdbuffer , ERROR_MSG_LENGTH );
1076
1087
break ;
1077
1088
}
1078
1089
}
@@ -1088,14 +1099,17 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
1088
1099
case 'Z' : /* Backend is ready for new query (6.4) */
1089
1100
break ;
1090
1101
case '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 );
1095
1107
QR_set_notice (res , cmdbuffer ); /* will dup this string */
1096
1108
1097
1109
mylog ("~~~ NOTICE: '%s'\n" , cmdbuffer );
1098
1110
qlog ("NOTICE from backend during send_query: '%s'\n" , cmdbuffer );
1111
+ while (msg_truncated )
1112
+ msg_truncated = SOCK_get_string (sock , cmdbuffer , ERROR_MSG_LENGTH );
1099
1113
1100
1114
continue ; /* dont return a result -- continue
1101
1115
* reading */
@@ -1107,20 +1121,22 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
1107
1121
{
1108
1122
self -> errornumber = CONNECTION_BACKEND_CRAZY ;
1109
1123
self -> errormsg = "Unexpected protocol character from backend (send_query - I)" ;
1110
- res = QR_Constructor ();
1124
+ if (!res )
1125
+ res = QR_Constructor ();
1111
1126
QR_set_status (res , PGRES_FATAL_ERROR );
1112
1127
return res ;
1113
1128
}
1114
1129
else
1115
1130
{
1116
1131
/* We return the empty query */
1117
- res = QR_Constructor ();
1132
+ if (!res )
1133
+ res = QR_Constructor ();
1118
1134
QR_set_status (res , PGRES_EMPTY_QUERY );
1119
1135
return res ;
1120
1136
}
1121
1137
break ;
1122
1138
case 'E' :
1123
- SOCK_get_string (sock , msgbuffer , ERROR_MSG_LENGTH );
1139
+ msg_truncated = SOCK_get_string (sock , msgbuffer , ERROR_MSG_LENGTH );
1124
1140
1125
1141
/* Remove a newline */
1126
1142
if (msgbuffer [0 ] != '\0' && msgbuffer [strlen (msgbuffer ) - 1 ] == '\n' )
@@ -1132,20 +1148,22 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
1132
1148
qlog ("ERROR from backend during send_query: '%s'\n" , self -> errormsg );
1133
1149
1134
1150
/* We should report that an error occured. Zoltan */
1135
- res = QR_Constructor ();
1151
+ if (!res )
1152
+ res = QR_Constructor ();
1136
1153
1137
1154
if (!strncmp (self -> errormsg , "FATAL" , 5 ))
1138
1155
{
1139
1156
self -> errornumber = CONNECTION_SERVER_REPORTED_ERROR ;
1140
1157
CC_set_no_trans (self );
1141
- QR_set_status (res , PGRES_FATAL_ERROR );
1142
1158
}
1143
1159
else
1144
1160
{
1145
1161
self -> errornumber = CONNECTION_SERVER_REPORTED_WARNING ;
1146
- QR_set_status (res , PGRES_NONFATAL_ERROR );
1147
1162
}
1163
+ QR_set_status (res , PGRES_FATAL_ERROR );
1148
1164
QR_set_aborted (res , TRUE);
1165
+ while (msg_truncated )
1166
+ msg_truncated = SOCK_get_string (sock , cmdbuffer , ERROR_MSG_LENGTH );
1149
1167
1150
1168
return res ; /* instead of NULL. Zoltan */
1151
1169
@@ -1188,19 +1206,25 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
1188
1206
1189
1207
return result_in ;
1190
1208
case '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 );
1193
1213
return res ;
1194
1214
case '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 );
1197
1219
return res ;
1198
1220
default :
1199
1221
self -> errornumber = CONNECTION_BACKEND_CRAZY ;
1200
1222
self -> errormsg = "Unexpected protocol character from backend (send_query)" ;
1201
1223
CC_set_no_trans (self );
1202
1224
1203
1225
mylog ("send_query: error - %s\n" , self -> errormsg );
1226
+ if (res )
1227
+ QR_Destructor (res );
1204
1228
return NULL ;
1205
1229
}
1206
1230
}
0 commit comments