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

John Carpenter carpenter.john at gmail.com
Mon Mar 23 21:53:34 MSK 2015


Thanks for all the other input but the resolution was to ditch ODBC and use
pgsql// dsn. With ODBC I get 3 decimal places, with pgsql dsb I get the
required 4. I think its a bit faster too.

On 23 March 2015 at 18:40, Abaci B <abaci64 at gmail.com> wrote:

> I'm doing something very similar, this is what I use:
>
> local rate = string.format("%.4f", currency]["rate"])
>
>
> On Mon, Mar 23, 2015 at 8:45 AM, Ítalo Rossi <italorossib at gmail.com>
> wrote:
>
>> Yep, it's available and defaults to 6 decimal places, but looks like it's
>> not a Lua issue...
>>
>> On Mon, Mar 23, 2015 at 9:05 AM, Bote Man <bote_radio at botecomm.com>
>> wrote:
>>
>>> 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))
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> _________________________________________________________________________
>>> 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
>>>
>>
>>
>>
>> --
>> Ítalo Rossi
>>
>> _________________________________________________________________________
>> 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
>>
>
>
> _________________________________________________________________________
> 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/20150323/a4e22a56/attachment-0001.html 


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