I am working on an application which uses SQLite databases a lot.
The user is able to copy and backup the DB, he also can change the encryption key.
This is all working ok WITHOUT sandboxing.
When I sandbox (with AppWrapper), most of the operations are failing and generating a SQLite error.
It is due to SQLite writes temporary and journal files for allmost every DB operation and sandboxing does not allow this.
I have searched numerious forums and Apple Developer pages but could not find a solution to overcome this limitation.
I have also tried different approaches like setting the journal-mode to MEMORY or loading the DB to the special folder ‘ApplicationData’,
but none of them are eliminating all errors.
There must be a better solution!
Any help would be appreciated.
regards Peter Stocker
When your app starts up, copy the db to your App Suppprt folder, do updates there, then copy it back either on close or periodically.
Just one idea.
[quote=93729:@Hanspeter Stocker]It is due to SQLite writes temporary and journal files for allmost every DB operation and sandboxing does not allow this.
[/quote]
With sandboxed applications, you have to set your program to use the proper folders. A subfolder of Specialfolder.AppData named after your app bundle is recommended for the database and could be used for temporary files as well, or you could set SQLLite to use the SpecialFolder.Temporary folder for temporary files.
Make sure not to use any shellpath or absolutepath, as sandboxed apps use a special container for both AppData and Temporary which is different than the location of unsandboxed.
Have you tried to look at the Console messages to see exactly where and which files your app is denied writing ?
If you could post some of the errors, that would be helpful. AFAIK, enabling journaling and/or moving the database to the App Support folder solves pretty much all errors.
The other possibility could be, does you application remember the last open files and then either auto open or allow the user to re-open (Recent menu)?
As Sam wrote: we now need to know the specific error messages to be able to help.
I am working with SQLite Databases from sandboxed apps every day. As you wrote, the database needs to be in Application Data, but once it is there, then I do not have to switch MEMORY mode to on (I would not do this for a productive app anyway).
At the beginning I allowed the database files to be in the user’s documents folder, but this leads to all kind of follow-up problems with sandboxed apps: you need to mess around with security scoped bookmarks (and this you want to avoid, if ever possible).
So now I wrote a little dialog which allows the user to create, rename, delete, import databases inside his application data folder, and I’m using this in various of our inhouse apps.
So I am sure there are ways to solve your issues.