Andreas Zollmann
Andreas Zollmann

Reputation: 187

Is [NSManagedObjectContext save] an atomic commit when using an underlying SQLite DB?

Or could it be that Core Data splits the save operation into several sequential atomic steps? For my work, I have to be sure that when re-accessing the database after a crash, either everything was saved, or I'm rolled back to the state before the save operation. I must not have the case where some modified NSObject's were saved but some not.

NB: I'm using the following SQLite pragma options (do I need any others to ensure atomicity?):

[pragmaOptions setObject:@"FULL" forKey:@"synchronous"];
[pragmaOptions setObject:@"1" forKey:@"fullfsync"];
[pragmaOptions setObject:@"WAL" forKey:@"journal_mode"];

Upvotes: 4

Views: 628

Answers (1)

Daniel Eggert
Daniel Eggert

Reputation: 6715

Yes, Core Data’s -save is transactional. Either everything gets saved or nothing. That's true regardless of which store you use.

Upvotes: 4

Related Questions