提交 673d442a authored 作者: Raymond Chandler's avatar Raymond Chandler

FSCORE-236

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10552 d0543943-73ff-0310-b7d9-9358b9ac24b2
上级 cad11dd9
......@@ -64,8 +64,35 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_connect(switch_odbc_hand
SWITCH_DECLARE(void) switch_odbc_handle_destroy(switch_odbc_handle_t **handlep);
SWITCH_DECLARE(switch_odbc_state_t) switch_odbc_handle_get_state(switch_odbc_handle_t *handle);
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_t *handle, char *sql, SQLHSTMT * rstmt);
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odbc_handle_t *handle,
/*!
\brief Execute the sql query and issue a callback for each row returned
\param file the file from which this function is called
\param func the function from which this function is called
\param line the line from which this function is called
\param handle the ODBC handle
\param sql the sql string to execute
\param callback the callback function to execute
\param pdata the state data passed on each callback invocation
\return SWITCH_STATUS_SUCCESS if the operation was successful
\note none
*/
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(const char *file, const char *func, int line, switch_odbc_handle_t *handle,
char *sql, switch_core_db_callback_func_t callback, void *pdata);
/*!
\brief Execute the sql query and issue a callback for each row returned
\param handle the ODBC handle
\param sql the sql string to execute
\param callback the callback function to execute
\param pdata the state data passed on each callback invocation
\return SWITCH_STATUS_SUCCESS if the operation was successful
\note none
*/
#define switch_odbc_handle_callback_exec(handle, sql, callback, pdata) \
switch_odbc_handle_callback_exec_detailed(__FILE__, (char * )__SWITCH_FUNC__, __LINE__, \
handle, sql, callback, pdata)
SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, SQLHSTMT stmt);
SWITCH_END_EXTERN_C
#endif
......
......@@ -322,12 +322,14 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_
return SWITCH_ODBC_FAIL;
}
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odbc_handle_t *handle,
char *sql, switch_core_db_callback_func_t callback, void *pdata)
SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(const char *file, const char *func, int line,
switch_odbc_handle_t *handle,
char *sql, switch_core_db_callback_func_t callback, void *pdata)
{
SQLHSTMT stmt = NULL;
SQLSMALLINT c = 0, x = 0;
SQLLEN m = 0, t = 0;
char *err_str = NULL;
int result;
switch_assert(callback != NULL);
......@@ -337,10 +339,12 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odb
}
if (SQLAllocHandle(SQL_HANDLE_STMT, handle->con, &stmt) != SQL_SUCCESS) {
err_str = "Unable to SQL allocate handle.";
goto error;
}
if (SQLPrepare(stmt, (unsigned char *) sql, SQL_NTS) != SQL_SUCCESS) {
err_str = "Unable to prepare SQL statement.";
goto error;
}
......@@ -407,7 +411,18 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec(switch_odb
error:
/* err_str is already defined for some error cases */
if (err_str != NULL) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
err_str = NULL;
}
if (stmt) {
err_str = switch_odbc_handle_get_error(handle, stmt);
if (!switch_strlen_zero(err_str)) {
switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, "ERR: [%s]\n[%s]\n", sql, switch_str_nil(err_str));
}
switch_safe_free(err_str);
SQLFreeHandle(SQL_HANDLE_STMT, stmt);
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论