diff --git a/src/include/switch_core.h b/src/include/switch_core.h index d02018b686..ff131acb17 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -2162,6 +2162,13 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_hand SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql_callback(switch_cache_db_handle_t *dbh, const char *sql, switch_core_db_callback_func_t callback, void *pdata, char **err); +/*! + \brief Get the affected rows of the last performed query + \param [in] dbh The handle + \param [out] the number of affected rows +*/ +SWITCH_DECLARE(int) switch_cache_db_affected_rows(switch_cache_db_handle_t *dbh); + /*! \brief Provides some feedback as to the status of the db connection pool \param [in] stream stream for status diff --git a/src/include/switch_odbc.h b/src/include/switch_odbc.h index 0b5f90462f..f76384003a 100644 --- a/src/include/switch_odbc.h +++ b/src/include/switch_odbc.h @@ -92,6 +92,9 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle, switch_odbc_statement_handle_t stmt); + +SWITCH_DECLARE(int) switch_odbc_handle_affected_rows(switch_odbc_handle_t *handle); + SWITCH_END_EXTERN_C #endif /* For Emacs: diff --git a/src/mod/languages/mod_lua/freeswitch.i b/src/mod/languages/mod_lua/freeswitch.i index cea764d9d6..9ccaf8ea9f 100644 --- a/src/mod/languages/mod_lua/freeswitch.i +++ b/src/mod/languages/mod_lua/freeswitch.i @@ -90,6 +90,7 @@ class Dbh { bool release(); bool connected(); bool query(char *sql, SWIGLUA_FN lua_fun); + int affected_rows(); }; } diff --git a/src/mod/languages/mod_lua/freeswitch_lua.cpp b/src/mod/languages/mod_lua/freeswitch_lua.cpp index aad87fa6c1..1a170dcc98 100644 --- a/src/mod/languages/mod_lua/freeswitch_lua.cpp +++ b/src/mod/languages/mod_lua/freeswitch_lua.cpp @@ -384,3 +384,11 @@ bool Dbh::query(char *sql, SWIGLUA_FN lua_fun) } return false; } + +int Dbh::affected_rows() +{ + if (m_connected) { + return switch_cache_db_affected_rows(dbh); + } + return 0; +} diff --git a/src/mod/languages/mod_lua/freeswitch_lua.h b/src/mod/languages/mod_lua/freeswitch_lua.h index 3c43ebdd9f..5f7966266c 100644 --- a/src/mod/languages/mod_lua/freeswitch_lua.h +++ b/src/mod/languages/mod_lua/freeswitch_lua.h @@ -63,6 +63,7 @@ namespace LUA { bool release(); bool connected(); bool query(char *sql, SWIGLUA_FN lua_fun); + int affected_rows(); }; } #endif diff --git a/src/mod/languages/mod_lua/mod_lua_wrap.cpp b/src/mod/languages/mod_lua/mod_lua_wrap.cpp index 4e2971098b..f10ed63fca 100644 --- a/src/mod/languages/mod_lua/mod_lua_wrap.cpp +++ b/src/mod/languages/mod_lua/mod_lua_wrap.cpp @@ -7296,6 +7296,31 @@ fail: } +static int _wrap_Dbh_affected_rows(lua_State* L) { + int SWIG_arg = -1; + LUA::Dbh *arg1 = (LUA::Dbh *) 0 ; + int result; + + SWIG_check_num_args("affected_rows",1,1) + if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("affected_rows",1,"LUA::Dbh *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_LUA__Dbh,0))){ + SWIG_fail_ptr("Dbh_affected_rows",1,SWIGTYPE_p_LUA__Dbh); + } + + result = (int)(arg1)->affected_rows(); + SWIG_arg=0; + lua_pushnumber(L, (lua_Number) result); SWIG_arg++; + return SWIG_arg; + + if(0) SWIG_fail; + +fail: + lua_error(L); + return SWIG_arg; +} + + static void swig_delete_Dbh(void *obj) { LUA::Dbh *arg1 = (LUA::Dbh *) obj; delete arg1; @@ -7304,6 +7329,7 @@ static swig_lua_method swig_LUA_Dbh_methods[] = { {"release", _wrap_Dbh_release}, {"connected", _wrap_Dbh_connected}, {"query", _wrap_Dbh_query}, + {"affected_rows", _wrap_Dbh_affected_rows}, {0,0} }; static swig_lua_attribute swig_LUA_Dbh_attributes[] = { diff --git a/src/mod/languages/mod_managed/freeswitch_wrap.cxx b/src/mod/languages/mod_managed/freeswitch_wrap.cxx index 33ceb470a1..d05f4f1213 100644 --- a/src/mod/languages/mod_managed/freeswitch_wrap.cxx +++ b/src/mod/languages/mod_managed/freeswitch_wrap.cxx @@ -10688,6 +10688,18 @@ SWIGEXPORT int SWIGSTDCALL CSharp_switch_cache_db_execute_sql_callback(void * ja } +SWIGEXPORT int SWIGSTDCALL CSharp_switch_cache_db_affected_rows(void * jarg1) { + int jresult ; + switch_cache_db_handle_t *arg1 = (switch_cache_db_handle_t *) 0 ; + int result; + + arg1 = (switch_cache_db_handle_t *)jarg1; + result = (int)switch_cache_db_affected_rows(arg1); + jresult = result; + return jresult; +} + + SWIGEXPORT void SWIGSTDCALL CSharp_switch_cache_db_status(void * jarg1) { switch_stream_handle_t *arg1 = (switch_stream_handle_t *) 0 ; diff --git a/src/mod/languages/mod_managed/managed/swig.cs b/src/mod/languages/mod_managed/managed/swig.cs index e51b050b25..849a6f62a4 100644 --- a/src/mod/languages/mod_managed/managed/swig.cs +++ b/src/mod/languages/mod_managed/managed/swig.cs @@ -2333,6 +2333,11 @@ public class freeswitch { return ret; } + public static int switch_cache_db_affected_rows(switch_cache_db_handle_t dbh) { + int ret = freeswitchPINVOKE.switch_cache_db_affected_rows(switch_cache_db_handle_t.getCPtr(dbh)); + return ret; + } + public static void switch_cache_db_status(switch_stream_handle stream) { freeswitchPINVOKE.switch_cache_db_status(switch_stream_handle.getCPtr(stream)); } @@ -8209,6 +8214,9 @@ class freeswitchPINVOKE { [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_execute_sql_callback")] public static extern int switch_cache_db_execute_sql_callback(HandleRef jarg1, string jarg2, HandleRef jarg3, HandleRef jarg4, ref string jarg5); + [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_affected_rows")] + public static extern int switch_cache_db_affected_rows(HandleRef jarg1); + [DllImport("mod_managed", EntryPoint="CSharp_switch_cache_db_status")] public static extern void switch_cache_db_status(HandleRef jarg1); diff --git a/src/mod/languages/mod_perl/mod_perl_wrap.cpp b/src/mod/languages/mod_perl/mod_perl_wrap.cpp index c22905285d..e8a4b9f409 100644 --- a/src/mod/languages/mod_perl/mod_perl_wrap.cpp +++ b/src/mod/languages/mod_perl/mod_perl_wrap.cpp @@ -9793,17 +9793,17 @@ XS(SWIG_init) { SWIG_TypeClientData(SWIGTYPE_p_IVRMenu, (void*) "freeswitch::IVRMenu"); SWIG_TypeClientData(SWIGTYPE_p_API, (void*) "freeswitch::API"); SWIG_TypeClientData(SWIGTYPE_p_input_callback_state, (void*) "freeswitch::input_callback_state_t"); - /*@SWIG:/usr/local/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { + /*@SWIG:/usr/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "S_HUP", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(S_HUP))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; - /*@SWIG:/usr/local/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { + /*@SWIG:/usr/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "S_FREE", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(S_FREE))); SvREADONLY_on(sv); } while(0) /*@SWIG@*/; - /*@SWIG:/usr/local/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { + /*@SWIG:/usr/share/swig/1.3.35/perl5/perltypemaps.swg,64,%set_constant@*/ do { SV *sv = get_sv((char*) SWIG_prefix "S_RDLOCK", TRUE | 0x2 | GV_ADDMULTI); sv_setsv(sv, SWIG_From_int SWIG_PERL_CALL_ARGS_1(static_cast< int >(S_RDLOCK))); SvREADONLY_on(sv); diff --git a/src/switch_core_sqldb.c b/src/switch_core_sqldb.c index c32b40629d..4167b4a89c 100644 --- a/src/switch_core_sqldb.c +++ b/src/switch_core_sqldb.c @@ -573,6 +573,24 @@ SWITCH_DECLARE(switch_status_t) switch_cache_db_execute_sql(switch_cache_db_hand } +SWITCH_DECLARE(int) switch_cache_db_affected_rows(switch_cache_db_handle_t *dbh) +{ + switch (dbh->type) { + case SCDB_TYPE_CORE_DB: + { + return switch_core_db_changes(dbh->native_handle.core_db_dbh); + } + break; + case SCDB_TYPE_ODBC: + { + return switch_odbc_handle_affected_rows(dbh->native_handle.odbc_dbh); + } + break; + } + return 0; +} + + SWITCH_DECLARE(char *) switch_cache_db_execute_sql2str(switch_cache_db_handle_t *dbh, char *sql, char *str, size_t len, char **err) { switch_status_t status = SWITCH_STATUS_FALSE; diff --git a/src/switch_odbc.c b/src/switch_odbc.c index 31fd8f5cf7..48ba62ce03 100644 --- a/src/switch_odbc.c +++ b/src/switch_odbc.c @@ -56,6 +56,7 @@ struct switch_odbc_handle { switch_odbc_state_t state; char odbc_driver[256]; BOOL is_firebird; + int affected_rows; }; #endif @@ -88,6 +89,7 @@ SWITCH_DECLARE(switch_odbc_handle_t *) switch_odbc_handle_new(const char *dsn, c new_handle->env = SQL_NULL_HANDLE; new_handle->state = SWITCH_ODBC_STATE_INIT; + new_handle->affected_rows = 0; return new_handle; @@ -355,12 +357,15 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec_string(switch_odbc_ SQLCHAR name[1024]; SQLLEN m = 0; + handle->affected_rows = 0; + if (switch_odbc_handle_exec(handle, sql, &stmt, err) == SWITCH_ODBC_SUCCESS) { SQLSMALLINT NameLength, DataType, DecimalDigits, Nullable; SQLULEN ColumnSize; int result; SQLRowCount(stmt, &m); + handle->affected_rows = (int) m; if (m <= 0) { goto done; @@ -395,6 +400,9 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_ SQLHSTMT stmt = NULL; int result; char *err_str = NULL; + SQLLEN m = 0; + + handle->affected_rows = 0; if (!db_is_up(handle)) { goto error; @@ -414,6 +422,9 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_exec(switch_odbc_handle_ goto error; } + SQLRowCount(stmt, &m); + handle->affected_rows = (int) m; + if (rstmt) { *rstmt = stmt; } else { @@ -462,6 +473,8 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c int err_cnt = 0; int done = 0; + handle->affected_rows = 0; + switch_assert(callback != NULL); if (!db_is_up(handle)) { @@ -486,6 +499,7 @@ SWITCH_DECLARE(switch_odbc_status_t) switch_odbc_handle_callback_exec_detailed(c SQLNumResultCols(stmt, &c); SQLRowCount(stmt, &m); + handle->affected_rows = (int) m; while (!done) { @@ -621,6 +635,15 @@ SWITCH_DECLARE(char *) switch_odbc_handle_get_error(switch_odbc_handle_t *handle #endif } +SWITCH_DECLARE(int) switch_odbc_handle_affected_rows(switch_odbc_handle_t *handle) +{ +#ifdef SWITCH_HAVE_ODBC + return handle->affected_rows; +#else + return 0; +#endif +} + SWITCH_DECLARE(switch_bool_t) switch_odbc_available(void) { #ifdef SWITCH_HAVE_ODBC