VoIP Mailing List Archives
Mailing list archives for the VoIP community |
|
View previous topic :: View next topic |
Author |
Message |
ynasida at gmail.com Guest
|
Posted: Tue Mar 08, 2016 12:59 pm Post subject: [Freeswitch-users] strange things with freeswitch.Dbh at FS |
|
|
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. |
|
Back to top |
|
|
abaci64 at gmail.com Guest
|
Posted: Tue Mar 08, 2016 1:31 pm Post subject: [Freeswitch-users] strange things with freeswitch.Dbh at FS |
|
|
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@gmail.com (ynasida@gmail.com)> wrote:
Quote: | 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@freeswitch.org (consulting@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
|
|
|
Back to top |
|
|
ynasida at gmail.com Guest
|
Posted: Tue Mar 08, 2016 2:16 pm Post subject: [Freeswitch-users] strange things with freeswitch.Dbh at FS |
|
|
Wow! Nice trick, thanks a lot
It works great but I am still a bit wonder why my script worked fine with old version of FS.
2016-03-08 21:29 GMT+03:00 Abaci B <abaci64@gmail.com (abaci64@gmail.com)>:
Quote: | 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@gmail.com (ynasida@gmail.com)> wrote:
Quote: | 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@freeswitch.org (consulting@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
|
_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@freeswitch.org (consulting@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
|
|
|
Back to top |
|
|
abaci64 at gmail.com Guest
|
Posted: Tue Mar 08, 2016 2:30 pm Post subject: [Freeswitch-users] strange things with freeswitch.Dbh at FS |
|
|
Just a guess, maybe you have a null value (for either var_name or var_value) and your mycount becomes unreliable, didn't check lately how freeswitch.Dbh handles null values.
On Tue, Mar 8, 2016 at 2:14 PM, Юрий Насида <ynasida@gmail.com (ynasida@gmail.com)> wrote:
Quote: | Wow! Nice trick, thanks a lot
It works great but I am still a bit wonder why my script worked fine with old version of FS.
2016-03-08 21:29 GMT+03:00 Abaci B <abaci64@gmail.com (abaci64@gmail.com)>:
Quote: | 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@gmail.com (ynasida@gmail.com)> wrote:
Quote: | 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@freeswitch.org (consulting@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
|
_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@freeswitch.org (consulting@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
|
_________________________________________________________________________
Professional FreeSWITCH Consulting Services:
consulting@freeswitch.org (consulting@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@lists.freeswitch.org (FreeSWITCH-users@lists.freeswitch.org)
http://lists.freeswitch.org/mailman/listinfo/freeswitch-users
UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users
http://www.freeswitch.org
|
|
|
Back to top |
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|