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

Bote Man bote_radio at botecomm.com
Mon Mar 23 15:05:53 MSK 2015


I’m not much of a programmer, but can’t you specify a format to %f to force it to return 4 decimal places?

 

Or is that not available in Lua?

 

Bote

 

 

From: John Carpenter
Sent: Monday, 23 March, 2015 06:59
Subject: Re: [Freeswitch-users] Problem with LUA dbh:query in Freeswitch

 

Thats it, changed connection to a pgsql:// dsn and I get four decimal places, changed it back to ODBC and back to 3 decimal places. 

Thanks very much, been driving me mad

 

On 23 March 2015 at 10:23, Steven Ayre <steveayre at gmail.com> wrote:

Have you tried a pgsql:// dsn? In case the ODBC driver is having some truncating effect.

 

On 22 March 2015 at 02:06, John Carpenter <carpenter.john at gmail.com> wrote:

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/20150323/b9121929/attachment-0001.html 


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