]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FSCORE-236
authorRaymond Chandler <intralanman@freeswitch.org>
Thu, 27 Nov 2008 02:03:21 +0000 (02:03 +0000)
committerRaymond Chandler <intralanman@freeswitch.org>
Thu, 27 Nov 2008 02:03:21 +0000 (02:03 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@10552 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_odbc.h
src/switch_odbc.c

index 1ec96ab4895ae871ceca38dbabad0ea61cfd454a..4bbc15471f9ec1e1c15caab2ce66f95adfe4b6a5 100644 (file)
@@ -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
index 19cff2d7d01a2fe669f99a3ed9f64f13d795bf1d..41628415e9e975c4255c57baf4b564014f1e2975 100644 (file)
@@ -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);
        }