问题
I would like to ship my app with an SQL datastore, but now, since Apple has introduced a WAL journaling, that makes 3 files instead of one, so I wonder if I should ship all 3 of them, or I can try to force SQL to make a checkpoint, merging it all into one .sql file.
I would really like to go with this new iOS 7 feature, so going back to rollback journaling is not a way for me.
回答1:
To force SQLite to make a checkpoint, execute PRAGMA wal_checkpoint.
Alternatively, ship the database with journal_mode = DELETE
, and change the mode after the file has been installed.
In any case, there is no problem with just shipping all files.
(The -shm
file does not contain permanent data and could be ignored.)
回答2:
You don't have to use WAL, that's just the default. You can switch to a different mode. When adding the persistent store, set the options
argument to something like
NSDictionary *options = @{ @"journal_mode": @"DELETE" };
Then you'll get the same journal behavior as in earlier versions of iOS. Use this when creating your pre-populated data store and you won't need to deal with the extra journal files.
来源:https://stackoverflow.com/questions/19758834/prepopulated-core-data-sql-store-with-new-write-ahead-log-wal-journaling