Prepopulated Core Data SQL store with new Write-Ahead Log (WAL) journaling

泄露秘密 提交于 2019-12-10 11:42:40

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!