SQLite DB: Where should it live?

I’m using SQLite for my data store and I have a sqlite3 file ready to use. I’m wondering whereabouts I need to put it in order for Corona to see it. I’m aware that it should go into the Documents Directory, but how do I achieve that? Do I copy the file from Resources into Documents when the app starts? Or can I put it in a sub-folder of my project’s folder and that will work?

Am I better off just creating the DB in Documents on start-up and creating all my tables from scratch using SQL code? [import]uid: 26769 topic_id: 7410 reply_id: 307410[/import]

Do I copy the file from Resources into Documents when the app starts?

If you need to have a pre-created database then yes, although…

Am I better off just creating the DB in Documents on start-up and creating all my tables from scratch using SQL code?

This is the approach I would suggest. Not hugely different for most situations, but it does make development marginally simpler because you don’t have to mess around with setting up your database outside of the code. [import]uid: 12108 topic_id: 7410 reply_id: 26163[/import]

Thanks for the reply. I’m going to go with the “creating the DB in code” option then.

Cheers. [import]uid: 26769 topic_id: 7410 reply_id: 26164[/import]

Actually, maybe not. It’s messy this way. If I make a mistake in my table definition then I have to run code just to correct it. Is there a way of seeing this SQLite file that Corona is making?

It makes more sense to build the DB outside of the code and just drop it into place when it’s ready. However, it’s a pain to have to copy it to the Document Directory. I should just be able to drop it into a “Documents” Directory in my project’s folder.

Hmm. Time for a rethink. [import]uid: 26769 topic_id: 7410 reply_id: 26165[/import]

see this thread, I figured that out just last weekend:
http://developer.anscamobile.com/forum/2011/02/28/unlock-levels-sqlite-or-not

incidentally
I should just be able to drop it into a “Documents” Directory in my project’s folder.

Can’t do that because of restrictions Apple has placed. To protect against tampering, they decided you can’t change any files in the app’s Resource directory. Thus to put a file in the Documents directory on an iPhone you have to go through the indirection of putting the file into the Resource directory and then have the app copy it from there. [import]uid: 12108 topic_id: 7410 reply_id: 26173[/import]

Thanks for the info. I’m getting there with it now :slight_smile: [import]uid: 26769 topic_id: 7410 reply_id: 26245[/import]