Make dbh:connected accessible from Lua - thanks Grmt
This commit is contained in:
parent
45a32dda3d
commit
09e6fd3f4e
|
@ -82,12 +82,13 @@ class Session : public CoreSession {
|
||||||
class Dbh {
|
class Dbh {
|
||||||
private:
|
private:
|
||||||
switch_cache_db_handle_t *dbh;
|
switch_cache_db_handle_t *dbh;
|
||||||
bool connected;
|
bool m_connected;
|
||||||
static int query_callback(void *pArg, int argc, char **argv, char **cargv);
|
static int query_callback(void *pArg, int argc, char **argv, char **cargv);
|
||||||
public:
|
public:
|
||||||
Dbh(char *dsn, char *user = NULL, char *pass = NULL);
|
Dbh(char *dsn, char *user = NULL, char *pass = NULL);
|
||||||
~Dbh();
|
~Dbh();
|
||||||
bool release();
|
bool release();
|
||||||
|
bool connected();
|
||||||
bool query(char *sql, SWIGLUA_FN lua_fun);
|
bool query(char *sql, SWIGLUA_FN lua_fun);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -318,9 +318,9 @@ Dbh::Dbh(char *dsn, char *user, char *pass)
|
||||||
options.odbc_options.pass = pass;
|
options.odbc_options.pass = pass;
|
||||||
|
|
||||||
if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) == SWITCH_STATUS_SUCCESS) {
|
if (switch_cache_db_get_db_handle(&dbh, SCDB_TYPE_ODBC, &options) == SWITCH_STATUS_SUCCESS) {
|
||||||
connected = true;
|
m_connected = true;
|
||||||
} else {
|
} else {
|
||||||
connected = false;
|
m_connected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -331,14 +331,19 @@ Dbh::~Dbh()
|
||||||
|
|
||||||
bool Dbh::release()
|
bool Dbh::release()
|
||||||
{
|
{
|
||||||
if (connected) {
|
if (m_connected) {
|
||||||
switch_cache_db_release_db_handle(&dbh);
|
switch_cache_db_release_db_handle(&dbh);
|
||||||
connected = false;
|
m_connected = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Dbh::connected()
|
||||||
|
{
|
||||||
|
return m_connected;
|
||||||
|
}
|
||||||
|
|
||||||
int Dbh::query_callback(void *pArg, int argc, char **argv, char **cargv)
|
int Dbh::query_callback(void *pArg, int argc, char **argv, char **cargv)
|
||||||
{
|
{
|
||||||
SWIGLUA_FN *lua_fun = (SWIGLUA_FN *)pArg;
|
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)
|
bool Dbh::query(char *sql, SWIGLUA_FN lua_fun)
|
||||||
{
|
{
|
||||||
if (connected) {
|
if (m_connected) {
|
||||||
if (lua_fun.L) {
|
if (lua_fun.L) {
|
||||||
if (switch_cache_db_execute_sql_callback(dbh, sql, query_callback, &lua_fun, NULL) == SWITCH_STATUS_SUCCESS) {
|
if (switch_cache_db_execute_sql_callback(dbh, sql, query_callback, &lua_fun, NULL) == SWITCH_STATUS_SUCCESS) {
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -55,12 +55,13 @@ namespace LUA {
|
||||||
class Dbh {
|
class Dbh {
|
||||||
protected:
|
protected:
|
||||||
switch_cache_db_handle_t *dbh;
|
switch_cache_db_handle_t *dbh;
|
||||||
bool connected;
|
bool m_connected;
|
||||||
static int query_callback(void *pArg, int argc, char **argv, char **cargv);
|
static int query_callback(void *pArg, int argc, char **argv, char **cargv);
|
||||||
public:
|
public:
|
||||||
Dbh(char *dsn, char *user = NULL, char *pass = NULL);
|
Dbh(char *dsn, char *user = NULL, char *pass = NULL);
|
||||||
~Dbh();
|
~Dbh();
|
||||||
bool release();
|
bool release();
|
||||||
|
bool connected();
|
||||||
bool query(char *sql, SWIGLUA_FN lua_fun);
|
bool query(char *sql, SWIGLUA_FN lua_fun);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
static int _wrap_Dbh_query(lua_State* L) {
|
||||||
int SWIG_arg = -1;
|
int SWIG_arg = -1;
|
||||||
LUA::Dbh *arg1 = (LUA::Dbh *) 0 ;
|
LUA::Dbh *arg1 = (LUA::Dbh *) 0 ;
|
||||||
|
@ -7277,6 +7302,7 @@ delete arg1;
|
||||||
}
|
}
|
||||||
static swig_lua_method swig_LUA_Dbh_methods[] = {
|
static swig_lua_method swig_LUA_Dbh_methods[] = {
|
||||||
{"release", _wrap_Dbh_release},
|
{"release", _wrap_Dbh_release},
|
||||||
|
{"connected", _wrap_Dbh_connected},
|
||||||
{"query", _wrap_Dbh_query},
|
{"query", _wrap_Dbh_query},
|
||||||
{0,0}
|
{0,0}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue