08.06.2021, 08:39
(08.06.2021, 06:49)admin Wrote: Use this to delete the storage entry:Where is the mistake?
Code:storage.delete('MyPowerLog')
i read data from my table, prepare csv header, look for data in my table and for each row i would like to add them to csv file, but nothing i have only headers.
Code:
--date.day, date.hour, date.min, date.sec = 1, 0, 0, 0
--ts_start = os.time(date)
--date.month = date.month + 1
--ts_end = os.time(date)
--PowTable = db:getall('SELECT * FROM MyPowerLog where time BETWEEN ? AND ? ORDER BY id DESC', ts_start, ts_end)
PowTable = db:getall('SELECT * FROM MyPowerLog')
-- csv buffer
buffer = {}
-- format csv row
csv = string.format('%q,%q,%q', "Time", "Attiva", "Reattiva")
-- add to buffer
table.insert(buffer, csv)
-- add empty line to buffer
table.insert(buffer, "")
-- Loop through PowTable
for _, Measure in ipairs(PowTable) do
-- format csv row
csv = string.format('%q,%q,%q', os.date("%d.%m.%Y %X", Measure.time),Measure.Attiva, Measure.Reattiva )
-- add to buffer
table.insert(buffer, csv)
end
--Create attachment inside FTP server
src = os.date('%Y-%m') .. '.csv'
dst = '/home/ftp/' .. src
io.writefile(dst, buffer)
thank you