[Freeswitch-svn] [commit] r10552 - in freeswitch/trunk/src: . include

FreeSWITCH SVN intralanman at freeswitch.org
Wed Nov 26 18:03:21 PST 2008


Author: intralanman
Date: Wed Nov 26 21:03:21 2008
New Revision: 10552

Log:
FSCORE-236

Modified:
   freeswitch/trunk/src/include/switch_odbc.h
   freeswitch/trunk/src/switch_odbc.c

Modified: freeswitch/trunk/src/include/switch_odbc.h
==============================================================================
--- freeswitch/trunk/src/include/switch_odbc.h	(original)
+++ freeswitch/trunk/src/include/switch_odbc.h	Wed Nov 26 21:03:21 2008
@@ -64,8 +64,35 @@
 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

Modified: freeswitch/trunk/src/switch_odbc.c
==============================================================================
--- freeswitch/trunk/src/switch_odbc.c	(original)
+++ freeswitch/trunk/src/switch_odbc.c	Wed Nov 26 21:03:21 2008
@@ -322,12 +322,14 @@
 	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 @@
 	}
 
 	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 @@
 
   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);
 	}
 



More information about the Freeswitch-svn mailing list