lua-users home
lua-l archive

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

Hi Tomas,

Thank you and the other guys so much, that works a treat!!

Many thanks guys :)


ation of the loop.
    Syntax of each row is: { ["column_name_1"] = "value_1", ["column_name_2"] = "value_2" }.
    If you (optionally) return a number other than 0 from the callback-function, you'll break the loop.

Note the last line.  As Alexey already told, it seems that you can return "a number other than 0" to break the loop.  In that case you should change your function:

assert (dbh:query(todnew_query,function(todresult)
       if (tostring(todresult.dayofmonth) == tostring( then
         freeswitch.consoleLog("notice","This entry matches on Day of month
          --return     <<---tried return or break here, is this correct?
          return 1    <<--- try returning a number other than 0 here


On 2015-09-22 04:50, Jonathan Hunter wrote:
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 : %sn", 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
todname='sales' order by priority;")

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
FS. If so just return any number > 0. Otherwise read the
Or try return different values

С уважением,

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


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


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