Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 9c50a00

Browse files
author
Hiroshi Inoue
committed
Change the driver so that large error messages are returned
by multiple SQLError calls.
1 parent f5d0c6c commit 9c50a00

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

src/interfaces/odbc/environ.c

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,16 @@ SQLError(
9191
char *msg;
9292
int status;
9393

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);
9595

96+
if (cbErrorMsgMax < 0)
97+
return SQL_ERROR;
9698
if (SQL_NULL_HSTMT != hstmt)
9799
{
98100
/* CC: return an error of a hstmt */
99101
StatementClass *stmt = (StatementClass *) hstmt;
102+
SWORD msglen;
103+
BOOL once_again = FALSE;
100104

101105
if (SC_get_error(stmt, &status, &msg))
102106
{
@@ -112,8 +116,18 @@ SQLError(
112116

113117
return SQL_NO_DATA_FOUND;
114118
}
119+
msglen = (SWORD) strlen(msg);
115120
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+
}
117131

118132
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
119133
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
@@ -238,7 +252,27 @@ SQLError(
238252
return SQL_NO_DATA_FOUND;
239253
}
240254

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;
242276
}
243277
else if (SQL_NULL_HDBC != hdbc)
244278
{

src/interfaces/odbc/statement.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@ SC_Constructor(void)
248248
rv->errormsg = NULL;
249249
rv->errornumber = 0;
250250
rv->errormsg_created = FALSE;
251+
rv->errormsg_malloced = FALSE;
251252

252253
rv->statement = NULL;
253254
rv->stmt_with_params = NULL;
@@ -530,9 +531,12 @@ SC_recycle_statement(StatementClass *self)
530531
self->bind_row = 0;
531532
self->last_fetch_count = 0;
532533

534+
if (self->errormsg_malloced && self->errormsg)
535+
free(self->errormsg);
533536
self->errormsg = NULL;
534537
self->errornumber = 0;
535538
self->errormsg_created = FALSE;
539+
self->errormsg_malloced = FALSE;
536540

537541
self->lobj_fd = -1;
538542

@@ -610,9 +614,12 @@ SC_unbind_cols(StatementClass *self)
610614
void
611615
SC_clear_error(StatementClass *self)
612616
{
617+
if (self->errormsg_malloced && self->errormsg)
618+
free(self->errormsg);
613619
self->errornumber = 0;
614620
self->errormsg = NULL;
615621
self->errormsg_created = FALSE;
622+
self->errormsg_malloced = FALSE;
616623
}
617624

618625

@@ -675,7 +682,8 @@ SC_get_error(StatementClass *self, int *number, char **message)
675682
{
676683
*number = self->errornumber;
677684
*message = self->errormsg;
678-
self->errormsg = NULL;
685+
if (!self->errormsg_malloced)
686+
self->errormsg = NULL;
679687
}
680688

681689
rv = (self->errornumber != 0);

src/interfaces/odbc/statement.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ struct StatementClass_
218218
char pre_executing; /* This statement is prematurely executing */
219219
char inaccurate_result; /* Current status is PREMATURE but
220220
* result is inaccurate */
221+
char errormsg_malloced; /* Current status is PREMATURE but
222+
* result is inaccurate */
221223
};
222224

223225
#define SC_get_conn(a) (a->hdbc)

0 commit comments

Comments
 (0)