Logic Machine Forum
Delete object logs from script - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: Delete object logs from script (/showthread.php?tid=794)



Delete object logs from script - Mirco - 17.05.2017

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

Thanks! Smile


RE: Delete object logs from script - buuuudzik - 17.05.2017

Something like below:
Code:
db:delete('objectlog', { id > -1 })



RE: Delete object logs from script - admin - 18.05.2017

Code:
db:query('DELETE FROM objectlog')



RE: Delete object logs from script - Mirco - 18.05.2017

The istruction returns this error:
Quote:User script:35: attempt to compare number with nil
stack traceback:
User script:35: in main chunk



RE: Delete object logs from script - admin - 18.05.2017

Use the second code example, the first one is incorrect, though it can be used like this:
Code:
db:delete('objectlog')



RE: Delete object logs from script - Mirco - 18.05.2017

Thank you!  Smile


RE: Delete object logs from script - khalil - 25.07.2021

(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?


RE: Delete object logs from script - admin - 26.07.2021

Use this:
Code:
id = buslib.encodega('1/1/1')
db:delete('objectlog', { address = id })



RE: Delete object logs from script - khalil - 26.07.2021

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

Thanks admin


RE: Delete object logs from script - khalil - 01.09.2021

(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,


RE: Delete object logs from script - admin - 01.09.2021

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)



RE: Delete object logs from script - khalil - 01.09.2021

(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?


RE: Delete object logs from script - admin - 01.09.2021

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



RE: Delete object logs from script - khalil - 01.09.2021

(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)


RE: Delete object logs from script - admin - 01.09.2021

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



RE: Delete object logs from script - khalil - 01.09.2021

(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