[Freeswitch-users] Problem with LUA dbh:query in Freeswitch

John Carpenter carpenter.john at gmail.com
Sun Mar 22 05:06:28 MSK 2015


I am trying to use Lua to retrieve some currency conversion rates from a
postgres database. It works but the numeric field value is only returning
the first three decimal places although if I list the data in postgres it
has four decimal places. I may be doing something daft as I am quite new to
Lua, sample code is below. Any ideas appreciated

regards, John


 local dbh = freeswitch.Dbh("odbc://fs_odbc:fs_user:password")
if dbh:connected() == false then
 freeswitch.consoleLog("notice", "dp.lua cannot connect to database" .. dsn
.. "\n")
 return
end
assert(dbh:connected())

e_rate = 1.123456789
-- just a test to see decimal places
freeswitch.consoleLog("info",string.format(" e_rate = %f", e_rate))

local function eur2usd()
   local sql = "select eur2usd from currency order by id desc limit 1"
   dbh:query(sql, function(row)
       e_rate = row.eur2usd
       end)
end

local function eur2gbp()
   local sql = "select eur2gbp from currency order by id desc limit 1"
   dbh:query(sql, function(row)
       e_rate = row.eur2gbp
       end)
end

eur2usd()
freeswitch.consoleLog("info",string.format(" euro2usd = %f", e_rate))
eur2gbp()
freeswitch.consoleLog("info",string.format(" euro2gbp = %f", e_rate))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.freeswitch.org/pipermail/freeswitch-users/attachments/20150322/d34921a6/attachment.html 


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