Thomas
Thomas

Reputation: 43

Where to store the SQLite database file?

I have a SQlite database file with records which comes with my app. I just used the file I added to my project to make my INSERT and UPDATE statements. After uploading it to my test device I got the exception that the file is read only. After a bit of research I found out, that I have to copy the db file to the users directory to make an insert. This works for now. But I have a view questions about it, which i didn't get answered through google:

Where should I put my copy process? I implemented it in the AppDelegates FinishedLaunching, where I check if it already exists.

Where should I copy the file to? I used the MyDocuments folder for now, is this ok?

Since the file cannot be encrypted, can another app access the database file?

When the user decides to delete the app from the device. Will the database file get deleted,too?

Thanks!

Upvotes: 1

Views: 1107

Answers (2)

poupou
poupou

Reputation: 43553

Where should I put my copy process? I implemented it in the AppDelegates FinishedLaunching

Keep in mind that you have a limited amount of time to complete FinishedLaunching execution (around 15 seconds) before the iOS watchdog kills your application.

Depending on the size of your database, the speed of device and other processing you need to do then you might want to consider only checking if it already exists (that should be quick) then do the copy (if required) from to another thread.

I used the MyDocuments folder for now, is this ok?

Yes, using Environment.GetFolderPath (Environment.SpecialFolder.MyDocuments) is correct.

Everything else from @Lightforce answer covers the rest.

Upvotes: 1

Sbhklr
Sbhklr

Reputation: 2703

Where should I put my copy process? I implemented it in the AppDelegates FinishedLaunching, where I check if it already exists.

That really depends, but finishedLaunching is OK from my point of view.

Where should I copy the file to? I used the MyDocuments folder for now, is this ok?

I'm not sure what you mean by "MyDocuments" folder. Each Application has a dedicated Document directory. That's where you should copy it.

Since the file cannot be encrypted, can another app access the database file?

No, they run sand-boxed (unless the device is jailbroken)

When the user decides to delete the app from the device. Will the database file get deleted,too?

Yes, since the whole document directory will be deleted.

Upvotes: 3

Related Questions