I have an app right now that stores data in a Room database using several entities. What I need is to take the contents of a table, convert the data into a CSV format, and then to send that format via email. I have the very last part buttoned down, as it simply involves sending the file through an intent with ACTION_SEND
. That's easy.
I understand that I can get the path to the actual database and manipulate that file. However, the designers of Room went to such great lengths to put SQLite into a black box that this seems like a bad idea.
I know that I can also write a query method in one of the DAOs that returns a string in CSV format that can then be turned into a File object. However, that is a lot of work, and I'm not going to waste my time if someone else has done so for me.
So, here's my question: How do I export a Room database table into a CSV formatted string? If there are multiple ways of doing so, is there a preferred way?
Bonus question: Is there any preferred way to back up the entire database?