mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-03-12 20:27:19 +00:00
FS-9741: lua expose db err str in freeeswitch.dbh
Added 2 methods to lua freeswitch.Dbh `last_error()` Returns the error string from the last query or nil. `clear_error()` clears the error string.
This commit is contained in:
parent
5bed1b0c2d
commit
d3201c6335
@ -90,6 +90,7 @@ class Session : public CoreSession {
|
|||||||
class Dbh {
|
class Dbh {
|
||||||
private:
|
private:
|
||||||
switch_cache_db_handle_t *dbh;
|
switch_cache_db_handle_t *dbh;
|
||||||
|
char *err;
|
||||||
bool m_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:
|
||||||
@ -100,6 +101,8 @@ class Dbh {
|
|||||||
bool test_reactive(char *test_sql, char *drop_sql = NULL, char *reactive_sql = NULL);
|
bool test_reactive(char *test_sql, char *drop_sql = NULL, char *reactive_sql = NULL);
|
||||||
bool query(char *sql, SWIGLUA_FN lua_fun);
|
bool query(char *sql, SWIGLUA_FN lua_fun);
|
||||||
int affected_rows();
|
int affected_rows();
|
||||||
|
char *last_error();
|
||||||
|
void clear_error();
|
||||||
int load_extension(const char *extension);
|
int load_extension(const char *extension);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -354,6 +354,7 @@ switch_status_t Session::run_dtmf_callback(void *input, switch_input_type_t ityp
|
|||||||
Dbh::Dbh(char *dsn, char *user, char *pass)
|
Dbh::Dbh(char *dsn, char *user, char *pass)
|
||||||
{
|
{
|
||||||
dbh = NULL;
|
dbh = NULL;
|
||||||
|
err = NULL;
|
||||||
char *tmp = NULL;
|
char *tmp = NULL;
|
||||||
|
|
||||||
if (!zstr(user) || !zstr(pass)) {
|
if (!zstr(user) || !zstr(pass)) {
|
||||||
@ -380,6 +381,18 @@ Dbh::Dbh(char *dsn, char *user, char *pass)
|
|||||||
Dbh::~Dbh()
|
Dbh::~Dbh()
|
||||||
{
|
{
|
||||||
if (dbh) release();
|
if (dbh) release();
|
||||||
|
|
||||||
|
clear_error();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dbh::clear_error()
|
||||||
|
{
|
||||||
|
switch_safe_free(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
char *Dbh::last_error()
|
||||||
|
{
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dbh::release()
|
bool Dbh::release()
|
||||||
@ -446,6 +459,8 @@ 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)
|
||||||
{
|
{
|
||||||
|
clear_error();
|
||||||
|
|
||||||
if (zstr(sql)) {
|
if (zstr(sql)) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing SQL query.\n");
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Missing SQL query.\n");
|
||||||
return false;
|
return false;
|
||||||
@ -453,17 +468,17 @@ bool Dbh::query(char *sql, SWIGLUA_FN lua_fun)
|
|||||||
|
|
||||||
if (dbh) {
|
if (dbh) {
|
||||||
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, &err) == SWITCH_STATUS_SUCCESS) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else { /* if no lua_fun arg is passed from Lua, an empty initialized struct will be sent - see freeswitch.i */
|
} else { /* if no lua_fun arg is passed from Lua, an empty initialized struct will be sent - see freeswitch.i */
|
||||||
if (switch_cache_db_execute_sql(dbh, sql, NULL) == SWITCH_STATUS_SUCCESS) {
|
if (switch_cache_db_execute_sql(dbh, sql, &err) == SWITCH_STATUS_SUCCESS) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DBH NOT Connected.\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "DBH NOT Connected.\n");
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ namespace LUA {
|
|||||||
class Dbh {
|
class Dbh {
|
||||||
protected:
|
protected:
|
||||||
switch_cache_db_handle_t *dbh;
|
switch_cache_db_handle_t *dbh;
|
||||||
|
char *err;
|
||||||
bool m_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:
|
||||||
@ -68,6 +69,8 @@ namespace LUA {
|
|||||||
bool test_reactive(char *test_sql, char *drop_sql = NULL, char *reactive_sql = NULL);
|
bool test_reactive(char *test_sql, char *drop_sql = NULL, char *reactive_sql = NULL);
|
||||||
bool query(char *sql, SWIGLUA_FN lua_fun);
|
bool query(char *sql, SWIGLUA_FN lua_fun);
|
||||||
int affected_rows();
|
int affected_rows();
|
||||||
|
char *last_error();
|
||||||
|
void clear_error();
|
||||||
int load_extension(const char *extension);
|
int load_extension(const char *extension);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -8263,6 +8263,53 @@ fail:
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int _wrap_Dbh_last_error(lua_State* L) {
|
||||||
|
int SWIG_arg = 0;
|
||||||
|
LUA::Dbh *arg1 = (LUA::Dbh *) 0 ;
|
||||||
|
char *result = 0 ;
|
||||||
|
|
||||||
|
SWIG_check_num_args("LUA::Dbh::last_error",1,1)
|
||||||
|
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("LUA::Dbh::last_error",1,"LUA::Dbh *");
|
||||||
|
|
||||||
|
if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_LUA__Dbh,0))){
|
||||||
|
SWIG_fail_ptr("Dbh_last_error",1,SWIGTYPE_p_LUA__Dbh);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = (char *)(arg1)->last_error();
|
||||||
|
lua_pushstring(L,(const char *)result); SWIG_arg++;
|
||||||
|
return SWIG_arg;
|
||||||
|
|
||||||
|
if(0) SWIG_fail;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
lua_error(L);
|
||||||
|
return SWIG_arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int _wrap_Dbh_clear_error(lua_State* L) {
|
||||||
|
int SWIG_arg = 0;
|
||||||
|
LUA::Dbh *arg1 = (LUA::Dbh *) 0 ;
|
||||||
|
|
||||||
|
SWIG_check_num_args("LUA::Dbh::clear_error",1,1)
|
||||||
|
if(!SWIG_isptrtype(L,1)) SWIG_fail_arg("LUA::Dbh::clear_error",1,"LUA::Dbh *");
|
||||||
|
|
||||||
|
if (!SWIG_IsOK(SWIG_ConvertPtr(L,1,(void**)&arg1,SWIGTYPE_p_LUA__Dbh,0))){
|
||||||
|
SWIG_fail_ptr("Dbh_clear_error",1,SWIGTYPE_p_LUA__Dbh);
|
||||||
|
}
|
||||||
|
|
||||||
|
(arg1)->clear_error();
|
||||||
|
|
||||||
|
return SWIG_arg;
|
||||||
|
|
||||||
|
if(0) SWIG_fail;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
lua_error(L);
|
||||||
|
return SWIG_arg;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static int _wrap_Dbh_load_extension(lua_State* L) {
|
static int _wrap_Dbh_load_extension(lua_State* L) {
|
||||||
int SWIG_arg = 0;
|
int SWIG_arg = 0;
|
||||||
LUA::Dbh *arg1 = (LUA::Dbh *) 0 ;
|
LUA::Dbh *arg1 = (LUA::Dbh *) 0 ;
|
||||||
@ -8300,6 +8347,8 @@ static swig_lua_method swig_LUA_Dbh_methods[] = {
|
|||||||
{"test_reactive", _wrap_Dbh_test_reactive},
|
{"test_reactive", _wrap_Dbh_test_reactive},
|
||||||
{"query", _wrap_Dbh_query},
|
{"query", _wrap_Dbh_query},
|
||||||
{"affected_rows", _wrap_Dbh_affected_rows},
|
{"affected_rows", _wrap_Dbh_affected_rows},
|
||||||
|
{"last_error", _wrap_Dbh_last_error},
|
||||||
|
{"clear_error", _wrap_Dbh_clear_error},
|
||||||
{"load_extension", _wrap_Dbh_load_extension},
|
{"load_extension", _wrap_Dbh_load_extension},
|
||||||
{0,0}
|
{0,0}
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user