What I need is to create a table with all objects within a certain address range. I am already able to calculate the start and stop ID from the address table, but when I try to look it up with the SQL, I am not as successful.
The code I am using is;
Code:
12
adresser = db:getall('SELECT ID FROM objects WHERE ID >= "%' .. startID .. '%" AND ID <= "%' .. stopID .. '%"')
log(adresser)
The log gives an empty table.
Any hints as to what I am doing wrong?
There are 10 kinds of people in the world; those who can read binary and those who don't
Hi
I'm not sure what is your end game here but you can take an idea from this script how to grab range of objects from DB and do some action on them.
This script will create tags on object based on the range and the separators selected and the object name.
You can use ? placeholders which are replaced by additional arguments passed to getall(). This will properly escape values to prevent SQL injections when parameters come from external sources. There's also SQL BETWEEN operator which is more readable than two comparisons.
Code:
1
adresser = db:getall('SELECT id FROM objects WHERE id BETWEEN ? AND ?', startID, stopID)
I have not been at the project today, so not been able to test anything, but will have a look at this.
@Daniel; what I want to do is to delete a range of objects from the SL by script. The reason is that in a project I have 30 SpaceLYnks as BACnet GW, and I only want a certain range of group addresses on each SL. But I also do not want to edit the ESF-file before importing it to the different SL's, but simply have a script that removes the surplus objects once a day or something.
There are 10 kinds of people in the world; those who can read binary and those who don't
20.09.2019, 19:40 (This post was last modified: 20.09.2019, 19:55 by Erwin van der Zwart.)
Hi,
Here is a simplified version (:
Code:
12345678910111213
functiondeleteGA(start, stop)
startID = knxlib.encodega(start)
stopID = knxlib.encodega(stop)
ifstopID < startIDthenlog('Start has higher value than stop. Delete is not possible')
elseresult = db:query('DELETE FROM objects WHERE ID BETWEEN ? AND ?', startID, stopID)
log(result .. ' address(es) within range is/are deleted')
endenddeleteGA('26/0/0', '26/0/10')
deleteGA('26/0/51', '26/0/70')
functiondeleteGA(start, stop)
startID = knxlib.encodega(start)
stopID = knxlib.encodega(stop)
ifstopID < startIDthenlog('Start has higher value than stop. Delete is not possible')
elseresult = db:query('DELETE FROM objects WHERE ID BETWEEN ? AND ?', startID, stopID)
log(result .. ' address(es) within range is/are deleted')
endenddeleteGA('26/0/0', '26/0/10')
deleteGA('26/0/51', '26/0/70')
BR,
Erwin
OK, that is a little more elegant.
Is there any place where one can find all these commands that are used for LM/SL? Like knxlib.encodega()? That would be really helpful to have a list of those, like we have already for the lua commands (https://openrb.com/docs/lua.htm).
There are 10 kinds of people in the world; those who can read binary and those who don't
I don't have a list, this is a command that is used in a lot of samples on this site, that is also where i got the info, when i see a new command like knxlib i usually log it log(knxlib) to see the included sub functions.