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.

Delete object logs from script
#1
Hi, is there a way to delete all object logs from a script?

Thanks! Smile
Reply
#2
Something like below:
Code:
db:delete('objectlog', { id > -1 })
Reply
#3
Code:
db:query('DELETE FROM objectlog')
Reply
#4
The istruction returns this error:
Quote:User script:35: attempt to compare number with nil
stack traceback:
User script:35: in main chunk
Reply
#5
Use the second code example, the first one is incorrect, though it can be used like this:
Code:
db:delete('objectlog')
Reply
#6
Thank you!  Smile
Reply
#7
(18.05.2017, 07:38)admin Wrote: Use the second code example, the first one is incorrect, though it can be used like this:
Code:
db:delete('objectlog')

Hello Admin
how to delete a specific object address logs?
Best Regards,
Reply
#8
Use this:
Code:
id = buslib.encodega('1/1/1')
db:delete('objectlog', { address = id })
Reply
#9
(26.07.2021, 10:16)admin Wrote: Use this:
Code:
id = buslib.encodega('1/1/1')
db:delete('objectlog', { address = id })

Thanks admin
Best Regards,
Reply
#10
(26.07.2021, 10:16)admin Wrote: Use this:
Code:
id = buslib.encodega('1/1/1')
db:delete('objectlog', { address = id })

hello admin
How to delete a specific period for a specific address
regards,
Best Regards,
Reply
#11
Like this, you need to specify the min/max log time as UNIX timestamp:
Code:
id = buslib.encodega('1/1/1')
mintime = os.time() - 3600 * 2
maxtime = os.time() - 3600
db:query('DELETE FROM objectlog WHERE address=? AND logtime BETWEEN ? AND ?', id, mintime, maxtime)
Reply
#12
(01.09.2021, 09:13)admin Wrote: Like this, you need to specify the min/max log time as UNIX timestamp:
Code:
id = buslib.encodega('1/1/1')
mintime = os.time() - 3600 * 2
maxtime = os.time() - 3600
db:query('DELETE FROM objectlog WHERE address=? AND logtime BETWEEN ? AND ?', id, mintime, maxtime)

thank you, admin
great 
where to learn about these query command?
like if I want it to be depend on value


db:query('DELETE FROM objectlog WHERE value<=0')

doese this work?
Best Regards,
Reply
#13
It's more complicated. Value is stored raw format so it has to be decoded before comparison.
Code:
obj = grp.find('1/1/1')
rows = db:getall('SELECT * FROM objectlog WHERE address=?', obj.id)

for _, row in ipairs(rows) do
  if row.datahex then
    value = busdatatype.decode(row.datahex, obj.datatype)

    if value <= 0 then
      db:delete('objectlog', { id = row.id })
    end
  end
end
Reply
#14
(01.09.2021, 12:08)admin Wrote: It's more complicated. Value is stored raw format so it has to be decoded before comparison.
Code:
obj = grp.find('1/1/1')
rows = db:getall('SELECT * FROM objectlog WHERE address=?', obj.id)

for _, row in ipairs(rows) do
  if row.datahex then
    value = busdatatype.decode(row.datahex, obj.datatype)

    if value <= 0 then
      db:delete('objectlog', { id = row.id })
    end
  end
end
thank you admin
is it easy to make it in general (delete all obj. logs <=0)
Best Regards,
Reply
#15
Try this:
Code:
rows = db:getall([[
  SELECT ol.id, ol.datahex, o.datatype
  FROM objectlog ol
  JOIN objects o ON ol.address=o.id
]])

for _, row in ipairs(rows) do
  if row.datahex then
    value = busdatatype.decode(row.datahex, row.datatype)

    if type(value) == 'number' and value <= 0 then
      db:delete('objectlog', { id = row.id })
    end
  end
end
Reply
#16
(01.09.2021, 12:37)admin Wrote: Try this:
Code:
rows = db:getall([[
  SELECT ol.id, ol.datahex, o.datatype
  FROM objectlog ol
  JOIN objects o ON ol.address=o.id
]])

for _, row in ipairs(rows) do
  if row.datahex then
    value = busdatatype.decode(row.datahex, row.datatype)

    if type(value) == 'number' and value <= 0 then
      db:delete('objectlog', { id = row.id })
    end
  end
end

thank you very much 
appreciate your help
Best Regards,
Reply


Forum Jump: