Hi,
I'm developing some routing logic with Kamailio 5.0.1 and app_lua. I've integrated my lua script and now I'm trying to use sqlops within the script. I want to use the reconnect stuff of sqlops instead of implementing it by myself.
This is what the Kamailio config looks like: [..] loadmodule "db_mysql.so" loadmodule "sqlops.so" loadmodule "app_lua.so" [..] modparam("sqlops", "sqlcon", "ca=>mysql://kamailio:foobar@127.0.0.1/kamailio")
modparam("app_lua", "reload", 1) modparam("app_lua", "register", "sqlops") modparam("app_lua", "load", "/etc/kamailio/playground.lua")
####### Routing Logic ########
# Main SIP request routing logic request_route { route(everythinginlua); }
onreply_route { route(everythinginlua); }
route[everythinginlua] { if(!lua_run("handle_packet")) { xlog("L_ERR", "SCRIPT: failed to execute lua function!\n"); }
drop; exit; }
The lua script looks like this:
-- Start of script function handle_packet() sr.log("L_INFO", "Got packet method "..sr.pv.get("$rm")) local status = sr.sqlops.sql_query("ca", "SELECT * FROM table", "fooresult") sr.err("sql query returned status "..status) end -- End of script
Now when a packet comes in, I see the following in the log file:
Jun 14 11:19:59 busch /usr/sbin/kamailio[13254]: ERROR: app_lua [app_lua_sr.c:104]: lua_sr_log(): Got packet method REGISTER Jun 14 11:19:59 busch /usr/sbin/kamailio[13254]: ERROR: app_lua [app_lua_api.c:713]: app_lua_run_ex(): error from Lua: /etc/kamailio/playground.lua:4: attempt to call field 'sql_query' (a nil value) Jun 14 11:19:59 busch /usr/sbin/kamailio[13254]: ERROR: app_lua [app_lua_api.c:726]: app_lua_run_ex(): error executing: handle_packet (err: 2) Jun 14 11:19:59 busch /usr/sbin/kamailio[13254]: ERROR: <script>: SCRIPT: failed to execute lua function!
Looks to me as if the functions of sqlops don't get exported to my lua script.
According to the documentation, after specifying the "register" modparam, I should be able to access those functions.
What am I missing?
Thanks in advance Sebastian