[Freeswitch-users] strange things with freeswitch.Dbh at FS 1.6

Abaci B abaci64 at gmail.com
Tue Mar 8 21:29:45 MSK 2016


I shortened and changed your function a little, can you try it and se if it
makes a difference?
BTW you can also shorten the set to a single execution by using "multiset"

local dbh = freeswitch.Dbh("name", "root", "passwd")

function get_global_vars()
 local res = {}
 my_query = "select var_name, var_value from directory_global_vars where
domain_id='1'"
 assert(dbh:query(my_query, function(qrow)
  if qrow["var_name"] and qrow["var_value"] then
   table.insert(row, qrow["var_name"] .. "=" .. qrow["var_value"]);
  end))
 return res
end

local row = get_global_vars()

for i in ipairs(row) do
 session:execute("set", "".. row[i] .."")
 freeswitch.consoleLog("NOTICE","row[i]   is '" .. row[i] .. "'\n")
end

On Tue, Mar 8, 2016 at 12:57 PM, Юрий Насида <ynasida at gmail.com> wrote:

> Hi list,
>
> I noted that my old lua script which I used a lot of years from FS 1.2
> works very strange with FS 1.6
>
> The script is quite simple. I am using it for getting the list of
> variables from mysql and set as channel variables. Please look below.
>
> local dbh = freeswitch.Dbh("name", "root", "passwd")
>
> function get_global_vars()
> local row = {}
> local i = 1
> local mycount = 1
>
> my_query = "select var_name, var_value from directory_global_vars where
> domain_id='1'"
>
> assert(dbh:query(my_query, function(qrow)
>
> for key, val in pairs(qrow) do
>   if mycount == 1 then
>   abc = val
>   mycount = 2
>   elseif mycount == 2 then
>   row[i] = abc.."="..val
>   mycount =1
>   i = i+1
>   end
> end
>
> end))
>
> return row
>
> end
>
>
> local row = get_global_vars()
> for k in pairs(row) do
> session:execute("set", "".. row[k] .."")
> freeswitch.consoleLog("NOTICE","row[k]   is '" .. row[k] .. "'\n")
> end
>
>
> The result in fs_cli should looks like
>  switch_cpp.cpp:1356  simplescript start
>  switch_cpp.cpp:1356 row[k]   is *'user_context=default*'
>  switch_cpp.cpp:1356 row[k]   is '*numbering_plan=USCAN*'
>
> BUT sometimes it looks like backwards!
>  switch_cpp.cpp:1356  simplescript start
>  switch_cpp.cpp:1356 row[k]   is '*default=user_context*'
>  switch_cpp.cpp:1356 row[k]   is '*USCAN=numbering_plan*'
>
> Please keep in mind that I do exactly same call without any changes but I
> have different results (its ~ 50%/50%)
>
> I am not sure but it looks like bug.
>
> Please advice.
> Thanks.
>
> _________________________________________________________________________
> Professional FreeSWITCH Consulting Services:
> consulting at freeswitch.org
> http://www.freeswitchsolutions.com
>
> Official FreeSWITCH Sites
> http://www.freeswitch.org
> http://confluence.freeswitch.org
> http://www.cluecon.com
>
> FreeSWITCH-users mailing list
> FreeSWITCH-users at lists.freeswitch.org
> http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
> UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
> http://www.freeswitch.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20160308/81f659f2/attachment-0001.html 


Join us at ClueCon 2016 Aug 8-12, 2016
More information about the FreeSWITCH-users mailing list