lua-users home
lua-l archive

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


Hi Guys,

Im quite new to Lua and Im having an issue with extracting particular data where there a multiple rows in a database I want to deal with so was wondering if someone could help?

Basically using a function, Im extracting data from a Mysql table that has multiple rows, and its looping through the rows as expected.

Now I have setup a number of entries for Time of day and I want to stop the loop (exit it) as soon as there is a match, and Id like to know how to achieve this.

Basically I want to perform a query such as;

select priority,dayofmonth,month,year,dayofmonth from timeofday_new where todname='sales' order by priority;
+----------+------------+-------+------+------------+
| priority | dayofmonth | month | year | dayofmonth |
+----------+------------+-------+------+------------+
|        1 | 20         | 9     | 2015 | 20         |
|        2 | 14-17      | 9     | 2015 | 14-17      |


And Im doing this using;




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;


--------------------------------------------------
--------------------------------------------------------------------------------
---If year and month match, send to freeswitch.
local t = os.date("*t");
if (tostring(todresult.year) == tostring(t.year) and tostring(todresult.month) == tostring(t.month)) then
       freeswitch.consoleLog("notice","Year and Month Match, next step is day of month\n")
    if (tostring(todresult.dayofmonth) == tostring(t.day)) then
         .....Exit here sending data.
      end
       
end
------------------------------------------------------------------------------
---End of loop to send all TOD options
end))

I want it to exit the loop/function on true and not return any of the other entries,so in affect matches on first priority entry and stops there.

Can this be done with the way Im trying to loop through multiple rows in a database table?

Many thanks

Jon