Best Practice for SQLite: Adding an already a populated database

Hello,
I’m looking for the best practice solution for a SQLite database Issue:

I have a SQLite database which is already populated that I want to use in my app. Where do I put that file so Corona SDK will pick it up?

In an answer I saw on that issue it says (from: http://developer.anscamobile.com/forum/2010/05/15/sqlite-openingcreating-database):

If you already have your SQLite db you can place it in the same folder as your main.lua file so it’s easy to find.
For example:
1
2
3
4 local path = system.pathForFile(“data.db”, system.ResourceDirectory)
db = sqlite3.open( path )

However, on the DB tutorial the suggestion was (from http://blog.anscamobile.com/2012/04/tutorial-database-access-in-corona/):

NOTE: The recommended location for creating a database is system.DocumentsDirectory (as shown in the example). This will ensure that you are able to read/write to your database, and that it is in a safe location. Your project resource directory is not writable, and temp/cache directories are periodically wiped clean by the OS.

But, when I first install the App, I don’t have Access to the system.DocumentsDirectory.

Do you suggest I’ll put it DB in the system.ResourceDirectory then Move it to the system.DocumentsDirectory?
Thanks
[import]uid: 43596 topic_id: 24938 reply_id: 324938[/import]

Yes, this is the only way.

Attention, Documents directory is dedicated for user generated content.
If your database does not host content made by user, you should put it into tmp or cache directory.

F [import]uid: 5578 topic_id: 24938 reply_id: 101245[/import]

I would like to add two more questions to this post.

  1. What happens to “DocumentsDirectory” when the apps is updated? Is it wipped or remains same as before the update?
  2. Which is the better way to allow the user to do database backup and database restore?
    [import]uid: 50425 topic_id: 24938 reply_id: 101259[/import]

Regarding your first question, I think it’s up to the developer to decide: If you wrote your App so that every update it wipes the “DocumentsDirectory” clean, it will be wiped clean but that’s a very good question and worth opening a new thread for it

As for your second question, what do you mean by the User?
If, by user, you mean the Developer, I guess it’s up to you to create a Backup. As for Restore, that’s a very good question but i guess you can use the Backup you will make [import]uid: 43596 topic_id: 24938 reply_id: 101536[/import]