mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-12 15:45:18 +00:00
res_odbc: fix missing SQL error diagnostic
On SQL error there is not diagnostic information about this error. There is only WARNING res_odbc.c: SQL Execute error -1! The function ast_odbc_print_errors calls a SQLGetDiagField to get the number of available diagnostic records, but the SQLGetDiagField returns 0. However SQLGetDiagRec could return one diagnostic records in this case. Looking at many example of getting diagnostics error information I found out that the best way it's to use only SQLGetDiagRec while it returns SQL_SUCCESS. Also this patch adds calls of ast_odbc_print_errors on SQL_ERROR to res_config_odbc. ASTERISK-28065 #close Change-Id: Iba5ae5470ac49ecd911dd084effbe9efac68ccc1
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);
|
||||
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);
|
||||
SQLFreeHandle (SQL_HANDLE_STMT, stmt);
|
||||
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);
|
||||
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));
|
||||
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
|
||||
return NULL;
|
||||
|
Reference in New Issue
Block a user