lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Hi Guys,

Thank you all so much for the response so far.

And yes I use the FreeSWITCH Database Handler (freeswitch.dbh) which allows connection from my lua script.

I can get results fine, its just ensuring as soon as I get a match based on month and  day of month that I break out of the function which is returning the results, as looking at previous freeswitch related posts I have seen;

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))

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" }
So I thought it made sense to go to you Lua guru's to give me some pointers, as the documentation is none existent in terms of how you can control/break out of this function if you were to get a match.

Hope this makes sense!

Thanks again


On Tue, Sep 22, 2015 at 5:15 AM, Alexey Melnichuk <> wrote:

> local todnew_query = string.format("select
> priority,dayofmonth,month,year,dayofmonth from timeofday_new where
> todname='sales' order by priority;")
>                                    assert
> (dbh:query(todnew_query,function(todresult)

> Now with using the function it loops through the rows, in this
> case, priority 1 and 2 rows, but if I match on the first entry with an if statement, such as;

It  hard  to say if you do not say which lib you use. I assume you use
FS.  If  so just return any number > 0. Otherwise read the doc/source.
Or try return different values

С уважением,

Это сообщение проверено на вирусы антивирусом Avast.

Jonathan Hunter
Technical Director /Telephony Developer
M:(+44) 7917 190 438