mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-04 11:58:52 +00:00
Merge "res_odbc: fix missing SQL error diagnostic"
This commit is contained in:
@@ -116,6 +116,9 @@ static SQLHSTMT custom_prepare(struct odbc_obj *obj, void *data)
|
|||||||
|
|
||||||
res = SQLPrepare(stmt, (unsigned char *)cps->sql, SQL_NTS);
|
res = SQLPrepare(stmt, (unsigned char *)cps->sql, SQL_NTS);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
|
if (res == SQL_ERROR) {
|
||||||
|
ast_odbc_print_errors(SQL_HANDLE_STMT, stmt, "SQL Prepare");
|
||||||
|
}
|
||||||
ast_log(LOG_WARNING, "SQL Prepare failed! [%s]\n", cps->sql);
|
ast_log(LOG_WARNING, "SQL Prepare failed! [%s]\n", cps->sql);
|
||||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -631,6 +634,9 @@ static SQLHSTMT update2_prepare(struct odbc_obj *obj, void *data)
|
|||||||
|
|
||||||
res = SQLPrepare(stmt, (unsigned char *)ast_str_buffer(sql), SQL_NTS);
|
res = SQLPrepare(stmt, (unsigned char *)ast_str_buffer(sql), SQL_NTS);
|
||||||
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
if ((res != SQL_SUCCESS) && (res != SQL_SUCCESS_WITH_INFO)) {
|
||||||
|
if (res == SQL_ERROR) {
|
||||||
|
ast_odbc_print_errors(SQL_HANDLE_STMT, stmt, "SQL Prepare");
|
||||||
|
}
|
||||||
ast_log(LOG_WARNING, "SQL Prepare failed! [%s]\n", ast_str_buffer(sql));
|
ast_log(LOG_WARNING, "SQL Prepare failed! [%s]\n", ast_str_buffer(sql));
|
||||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@@ -431,23 +431,20 @@ struct ast_str *ast_odbc_print_errors(SQLSMALLINT handle_type, SQLHANDLE handle,
|
|||||||
{
|
{
|
||||||
struct ast_str *errors = ast_str_thread_get(&errors_buf, 16);
|
struct ast_str *errors = ast_str_thread_get(&errors_buf, 16);
|
||||||
SQLINTEGER nativeerror = 0;
|
SQLINTEGER nativeerror = 0;
|
||||||
SQLINTEGER numfields = 0;
|
|
||||||
SQLSMALLINT diagbytes = 0;
|
SQLSMALLINT diagbytes = 0;
|
||||||
SQLSMALLINT i;
|
SQLSMALLINT i;
|
||||||
unsigned char state[10];
|
unsigned char state[10];
|
||||||
unsigned char diagnostic[256];
|
unsigned char diagnostic[256];
|
||||||
|
|
||||||
ast_str_reset(errors);
|
ast_str_reset(errors);
|
||||||
SQLGetDiagField(handle_type, handle, 1, SQL_DIAG_NUMBER, &numfields,
|
i = 0;
|
||||||
SQL_IS_INTEGER, &diagbytes);
|
while (SQLGetDiagRec(handle_type, handle, ++i, state, &nativeerror,
|
||||||
for (i = 0; i < numfields; i++) {
|
diagnostic, sizeof(diagnostic), &diagbytes) == SQL_SUCCESS) {
|
||||||
SQLGetDiagRec(handle_type, handle, i + 1, state, &nativeerror,
|
|
||||||
diagnostic, sizeof(diagnostic), &diagbytes);
|
|
||||||
ast_str_append(&errors, 0, "%s%s", ast_str_strlen(errors) ? "," : "", state);
|
ast_str_append(&errors, 0, "%s%s", ast_str_strlen(errors) ? "," : "", state);
|
||||||
ast_log(LOG_WARNING, "%s returned an error: %s: %s\n", operation, state, diagnostic);
|
ast_log(LOG_WARNING, "%s returned an error: %s: %s\n", operation, state, diagnostic);
|
||||||
/* XXX Why is this here? */
|
/* XXX Why is this here? */
|
||||||
if (i > 10) {
|
if (i > 10) {
|
||||||
ast_log(LOG_WARNING, "Oh, that was good. There are really %d diagnostics?\n", (int)numfields);
|
ast_log(LOG_WARNING, "There are more than 10 diagnostic records! Ignore the rest.\n");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user