SQLite Backup with Sandboxing

Hi all,
In one of my applications I use a SQLite Database, the user has the option to backup and restore the DB to undo changes he made.
For that I create an In-Memory database and using the SQLiteDatabase.Backup methode.
It works as expected if the application is NOT sandboxed, but failes when sandboxed.

It looks like doing the backup is ok, I can open the created In-Memory DB and all tables and data are there - but restoring failes.
(again with the methode SQLiteDatabase.Backup)
The restored DB is empty.
If I deselecte the Sandbox option (AppWrapperMini) all is working normal.

Any ideas?

regards Peter Stocker

The problem is probably that you are not storing the database in a sandbox-safe place.

Check out SpecialFolder.ApplicationData - this is the place your sandboxed app can use quite happily.

Please don’t post 4 times. If you get error with posting, please reload forum page and check if the message was posted before doing again.

It just happened for me. I got error sending the response and reloaded page to see my messages was received.

[quote=91743:@Hanspeter Stocker]Hi all,
In one of my applications I use a SQLite Database, the user has the option to backup and restore the DB to undo changes he made.
For that I create an In-Memory database and using the SQLiteDatabase.Backup methode.
It works as expected if the application is NOT sandboxed, but failes when sandboxed.

It looks like doing the backup is ok, I can open the created In-Memory DB and all tables and data are there - but restoring failes.
(again with the methode SQLiteDatabase.Backup)
The restored DB is empty.
If I deselecte the Sandbox option (AppWrapperMini) all is working normal.

Any ideas?

regards Peter Stocker[/quote]

I have the same issue. Did you find a working solution to this issue you can share with us, please?

In the meanwhile i use the following workaround for Mac App Store (Sandboxed) Apps:

[code]Dim d As New Date
Dim backupDBFile As FolderItem = GetSaveFolderItem( “”, "Database-Name " + d.SQLDateTime.ReplaceAll( “:”, “-” ) + “.db” )

If backupDBFile <> Nil Then

If backupDBFile.Exists Then

MsgBox( kFileAlreadyExist ) // Tell the User that overwriting an existing File is not allowed
Return

End If

db.DatabaseFile.CopyFileTo( backupDBFile )
MsgBox( kDatabaseBackupSuccessfull )

End If
[/code]

[quote=407999:@Sascha S]In the meanwhile i use the following workaround for Mac App Store (Sandboxed) Apps:

[code]Dim d As New Date
Dim backupDBFile As FolderItem = GetSaveFolderItem( “”, "Database-Name " + d.SQLDateTime.ReplaceAll( “:”, “-” ) + “.db” )

If backupDBFile <> Nil Then

If backupDBFile.Exists Then

MsgBox( kFileAlreadyExist ) // Tell the User that overwriting an existing File is not allowed
Return

End If

db.DatabaseFile.CopyFileTo( backupDBFile )
MsgBox( kDatabaseBackupSuccessfull )

End If
[/code][/quote]

since the data backup have date and time stamp, the overwriting of the data file would happen. So do you really need to include the checking of backupDBFile.Exists??

Yes, because the user could select an existing File and overwriting such a file does not work with a Sandboxed App. It fails without any Error. Better safe then sorry. :slight_smile:

i see… if that is the case, then better be safe than sorry.
my application does not allow them to select a file , so it was okay

you really should use the SQLite BACKUP function and not CopyFile, but that is just my opinion

If you do so in a Sandboxed App, the Backup File is always empty…

what is the command in xojo to do backup for sqlite db??

I guess Page Not Found — Xojo documentation

[quote=91743:@Hanspeter Stocker]It works as expected if the application is NOT sandboxed, but failes when sandboxed.

It looks like doing the backup is ok, I can open the created In-Memory DB and all tables and data are there - but restoring failes.
(again with the methode SQLiteDatabase.Backup)[/quote]

of dear… i don’t even know that exist… i have been using the copyfile method.

i am doing the backup of the application on exit of the application.