This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

SQL challenge yet again
#7
(20.09.2019, 12:02)Daniel. Wrote: You will have quite a lot of logs there Wink

Yep, I used it during debugging and forgot to remove it :-)

It is no longer there in my live script.

Updated version, now as function so that one can add several ranges to delete. 

Now without extensive logging  Smile
Code:
function deleteGA(start, stop)
    startHG = tonumber(string.split(start, '/')[1])
    startMG = tonumber(string.split(start, '/')[2])
    startUG = tonumber(string.split(start, '/')[3])
    
    startID = (startHG * 2048) + (startMG * 256) + startUG
    
    
    stopHG = tonumber(string.split(stop, '/')[1])
    stopMG = tonumber(string.split(stop, '/')[2])
    stopUG = tonumber(string.split(stop, '/')[3])
    
    stopID = (stopHG * 2048) + (stopMG * 256) + stopUG
    
    if stopID < startID then
      log('Start has higher value than stop. Delete is not possible')
    else
      log('Addresses within range are deleted')
      adresser = db:getall('SELECT address, name FROM objects WHERE ID BETWEEN "' .. startID .. '" AND  "' .. stopID .. '"')
      for _, addr in ipairs(adresser) do
        --log(addr.name)
        grp.delete(addr.name)
      end
    end
end





start = '26/0/0'
stop = '26/0/10'
deleteGA(start, stop)

start = '26/0/51'
stop = '26/0/70'
deleteGA(start, stop)
There are 10 kinds of people in the world; those who can read binary and those who don't  Cool
Reply


Messages In This Thread
SQL challenge yet again - by Trond Hoyem - 16.09.2019, 13:31
RE: SQL challenge yet again - by Daniel - 16.09.2019, 14:25
RE: SQL challenge yet again - by admin - 16.09.2019, 18:50
RE: SQL challenge yet again - by Trond Hoyem - 17.09.2019, 19:43
RE: SQL challenge yet again - by Trond Hoyem - 20.09.2019, 12:00
RE: SQL challenge yet again - by Daniel - 20.09.2019, 12:02
RE: SQL challenge yet again - by Trond Hoyem - 20.09.2019, 12:09
RE: SQL challenge yet again - by Trond Hoyem - 25.09.2019, 06:33

Forum Jump: