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.

Table and CSV
#3
(08.06.2021, 06:49)admin Wrote: Use this to delete the storage entry:
Code:
storage.delete('MyPowerLog')
Where is the mistake?

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)
i probably wrong something in the table reading loop but i can't figure out what.

thank you
Reply


Messages In This Thread
Table and CSV - by Frank68 - 08.06.2021, 06:44
RE: Table and CSV - by admin - 08.06.2021, 06:49
RE: Table and CSV - by Frank68 - 08.06.2021, 08:39
RE: Table and CSV - by admin - 08.06.2021, 08:40
RE: Table and CSV - by Frank68 - 08.06.2021, 08:51

Forum Jump: