<div dir="ltr">Hi,<div><br></div><div>but take care, the freeswitch.dbh and either the 3rd party lua mysql support prepared statements. So you should be check for sql-injections via SIP.</div><div><br></div><div>Thats why i use lua-dbi. It supports prepared statements.</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014/1/11 Sanath Prasanna <span dir="ltr">&lt;<a href="mailto:ahe.sanath@gmail.com" target="_blank">ahe.sanath@gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr"><div>Only Suggestion:  You can use dbh to get data from mysql. You need to configure ODBC settings then.</div><div><br></div><div>Sample one:</div><div>db_con = set_db_connection();<br></div><div><div>function set_db_connection()</div>

<div><span style="white-space:pre-wrap">        </span>dbh = freeswitch.Dbh(&quot;freeswitch_odbc&quot;, &quot;testusername&quot;, &quot;testpw&quot;);</div><div><span style="white-space:pre-wrap">        </span>if dbh:connected() == false then</div>

<div><span style="white-space:pre-wrap">                </span>return false;</div><div><span style="white-space:pre-wrap">        </span>else</div><div><span style="white-space:pre-wrap">                </span>return true;</div><div><span style="white-space:pre-wrap">        </span>end</div>

<div>end</div></div><div><br></div><div><br></div><div><div>function get_susb_data(old_no, pin_no)</div><div><span style="white-space:pre-wrap">        </span>language = false ;</div><div><span style="white-space:pre-wrap">        </span>my_query = &quot;SELECT name * FROM subscriber;</div>

<div><span style="white-space:pre-wrap">        </span>dbh:query(my_query, function(qrow)<span style="white-space:pre-wrap">        </span> </div><div><span style="white-space:pre-wrap">                </span>name = <a href="http://qrow.name" target="_blank">qrow.name</a>;</div>

<div><span style="white-space:pre-wrap">                                </span><br></div><div>    end);    </div><div>    --logInfo(&quot; name:&quot; .. name); </div><div>end<br></div></div><div><br></div><div><a href="http://wiki.freeswitch.org/wiki/Using_ODBC_in_the_core" target="_blank">http://wiki.freeswitch.org/wiki/Using_ODBC_in_the_core</a><br>

</div><div><br></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 10, 2014 at 10:13 PM, KPS Maillinglist <span dir="ltr">&lt;<a href="mailto:ksims.ml@gmail.com" target="_blank">ksims.ml@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">I placed the line in my script and the path in which the file lives is in fact in the modules path.<div>

<br></div><div>2014-01-10 04:37:31.872812 [INFO] switch_cpp.cpp:1293 package.path /usr/local/share/lua/5.2/?.lua;/usr/local/share/lua/5.2/?/init.lua;/usr/local/lib/lua/5.2/?.lua;/usr/local/lib/lua/5.2/?/init.lua;./?.luapackage.cpath /usr/local/lib/lua/5.2/?.so;/usr/local/lib/lua/5.2/loadall.so;./?.so<br>


</div></div><div><div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Jan 10, 2014 at 7:19 AM, Karsten Horsmann <span dir="ltr">&lt;<a href="mailto:khorsmann@gmail.com" target="_blank">khorsmann@gmail.com</a>&gt;</span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi,<div><br></div><div>are you sure that the lua-path enviroment?<br><br><a href="https://wiki.freeswitch.org/wiki/Mod_lua#Where_do_I_put_3rd_party_Lua_scripts.2Fmodules.3F" target="_blank">https://wiki.freeswitch.org/wiki/Mod_lua#Where_do_I_put_3rd_party_Lua_scripts.2Fmodules.3F</a><br>



<br>For debugging you could <br><br><font face="courier new, monospace">freeswitch.consoleLog(INFO, &quot;package.path &quot;.. package.path .. &quot;package.cpath &quot; .. package.cpath )</font><br><br>In my lua 5.1 FS 1.2.x Lua scripts in include my 3rd party libaries like this:<br>



<br><div><font face="courier new, monospace">-- include the DBI script and the DBI Module Paths</font></div><div><font face="courier new, monospace">package.path = package.path .. &quot;;/usr/share/lua/5.1/?.lua&quot;</font></div>



<div><font face="courier new, monospace">package.cpath = package.cpath .. &quot;;/usr/lib64/lua/5.1/?.so&quot;</font></div><div><span style="font-family:&#39;courier new&#39;,monospace">-- mysql Config</span><br></div><div>



<font face="courier new, monospace">require (&#39;DBI&#39;)</font></div></div><div><br></div><div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014/1/9 KPS Maillinglist <span dir="ltr">&lt;<a href="mailto:ksims.ml@gmail.com" target="_blank">ksims.ml@gmail.com</a>&gt;</span><br>



<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div><div dir="ltr"><div>I&#39;m wriiting because I can&#39;t seem to get Lua from within Freeswitch to load the luasql mysql object. The error on the freeswitch console states that there&#39;s a error loading module luasql.mysql&#39; but when i run a script from the shell requiring the same file it works just fine. I did due diligience and researched the issue and seen someone state the proble is due to lua being compiled from C++ code and the mysql module being compiled from C source code. Any help will be greatly appreciated because none of my scripts work because they are all database driven.</div>




<div><br></div><div>FS Cli error:</div><div>#########################</div><div><div>2014-01-09 05:36:31.432815 [ERR] mod_lua.cpp:199 error loading module &#39;luasql.mysql&#39; from file &#39;/usr/local/lib/lua/5.2/luasql/mysql.so&#39;:</div>




<div>        /usr/local/lib/lua/5.2/luasql/mysql.so: undefined symbol: lua_getfield</div><div>stack traceback:</div><div>        [C]: in ?</div><div>        [C]: in function &#39;require&#39;</div><div>        /cdi/fs157/scripts/cdi_scripts/cdi_main_start.lua:2: in main chunk</div>




</div><div><br></div><div><br></div><div>First few lines of the script in question:</div><div>################################</div><div><div>#!/usr/bin/lua</div><div>require &quot;luasql.mysql&quot;</div><div>-- I also tried to call module like statement below</div>




<div>-- luasql = require &quot;luasql.mysql&quot;</div><div>fs_api = freeswitch.API();</div><div><br></div><div>dofile &quot;/cdi/cdi_scripts/vars.lua&quot;</div><div>dofile &quot;/cdi/cdi_scripts/maininclude.lua&quot;</div>




</div><div><br></div><div>Shell test script that works</div><div>#######################################</div><div><div>#!/usr/bin/lua</div><div>luasql = require &quot;luasql.mysql&quot;</div><div><br></div><div>env = assert (luasql.mysql())</div>




<div>con = assert (env:connect(&quot;database&quot;,&quot;username&quot;,&quot;password&quot;,&quot;162.21X.XXX.144&quot;))</div><div>cur = assert (con:execute&quot;SELECT * FROM xxx_acct_did&quot;)</div><div>row = cur:fetch ({}, &quot;a&quot;)</div>




<div><br></div><div>while true  do end</div><div>while row do</div><div><br></div><div>print(string.format(&quot;DID: %s, Route: %s&quot;, row.did, row.route))</div><div>  row = cur:fetch (row, &quot;a&quot;)</div><div>end</div>




<div>cur:close()</div><div>con:close()</div></div><div><br></div><div>Output of the script above:</div><div>###################################</div><div><div>DID: <a href="tel:18155516741" value="+18155516741" target="_blank">18155516741</a>, Route: <a href="http://8171111741@108.111.175.183:5066" target="_blank">8171111741@108.111.175.183:5066</a></div>




<div>DID: <a href="tel:19755514964" value="+19755514964" target="_blank">19755514964</a>, Route: <a href="http://9721111964@173.111.252.22:5066" target="_blank">9721111964@173.111.252.22:5066</a></div><div>DID: <a href="tel:19155515245" value="+19155515245" target="_blank">19155515245</a>, Route: <a href="mailto:9171111245@150.111.194.215" target="_blank">9171111245@150.111.194.215</a></div>




<div>DID: <a href="tel:19755516483" value="+19755516483" target="_blank">19755516483</a>, Route: <a href="http://9721111483@173.111.252.22:5066" target="_blank">9721111483@173.111.252.22:5066</a></div><div>DID: <a href="tel:12155516793" value="+12155516793" target="_blank">12155516793</a>, Route: <a href="http://2141111793@108.111.175.183:5066" target="_blank">2141111793@108.111.175.183:5066</a></div>




<div>DID: 18755519608, Route: <a href="http://8771111608@173.111.252.22:5066" target="_blank">8771111608@173.111.252.22:5066</a></div><div>DID: <a href="tel:18655518946" value="+18655518946" target="_blank">18655518946</a>, Route: <a href="http://8771111608@192.111.146.243:5199" target="_blank">8771111608@192.111.146.243:5199</a></div>




<div>DID: <a href="tel:19755517847" value="+19755517847" target="_blank">19755517847</a>, Route: <a href="http://8171111741@108.111.175.183:5066" target="_blank">8171111741@108.111.175.183:5066</a></div><div>DID: <a href="tel:15155510762" value="+15155510762" target="_blank">15155510762</a>, Route: <a href="http://5101111762@173.111.252.22:5066" target="_blank">5101111762@173.111.252.22:5066</a></div>




<div>DID: 14655512043, Route: <a href="http://4691111043@173.111.252.22:5066" target="_blank">4691111043@173.111.252.22:5066</a></div><div>DID: <a href="tel:16155519638" value="+16155519638" target="_blank">16155519638</a>, Route: <a href="http://6191111638@173.111.252.22:5066" target="_blank">6191111638@173.111.252.22:5066</a></div>




<div>DID: 14655512044, Route: <a href="http://4691111044@173.111.252.22:5066" target="_blank">4691111044@173.111.252.22:5066</a></div><div>DID: 18755511623, Route: <a href="http://8171111741@173.111.252.22:5066" target="_blank">8171111741@173.111.252.22:5066</a></div>




<div>DID: 18755511624, Route: <a href="http://8771111608@199.111.249.94:5199" target="_blank">8771111608@199.111.249.94:5199</a></div><div>DID: <a href="tel:19725550001" value="+19725550001" target="_blank">19725550001</a>, Route: <a href="http://9721111001@173.111.252.22:5066" target="_blank">9721111001@173.111.252.22:5066</a></div>




<div>DID: <a href="tel:16305512270" value="+16305512270" target="_blank">16305512270</a>, Route: <a href="http://8171111741@108.111.175.183:5066" target="_blank">8171111741@108.111.175.183:5066</a></div><div>DID: <a href="tel:14695512042" value="+14695512042" target="_blank">14695512042</a>, Route: <a href="http://8171111741@162.111.160.145:5066" target="_blank">8171111741@162.111.160.145:5066</a></div>




</div><div><br></div><div>luasql file path:</div><div>###############################################</div><div><br></div><div><div>[root@rch-vmli ~]# ls -larth /usr/local/lib/lua/5.2/luasql/mysql.so</div><div>-rwxr-xr-x 1 root root 18K Jan  6 10:35 /usr/local/lib/lua/5.2/luasql/mysql.so</div>




</div><div><br></div><div><br></div><div>FS Info:</div><div>######################################</div><div>FreeSWITCH Version 1.5.8b+git~20140106T145044Z~8d30da28d7~32bi<br></div><div>Lua version 5.2.2</div></div>
<br></div></div>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.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://wiki.freeswitch.org" target="_blank">http://wiki.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" target="_blank">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>
<br></blockquote></div><span><font color="#888888"><br><br clear="all"><div><br></div>-- <br>Mit freundlichen Grüßen<br>*Karsten Horsmann*<br>
</font></span></div>
<br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.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://wiki.freeswitch.org" target="_blank">http://wiki.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" target="_blank">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>
<br></blockquote></div><br></div>
</div></div><br>_________________________________________________________________________<br>
Professional FreeSWITCH Consulting Services:<br>
<a href="mailto:consulting@freeswitch.org" target="_blank">consulting@freeswitch.org</a><br>
<a href="http://www.freeswitchsolutions.com" target="_blank">http://www.freeswitchsolutions.com</a><br>
<br>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.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://wiki.freeswitch.org" target="_blank">http://wiki.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" target="_blank">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>
<br></blockquote></div><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>
FreeSWITCH-powered IP PBX: The CudaTel Communication Server<br>
<a href="http://www.cudatel.com" target="_blank">http://www.cudatel.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://wiki.freeswitch.org" target="_blank">http://wiki.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>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Mit freundlichen Grüßen<br>*Karsten Horsmann*<br>
</div>