Lua and dbh:query returning multiple rows
Could you demonstrate how to iterate through multiple returned rows in Lua from the function Dbh:query?
Actually, I'm trying to consume two sets of return data, rather than rows. This is a technique we're familiar with on Microsoft platforms but maybe not something to be expected with FreeTDS/unixODBC/freeswitch.Dbh. Just wondering if maybe someone else had resolved a similar problem? On Tue, Nov 23, 2010 at 4:11 PM, elijah <elijah@crankenstein.com> wrote:
Could you demonstrate how to iterate through multiple returned rows in Lua from the function Dbh:query?
Hello Elijah, Can you please explain how multiple sets of data should work ? I'm only familiar with getting one set of data. Kind regards, Leon On Nov 24, 2010, at 9:30 PM, elijah wrote:
Actually, I'm trying to consume two sets of return data, rather than rows. This is a technique we're familiar with on Microsoft platforms but maybe not something to be expected with FreeTDS/unixODBC/ freeswitch.Dbh. Just wondering if maybe someone else had resolved a similar problem?
On Tue, Nov 23, 2010 at 4:11 PM, elijah <elijah@crankenstein.com> wrote: Could you demonstrate how to iterate through multiple returned rows in Lua from the function Dbh:query?
_______________________________________________ FreeSWITCH-users mailing list FreeSWITCH-users@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
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@lists.freeswitch.org http://lists.freeswitch.org/mailman/listinfo/freeswitch-users UNSUBSCRIBE:http://lists.freeswitch.org/mailman/options/freeswitch-users http://www.freeswitch.org
participants (2)
-
elijah
-
Leon de Rooij