@@ -91,12 +91,16 @@ SQLError(
91
91
char * msg ;
92
92
int status ;
93
93
94
- mylog ("**** SQLError: henv=%u, hdbc=%u, hstmt=%u\n" , henv , hdbc , hstmt );
94
+ mylog ("**** SQLError: henv=%u, hdbc=%u, hstmt=%u <%d> \n" , henv , hdbc , hstmt , cbErrorMsgMax );
95
95
96
+ if (cbErrorMsgMax < 0 )
97
+ return SQL_ERROR ;
96
98
if (SQL_NULL_HSTMT != hstmt )
97
99
{
98
100
/* CC: return an error of a hstmt */
99
101
StatementClass * stmt = (StatementClass * ) hstmt ;
102
+ SWORD msglen ;
103
+ BOOL once_again = FALSE;
100
104
101
105
if (SC_get_error (stmt , & status , & msg ))
102
106
{
@@ -112,8 +116,18 @@ SQLError(
112
116
113
117
return SQL_NO_DATA_FOUND ;
114
118
}
119
+ msglen = (SWORD ) strlen (msg );
115
120
if (NULL != pcbErrorMsg )
116
- * pcbErrorMsg = (SWORD ) strlen (msg );
121
+ {
122
+ * pcbErrorMsg = msglen ;
123
+ if (cbErrorMsgMax == 0 )
124
+ once_again = TRUE;
125
+ else if (msglen >= cbErrorMsgMax )
126
+ {
127
+ once_again = TRUE;
128
+ * pcbErrorMsg = cbErrorMsgMax - 1 ;
129
+ }
130
+ }
117
131
118
132
if ((NULL != szErrorMsg ) && (cbErrorMsgMax > 0 ))
119
133
strncpy_null (szErrorMsg , msg , cbErrorMsgMax );
@@ -238,7 +252,27 @@ SQLError(
238
252
return SQL_NO_DATA_FOUND ;
239
253
}
240
254
241
- return SQL_SUCCESS ;
255
+ if (once_again )
256
+ {
257
+ int outlen ;
258
+ stmt -> errornumber = status ;
259
+ if (cbErrorMsgMax > 0 )
260
+ outlen = * pcbErrorMsg ;
261
+ else
262
+ outlen = 0 ;
263
+ if (!stmt -> errormsg_malloced || !stmt -> errormsg )
264
+ {
265
+ stmt -> errormsg = malloc (msglen - outlen + 1 );
266
+ stmt -> errormsg_malloced = TRUE;
267
+ }
268
+ memmove (stmt -> errormsg , msg + outlen , msglen - outlen + 1 );
269
+ }
270
+ else if (stmt -> errormsg_malloced )
271
+ SC_clear_error (stmt );
272
+ if (cbErrorMsgMax == 0 )
273
+ return SQL_SUCCESS_WITH_INFO ;
274
+ else
275
+ return SQL_SUCCESS ;
242
276
}
243
277
else if (SQL_NULL_HDBC != hdbc )
244
278
{
0 commit comments