char *msg;
int status;
- mylog("**** SQLError: henv=%u, hdbc=%u, hstmt=%u\n", henv, hdbc, hstmt);
+ mylog("**** SQLError: henv=%u, hdbc=%u, hstmt=%u <%d>\n", henv, hdbc, hstmt, cbErrorMsgMax);
+ if (cbErrorMsgMax < 0)
+ return SQL_ERROR;
if (SQL_NULL_HSTMT != hstmt)
{
/* CC: return an error of a hstmt */
StatementClass *stmt = (StatementClass *) hstmt;
+ SWORD msglen;
+ BOOL once_again = FALSE;
if (SC_get_error(stmt, &status, &msg))
{
return SQL_NO_DATA_FOUND;
}
+ msglen = (SWORD) strlen(msg);
if (NULL != pcbErrorMsg)
- *pcbErrorMsg = (SWORD) strlen(msg);
+ {
+ *pcbErrorMsg = msglen;
+ if (cbErrorMsgMax == 0)
+ once_again = TRUE;
+ else if (msglen >= cbErrorMsgMax)
+ {
+ once_again = TRUE;
+ *pcbErrorMsg = cbErrorMsgMax - 1;
+ }
+ }
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
return SQL_NO_DATA_FOUND;
}
- return SQL_SUCCESS;
+ if (once_again)
+ {
+ int outlen;
+ stmt->errornumber = status;
+ if (cbErrorMsgMax > 0)
+ outlen = *pcbErrorMsg;
+ else
+ outlen = 0;
+ if (!stmt->errormsg_malloced || !stmt->errormsg)
+ {
+ stmt->errormsg = malloc(msglen - outlen + 1);
+ stmt->errormsg_malloced = TRUE;
+ }
+ memmove(stmt->errormsg, msg + outlen, msglen - outlen + 1);
+ }
+ else if (stmt->errormsg_malloced)
+ SC_clear_error(stmt);
+ if (cbErrorMsgMax == 0)
+ return SQL_SUCCESS_WITH_INFO;
+ else
+ return SQL_SUCCESS;
}
else if (SQL_NULL_HDBC != hdbc)
{
rv->errormsg = NULL;
rv->errornumber = 0;
rv->errormsg_created = FALSE;
+ rv->errormsg_malloced = FALSE;
rv->statement = NULL;
rv->stmt_with_params = NULL;
self->bind_row = 0;
self->last_fetch_count = 0;
+ if (self->errormsg_malloced && self->errormsg)
+ free(self->errormsg);
self->errormsg = NULL;
self->errornumber = 0;
self->errormsg_created = FALSE;
+ self->errormsg_malloced = FALSE;
self->lobj_fd = -1;
void
SC_clear_error(StatementClass *self)
{
+ if (self->errormsg_malloced && self->errormsg)
+ free(self->errormsg);
self->errornumber = 0;
self->errormsg = NULL;
self->errormsg_created = FALSE;
+ self->errormsg_malloced = FALSE;
}
{
*number = self->errornumber;
*message = self->errormsg;
- self->errormsg = NULL;
+ if (!self->errormsg_malloced)
+ self->errormsg = NULL;
}
rv = (self->errornumber != 0);
char pre_executing; /* This statement is prematurely executing */
char inaccurate_result; /* Current status is PREMATURE but
* result is inaccurate */
+ char errormsg_malloced; /* Current status is PREMATURE but
+ * result is inaccurate */
};
#define SC_get_conn(a) (a->hdbc)