[SR-Users] app_lua and sqlops returns error

Daniel-Constantin Mierla miconda at gmail.com
Wed Jun 14 11:44:24 CEST 2017


Hello,


On 14.06.17 11:25, Sebastian Damm wrote:
> 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?
>
>
according to the code, the function is not exported as sql_query(), but
query():

  -
https://github.com/kamailio/kamailio/blob/master/src/modules/app_lua/app_lua_exp.c#L989

With the old export system, everything was done by the developer inside
the app_lua (interpreter module), each deciding the names of exports.
With kemi framework, the name is decided in the exporting module, not in
the interpreter module and the list of exported functions can be seen
via a rpc command:

  -
https://www.kamailio.org/docs/modules/devel/modules/app_lua.html#app_lua.r.api_list

Cheers,
Daniel

-- 
Daniel-Constantin Mierla
www.twitter.com/miconda -- www.linkedin.com/in/miconda
Kamailio Advanced Training - www.asipto.com
Kamailio World Conference - www.kamailioworld.com




More information about the sr-users mailing list