diff --git a/src/mod/languages/mod_lua/freeswitch.i b/src/mod/languages/mod_lua/freeswitch.i index 54bdb7bdc9..cea764d9d6 100644 --- a/src/mod/languages/mod_lua/freeswitch.i +++ b/src/mod/languages/mod_lua/freeswitch.i @@ -82,12 +82,13 @@ class Session : public CoreSession { class Dbh { private: switch_cache_db_handle_t *dbh; - bool connected; + bool m_connected; static int query_callback(void *pArg, int argc, char **argv, char **cargv); public: Dbh(char *dsn, char *user = NULL, char *pass = NULL); ~Dbh(); bool release(); + bool connected(); bool query(char *sql, SWIGLUA_FN lua_fun); }; diff --git a/src/mod/languages/mod_lua/freeswitch_lua.cpp b/src/mod/languages/mod_lua/freeswitch_lua.cpp index d60ae737a8..aad87fa6c1 100644 --- a/src/mod/languages/mod_lua/freeswitch_lua.cpp +++ b/src/mod/languages/mod_lua/freeswitch_lua.cpp @@ -318,9 +318,9 @@ Dbh::Dbh(char *dsn, char *user, char *pass) options.odbc_options.pass = pass; if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) == SWITCH_STATUS_SUCCESS) { - connected = true; + m_connected = true; } else { - connected = false; + m_connected = false; } } @@ -331,14 +331,19 @@ Dbh::~Dbh() bool Dbh::release() { - if (connected) { + if (m_connected) { switch_cache_db_release_db_handle(&dbh); - connected = false; + m_connected = false; return true; } return false; } +bool Dbh::connected() +{ + return m_connected; +} + int Dbh::query_callback(void *pArg, int argc, char **argv, char **cargv) { SWIGLUA_FN *lua_fun = (SWIGLUA_FN *)pArg; @@ -366,7 +371,7 @@ int Dbh::query_callback(void *pArg, int argc, char **argv, char **cargv) bool Dbh::query(char *sql, SWIGLUA_FN lua_fun) { - if (connected) { + if (m_connected) { if (lua_fun.L) { if (switch_cache_db_execute_sql_callback(dbh, sql, query_callback, &lua_fun, NULL) == SWITCH_STATUS_SUCCESS) { return true; diff --git a/src/mod/languages/mod_lua/freeswitch_lua.h b/src/mod/languages/mod_lua/freeswitch_lua.h index a0780b1537..3c43ebdd9f 100644 --- a/src/mod/languages/mod_lua/freeswitch_lua.h +++ b/src/mod/languages/mod_lua/freeswitch_lua.h @@ -55,12 +55,13 @@ namespace LUA { class Dbh { protected: switch_cache_db_handle_t *dbh; - bool connected; + bool m_connected; static int query_callback(void *pArg, int argc, char **argv, char **cargv); public: Dbh(char *dsn, char *user = NULL, char *pass = NULL); ~Dbh(); bool release(); + bool connected(); bool query(char *sql, SWIGLUA_FN lua_fun); }; } diff --git a/src/mod/languages/mod_lua/mod_lua_wrap.cpp b/src/mod/languages/mod_lua/mod_lua_wrap.cpp index d32646654c..4e2971098b 100644 --- a/src/mod/languages/mod_lua/mod_lua_wrap.cpp +++ b/src/mod/languages/mod_lua/mod_lua_wrap.cpp @@ -7229,6 +7229,31 @@ fail: } +static int _wrap_Dbh_connected(lua_State* L) { + int SWIG_arg = -1; + LUA::Dbh *arg1 = (LUA::Dbh *) 0 ; + bool result; + + SWIG_check_num_args("connected",1,1) + if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("connected",1,"LUA::Dbh *"); + + if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_LUA__Dbh,0))){ + SWIG_fail_ptr("Dbh_connected",1,SWIGTYPE_p_LUA__Dbh); + } + + result = (bool)(arg1)->connected(); + SWIG_arg=0; + lua_pushboolean(L,(int)(result==true)); SWIG_arg++; + return SWIG_arg; + + if(0) SWIG_fail; + +fail: + lua_error(L); + return SWIG_arg; +} + + static int _wrap_Dbh_query(lua_State* L) { int SWIG_arg = -1; LUA::Dbh *arg1 = (LUA::Dbh *) 0 ; @@ -7277,6 +7302,7 @@ delete arg1; } static swig_lua_method swig_LUA_Dbh_methods[] = { {"release", _wrap_Dbh_release}, + {"connected", _wrap_Dbh_connected}, {"query", _wrap_Dbh_query}, {0,0} };