I’m working on an iOS app that has a rather large sqlite database that gets at least once a day and I’d like to use savepoints to restore it if something happens while the transactions are running.
The statements I’ve been running are the following:
const char *sqlSetSavePoint = @"savepoint updateSavepoint";
const char *sqlRollback = @"Rollback transaction to savepoint updateSavepoint";
I have obviously omitted a lot of code that actually runs these statements, but since I’m running the same method for other statements and they work fine I have confidence that the problem isn’t there. I’m setting the savepoint before running my insert transactions (inserting up to 200 thousand lines) and then if something throws an exception or an error I try to do a rollback.
My questions is; are these rollback statements correct (and I’m just doing something wrong) or is there some other way of using savepoints in sqlite3 in iOS?
EDIT: Just for clarification, I’m trying to set a savepoint before then running a number of transactions and if any of them, or a data fetch from the server, fail I want to do a total rollback to the savepoint. It is simply like this:
"savepoint updateSavepoint"
->FetchDatafromServer()
-> "Begin exclusive transaction"
//sqlite3_bind functions
-> "Commit transaction"
->FetchDatafromServer()
-> "Begin exclusive transaction"
//sqlite3_bind functions
-> "Commit transaction"
->FetchDatafromServer()
-> "Begin exclusive transaction"
//sqlite3_bind functions
-> "Commit transaction"
->FetchDatafromServer()
-> "Begin exclusive transaction"
!!Failure!!
"Rollback transaction to savepoint updateSavepoint"
You can use savepoints inside a transaction or inside other savepoints, but you cannot use transactions inside a savepoint.
Replace your inner transactions with savepoints.