<div dir="ltr">Have you tried a pgsql:// dsn? In case the ODBC driver is having some truncating effect.</div><div class="gmail_extra"><br><div class="gmail_quote">On 22 March 2015 at 02:06, John Carpenter <span dir="ltr"><<a href="mailto:carpenter.john@gmail.com" target="_blank">carpenter.john@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div>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<br><br></div>regards, John<br><div><br>
<div>
<span style="font-family:monospace"><span style="font-weight:bold;color:rgb(255,255,84);background-color:rgb(255,255,255)"><br></span></span>
<div>
<span style="color:rgb(0,0,0)"><span style="background-color:rgb(243,243,243)"><span style="font-family:monospace,monospace"><span style="font-weight:bold">local</span> dbh = freeswitch.Dbh(<span style="font-weight:bold">"odbc://fs_odbc:fs_user:password"</span>)
<br><span style="font-weight:bold">if</span> dbh:connected() == <span style="font-weight:bold">false</span> <span style="font-weight:bold">then</span>
<br> freeswitch.consoleLog(<span style="font-weight:bold">"notice"</span>, <span style="font-weight:bold">"dp.lua cannot connect to database"</span> .. dsn .. <span style="font-weight:bold">"</span><span style="font-weight:bold">\n</span><span style="font-weight:bold">"</span>)
<br> <span style="font-weight:bold">return</span>
<br><span style="font-weight:bold">end</span>
<br><span style="font-weight:bold">assert</span>(dbh:connected())
<br>
<br>e_rate = <span style="font-weight:bold">1.123456789</span>
<br><span style="font-weight:bold">-- just a test</span>
to see decimal places<br>freeswitch.consoleLog(<span style="font-weight:bold">"info"</span>,<span style="font-weight:bold">string.format</span>(<span style="font-weight:bold">" e_rate = %f"</span>, e_rate))
<br>
<br><span style="font-weight:bold">local</span> <span style="font-weight:bold">function</span> eur2usd()
<br> <span style="font-weight:bold">local</span> sql = <span style="font-weight:bold">"select eur2usd from currency order by id desc limit 1"</span>
<br> dbh:query(sql, <span style="font-weight:bold">function</span>(row)
<br> e_rate = row.eur2usd
<br> <span style="font-weight:bold">end</span>)
<br><span style="font-weight:bold">end</span>
<span></span><br>
<br><span style="font-weight:bold">local</span> <span style="font-weight:bold">function</span> eur2gbp()
<br> <span style="font-weight:bold">local</span> sql = <span style="font-weight:bold">"select eur2gbp from currency order by id desc limit 1"</span>
<br> dbh:query(sql, <span style="font-weight:bold">function</span>(row)
<br> e_rate = row.eur2gbp
<br> <span style="font-weight:bold">end</span>)
<br><span style="font-weight:bold">end</span>
<br>
<br>eur2usd()
<br>freeswitch.consoleLog(<span style="font-weight:bold">"info"</span>,<span style="font-weight:bold">string.format</span>(<span style="font-weight:bold">" euro2usd = %f"</span>, e_rate))
<br>eur2gbp()
<br>freeswitch.consoleLog(<span style="font-weight:bold">"info"</span>,<span style="font-weight:bold">string.format</span>(<span style="font-weight:bold">" euro2gbp = %f"</span>, e_rate))<br></span></span></span></div><span style="color:rgb(0,0,0)"><span style="background-color:rgb(243,243,243)"><span style="font-family:monospace,monospace">
</span></span></span><br></div>
</div></div>
<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
Official FreeSWITCH Sites<br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br>
<a href="http://confluence.freeswitch.org" target="_blank">http://confluence.freeswitch.org</a><br>
<a href="http://www.cluecon.com" target="_blank">http://www.cluecon.com</a><br>
<br>
FreeSWITCH-users mailing list<br>
<a href="mailto:FreeSWITCH-users@lists.freeswitch.org">FreeSWITCH-users@lists.freeswitch.org</a><br>
<a href="http://lists.freeswitch.org/mailman/listinfo/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/listinfo/freeswitch-users</a><br>
UNSUBSCRIBE:<a href="http://lists.freeswitch.org/mailman/options/freeswitch-users" target="_blank">http://lists.freeswitch.org/mailman/options/freeswitch-users</a><br>
<a href="http://www.freeswitch.org" target="_blank">http://www.freeswitch.org</a><br></blockquote></div><br></div>