Send data to email in csv format

Hello!

I have an app that uses sqlite3 to create a table and the table contains information such as name, email, and phone. I’d like to offer an option to the user to export the data from the database to a csv format. Is this possible?

You would have to extract the data from the SQL file, write it out as a text file in CSV format to say your system.TemporaryDirectory and then you can attach it to an email using the native.showPopup() API for mail.

Rob

Thanks Rob! I was afraid that would be the answer.

I thought this might make a good tutorial.  I found some existing Lua code for parsing a CSV file into a Lua table but I didn’t find anything for taking a Lua table and writing out a CSV file.  It’s really not that hard, except for escaping quotes inside of strings.  I may still try to do this, if I can figure out a reasonably simple way to quote the strings correctly.

Rob

You would have to extract the data from the SQL file, write it out as a text file in CSV format to say your system.TemporaryDirectory and then you can attach it to an email using the native.showPopup() API for mail.

Rob

Thanks Rob! I was afraid that would be the answer.

I thought this might make a good tutorial.  I found some existing Lua code for parsing a CSV file into a Lua table but I didn’t find anything for taking a Lua table and writing out a CSV file.  It’s really not that hard, except for escaping quotes inside of strings.  I may still try to do this, if I can figure out a reasonably simple way to quote the strings correctly.

Rob