]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-2962
authorBrian West <brian@freeswitch.org>
Wed, 5 Jan 2011 17:45:48 +0000 (11:45 -0600)
committerBrian West <brian@freeswitch.org>
Wed, 5 Jan 2011 17:45:48 +0000 (11:45 -0600)
src/include/switch_core.h
src/include/switch_odbc.h
src/mod/languages/mod_lua/freeswitch.i
src/mod/languages/mod_lua/freeswitch_lua.cpp
src/mod/languages/mod_lua/freeswitch_lua.h
src/mod/languages/mod_lua/mod_lua_wrap.cpp
src/mod/languages/mod_managed/freeswitch_wrap.cxx
src/mod/languages/mod_managed/managed/swig.cs
src/mod/languages/mod_perl/mod_perl_wrap.cpp
src/switch_core_sqldb.c
src/switch_odbc.c

index d02018b686ada930e4bf7e746629a49927bb7685..ff131acb1742aca4c9ca74e60f2f44285ae39c36 100644 (file)
@@ -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
index 0b5f90462fa0a3cdc62cd539c8dbd85bfa4c8daa..f76384003ac8b1a4cd5f34afe82d11abc41d8e26 100644 (file)
@@ -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:
index cea764d9d61e0f9358925497650aaad22814d826..9ccaf8ea9f959913edc19d36e17cd9cfc85e658d 100644 (file)
@@ -90,6 +90,7 @@ class Dbh {
     bool release();
     bool connected();
     bool query(char *sql, SWIGLUA_FN lua_fun);
+    int affected_rows();
 };
 
 }
index aad87fa6c101f75cfd829469a3cecf1070b41d8e..1a170dcc983c98c2d329864c6dd6dc6a35574f1c 100644 (file)
@@ -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;
+}
index 3c43ebdd9f02fcdb6124466fbdc76170bf0b6675..5f7966266cb5f08f9bd0780c2b98517acc066d4a 100644 (file)
@@ -63,6 +63,7 @@ namespace LUA {
       bool release();
       bool connected();
       bool query(char *sql, SWIGLUA_FN lua_fun);
+      int affected_rows();
   };
 }
 #endif
index 4e2971098bfcf91a85b4802b42fce1d7da00d313..f10ed63fca473c18f2d0d04e916833a64decf1df 100644 (file)
@@ -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[] = {
index 33ceb470a1507477d7daf7d55306ad8559c333bf..d05f4f1213acedacd270dba17ce63dde21f79489 100644 (file)
@@ -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 ;
   
index e51b050b2577fe4fad29dd79e2786909c9155763..849a6f62a4f91741533c0335c04080001543191c 100644 (file)
@@ -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);
 
index c22905285d2d37ec84a86012d353d2ee0375eefc..e8a4b9f40938b440c195d75d40d34c7d5b7149da 100644 (file)
@@ -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);
index c32b40629d660ac47bcb8acd4378176bac8e9f46..4167b4a89cd6e2c862e6c954b96463b6648fa293 100644 (file)
@@ -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;
index 31fd8f5cf7d458e2b473e2d961cfef3325ce4b76..48ba62ce031eccfba8c45d0c245bcc3aa3092efe 100644 (file)
@@ -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