Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit76d38cb

Browse files
author
Hiroshi Inoue
committed
Changed the error handling as follows.
1) ERRORs cause an SQL_ERROR and the SQLSTATE='S1000'.2) NOTICEs cause an SQL_SUCCESS_WITH_INFO and the succeeding SQLError() returns the NOTICE message.
1 parent3709a5a commit76d38cb

File tree

4 files changed

+52
-27
lines changed

4 files changed

+52
-27
lines changed

‎src/interfaces/odbc/connection.c

Lines changed: 42 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
916916
intid;
917917
SocketClass*sock=self->sock;
918918
intmaxlen;
919+
BOOLmsg_truncated;
919920

920921
/* ERROR_MSG_LENGTH is suffcient */
921922
staticcharmsgbuffer[ERROR_MSG_LENGTH+1];
@@ -1004,6 +1005,8 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10041005
self->errormsg="No response from backend while receiving a portal query command";
10051006
mylog("send_query: 'C' - %s\n",self->errormsg);
10061007
CC_set_no_trans(self);
1008+
if (res)
1009+
QR_Destructor(res);
10071010
returnNULL;
10081011
}
10091012
else
@@ -1018,7 +1021,8 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10181021
mylog("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);
10221026
QR_set_command(res,cmdbuffer);
10231027

10241028
/*
@@ -1049,11 +1053,16 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10491053
qlog("Command response: '%s'\n",cmdbuffer);
10501054
break;
10511055
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 */
10531060
qlog("NOTICE from backend during clear: '%s'\n",cmdbuffer);
1061+
while (msg_truncated)
1062+
msg_truncated=SOCK_get_string(sock,cmdbuffer,ERROR_MSG_LENGTH);
10541063
break;
10551064
case'E':
1056-
SOCK_get_string(sock,cmdbuffer,ERROR_MSG_LENGTH);
1065+
msg_truncated=SOCK_get_string(sock,cmdbuffer,ERROR_MSG_LENGTH);
10571066
qlog("ERROR from backend during clear: '%s'\n",cmdbuffer);
10581067

10591068
/*
@@ -1071,8 +1080,10 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10711080
}
10721081
else
10731082
self->errornumber=CONNECTION_SERVER_REPORTED_WARNING;
1074-
QR_set_status(res,PGRES_NONFATAL_ERROR);
1083+
QR_set_status(res,PGRES_FATAL_ERROR);
10751084
QR_set_aborted(res, TRUE);
1085+
while (msg_truncated)
1086+
msg_truncated=SOCK_get_string(sock,cmdbuffer,ERROR_MSG_LENGTH);
10761087
break;
10771088
}
10781089
}
@@ -1088,14 +1099,17 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
10881099
case'Z':/* Backend is ready for new query (6.4) */
10891100
break;
10901101
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);
10951107
QR_set_notice(res,cmdbuffer);/* will dup this string */
10961108

10971109
mylog("~~~ NOTICE: '%s'\n",cmdbuffer);
10981110
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);
10991113

11001114
continue;/* dont return a result -- continue
11011115
* reading */
@@ -1107,20 +1121,22 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
11071121
{
11081122
self->errornumber=CONNECTION_BACKEND_CRAZY;
11091123
self->errormsg="Unexpected protocol character from backend (send_query - I)";
1110-
res=QR_Constructor();
1124+
if (!res)
1125+
res=QR_Constructor();
11111126
QR_set_status(res,PGRES_FATAL_ERROR);
11121127
returnres;
11131128
}
11141129
else
11151130
{
11161131
/* We return the empty query */
1117-
res=QR_Constructor();
1132+
if (!res)
1133+
res=QR_Constructor();
11181134
QR_set_status(res,PGRES_EMPTY_QUERY);
11191135
returnres;
11201136
}
11211137
break;
11221138
case'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 */
11261142
if (msgbuffer[0]!='\0'&&msgbuffer[strlen(msgbuffer)-1]=='\n')
@@ -1132,20 +1148,22 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
11321148
qlog("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

11371154
if (!strncmp(self->errormsg,"FATAL",5))
11381155
{
11391156
self->errornumber=CONNECTION_SERVER_REPORTED_ERROR;
11401157
CC_set_no_trans(self);
1141-
QR_set_status(res,PGRES_FATAL_ERROR);
11421158
}
11431159
else
11441160
{
11451161
self->errornumber=CONNECTION_SERVER_REPORTED_WARNING;
1146-
QR_set_status(res,PGRES_NONFATAL_ERROR);
11471162
}
1163+
QR_set_status(res,PGRES_FATAL_ERROR);
11481164
QR_set_aborted(res, TRUE);
1165+
while (msg_truncated)
1166+
msg_truncated=SOCK_get_string(sock,cmdbuffer,ERROR_MSG_LENGTH);
11491167

11501168
returnres;/* instead of NULL. Zoltan */
11511169

@@ -1188,19 +1206,25 @@ CC_send_query(ConnectionClass *self, char *query, QueryInfo *qi)
11881206

11891207
returnresult_in;
11901208
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);
11931213
returnres;
11941214
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);
11971219
returnres;
11981220
default:
11991221
self->errornumber=CONNECTION_BACKEND_CRAZY;
12001222
self->errormsg="Unexpected protocol character from backend (send_query)";
12011223
CC_set_no_trans(self);
12021224

12031225
mylog("send_query: error - %s\n",self->errormsg);
1226+
if (res)
1227+
QR_Destructor(res);
12041228
returnNULL;
12051229
}
12061230
}

‎src/interfaces/odbc/socket.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,19 @@ SOCK_put_n_char(SocketClass *self, char *buffer, int len)
195195
/*
196196
*bufsize must include room for the null terminator
197197
*will read at most bufsize-1 characters + null.
198+
*returns TRUE if truncation occurs.
198199
*/
199-
void
200+
BOOL
200201
SOCK_get_string(SocketClass*self,char*buffer,intbufsize)
201202
{
202203
registerintlf=0;
203204

204205
for (lf=0;lf<bufsize;lf++)
205206
if (!(buffer[lf]=SOCK_get_next_byte(self)))
206-
return;
207+
return FALSE;
207208

208209
buffer[bufsize-1]='\0';
210+
return TRUE;
209211
}
210212

211213

‎src/interfaces/odbc/socket.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ voidSOCK_Destructor(SocketClass *self);
8686
charSOCK_connect_to(SocketClass*self,unsigned shortport,char*hostname);
8787
voidSOCK_get_n_char(SocketClass*self,char*buffer,intlen);
8888
voidSOCK_put_n_char(SocketClass*self,char*buffer,intlen);
89-
voidSOCK_get_string(SocketClass*self,char*buffer,intbufsize);
89+
BOOLSOCK_get_string(SocketClass*self,char*buffer,intbufsize);
9090
voidSOCK_put_string(SocketClass*self,char*string);
9191
intSOCK_get_int(SocketClass*self,shortlen);
9292
voidSOCK_put_int(SocketClass*self,intvalue,shortlen);

‎src/interfaces/odbc/statement.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,8 @@ SC_create_errormsg(StatementClass *self)
652652
sprintf(&msg[pos],";\n%s",sock->errormsg);
653653
}
654654
}
655+
if (!msg[0]&&res&&QR_get_notice(res))
656+
returnQR_get_notice(res);
655657

656658
returnmsg;
657659
}
@@ -1044,14 +1046,11 @@ SC_execute(StatementClass *self)
10441046

10451047
if (self->errornumber==STMT_OK)
10461048
returnSQL_SUCCESS;
1047-
1049+
elseif (self->errornumber==STMT_INFO_ONLY)
1050+
returnSQL_SUCCESS_WITH_INFO;
10481051
else
10491052
{
1050-
/* Modified, 2000-04-29, Zoltan */
1051-
if (self->errornumber==STMT_INFO_ONLY)
1052-
self->errormsg="Error while executing the query (non-fatal)";
1053-
else
1054-
self->errormsg="Unknown error";
1053+
self->errormsg="Error while executing the query";
10551054
SC_log_error(func,"",self);
10561055
returnSQL_ERROR;
10571056
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp