mirror of
https://github.com/postgres/postgres.git
synced 2025-06-06 00:02:36 -04:00
Change the driver so that large error messages are returned
by multiple SQLError calls.
This commit is contained in:
parent
f5d0c6cad5
commit
9c50a0047f
@ -91,12 +91,16 @@ SQLError(
|
|||||||
char *msg;
|
char *msg;
|
||||||
int status;
|
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)
|
if (SQL_NULL_HSTMT != hstmt)
|
||||||
{
|
{
|
||||||
/* CC: return an error of a hstmt */
|
/* CC: return an error of a hstmt */
|
||||||
StatementClass *stmt = (StatementClass *) hstmt;
|
StatementClass *stmt = (StatementClass *) hstmt;
|
||||||
|
SWORD msglen;
|
||||||
|
BOOL once_again = FALSE;
|
||||||
|
|
||||||
if (SC_get_error(stmt, &status, &msg))
|
if (SC_get_error(stmt, &status, &msg))
|
||||||
{
|
{
|
||||||
@ -112,8 +116,18 @@ SQLError(
|
|||||||
|
|
||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
}
|
}
|
||||||
|
msglen = (SWORD) strlen(msg);
|
||||||
if (NULL != pcbErrorMsg)
|
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))
|
if ((NULL != szErrorMsg) && (cbErrorMsgMax > 0))
|
||||||
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
|
strncpy_null(szErrorMsg, msg, cbErrorMsgMax);
|
||||||
@ -238,6 +252,26 @@ SQLError(
|
|||||||
return SQL_NO_DATA_FOUND;
|
return SQL_NO_DATA_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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;
|
return SQL_SUCCESS;
|
||||||
}
|
}
|
||||||
else if (SQL_NULL_HDBC != hdbc)
|
else if (SQL_NULL_HDBC != hdbc)
|
||||||
|
@ -248,6 +248,7 @@ SC_Constructor(void)
|
|||||||
rv->errormsg = NULL;
|
rv->errormsg = NULL;
|
||||||
rv->errornumber = 0;
|
rv->errornumber = 0;
|
||||||
rv->errormsg_created = FALSE;
|
rv->errormsg_created = FALSE;
|
||||||
|
rv->errormsg_malloced = FALSE;
|
||||||
|
|
||||||
rv->statement = NULL;
|
rv->statement = NULL;
|
||||||
rv->stmt_with_params = NULL;
|
rv->stmt_with_params = NULL;
|
||||||
@ -530,9 +531,12 @@ SC_recycle_statement(StatementClass *self)
|
|||||||
self->bind_row = 0;
|
self->bind_row = 0;
|
||||||
self->last_fetch_count = 0;
|
self->last_fetch_count = 0;
|
||||||
|
|
||||||
|
if (self->errormsg_malloced && self->errormsg)
|
||||||
|
free(self->errormsg);
|
||||||
self->errormsg = NULL;
|
self->errormsg = NULL;
|
||||||
self->errornumber = 0;
|
self->errornumber = 0;
|
||||||
self->errormsg_created = FALSE;
|
self->errormsg_created = FALSE;
|
||||||
|
self->errormsg_malloced = FALSE;
|
||||||
|
|
||||||
self->lobj_fd = -1;
|
self->lobj_fd = -1;
|
||||||
|
|
||||||
@ -610,9 +614,12 @@ SC_unbind_cols(StatementClass *self)
|
|||||||
void
|
void
|
||||||
SC_clear_error(StatementClass *self)
|
SC_clear_error(StatementClass *self)
|
||||||
{
|
{
|
||||||
|
if (self->errormsg_malloced && self->errormsg)
|
||||||
|
free(self->errormsg);
|
||||||
self->errornumber = 0;
|
self->errornumber = 0;
|
||||||
self->errormsg = NULL;
|
self->errormsg = NULL;
|
||||||
self->errormsg_created = FALSE;
|
self->errormsg_created = FALSE;
|
||||||
|
self->errormsg_malloced = FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -675,6 +682,7 @@ SC_get_error(StatementClass *self, int *number, char **message)
|
|||||||
{
|
{
|
||||||
*number = self->errornumber;
|
*number = self->errornumber;
|
||||||
*message = self->errormsg;
|
*message = self->errormsg;
|
||||||
|
if (!self->errormsg_malloced)
|
||||||
self->errormsg = NULL;
|
self->errormsg = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,6 +218,8 @@ struct StatementClass_
|
|||||||
char pre_executing; /* This statement is prematurely executing */
|
char pre_executing; /* This statement is prematurely executing */
|
||||||
char inaccurate_result; /* Current status is PREMATURE but
|
char inaccurate_result; /* Current status is PREMATURE but
|
||||||
* result is inaccurate */
|
* result is inaccurate */
|
||||||
|
char errormsg_malloced; /* Current status is PREMATURE but
|
||||||
|
* result is inaccurate */
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SC_get_conn(a) (a->hdbc)
|
#define SC_get_conn(a) (a->hdbc)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user