[Freeswitch-users] Lua and dbh:query returning multiple rows
Leon de Rooij
leon at scarlet-internet.nl
Thu Nov 25 01:41:20 PST 2010
Hello Elijah,
You can pass a function as second argument to dbh:query, like so:
dbh = freeswitch.Dbh(odbc_dsn, odbc_user, odbc_pass)
dbh:query("select * from some_table", function(row) -- here it
loops through all rows
for key, val in pairs(row) do -- here it
loops through all columns
stream:write(string.format("%25s : %s\n", key, val))
end
stream:write("\n")
end))
This will run the anonymous function for each row, where each
iteration of the function will be passed a row in the form of a table.
Each row (table) will have the following syntax:
{ ["column_name_1"] = "row_value_1", ["column_name_2" = "row_value_2" }
There's more info here:
http://wiki.freeswitch.org/wiki/Mod_lua#freeswitch.Dbh
and here:
http://wiki.freeswitch.org/wiki/Lua_freeswitch_dbh
kind regards,
Leon
On Nov 24, 2010, at 1:11 AM, elijah wrote:
> Could you demonstrate how to iterate through multiple returned rows
> in Lua from the function Dbh:query?
>
> _______________________________________________
> 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/20101125/6a8430db/attachment.html
More information about the FreeSWITCH-users
mailing list