5

I've read many threads about the new WAL default setting in ios7 SQLite / Core Data stack.

It looked like a good idea in the first place... Though I need to perform a database copy to a distant webservice from time to time according to my business needs. At the moment I only backup the SQLITE file and I can't add the 2 other files to the webservice operation I'm using. This means my backup is clearly not up-to-date thus pretty pointless.

Other people suggest that I should disable WAL using the journal_mode=DELETE (NSSQLitePragmasOption) which is, to me, an acceptable workaround. Still, I don't feel comfortable with this. It feels like I'm missing out on a pretty decent performance bump.

Ideally I'd like to be able to tell Core Data / SQLite to sync the SHM/WAL to the main data file and then perform the backup. Is there a way to do so without digging out crazy private or undocumented APIs ?

bneely
  • 9,083
  • 4
  • 38
  • 46
vivien.destpern
  • 1,020
  • 1
  • 7
  • 14
  • r u got any solution? –  Oct 05 '13 at 09:16
  • I'm having the same problem. I'm moving from ios 6 to ios 7, ios6 seems to only have .sqlite file to store data. But ios7 has .shm and .wal file. I use fileWrapper to save the files to a single file. If in iOS7 I don't disable *.shm and *.wal, then iOS6 cannot use the file backuped in iOS7 – JimZ Oct 11 '13 at 01:05
  • I went for the easy option (the former default mode). I didn't find a good solution. – vivien.destpern Oct 30 '13 at 15:55

2 Answers2

2

To move the WAL data to the database file, open the database file and execute the SQL statement PRAGMA wal_checkpoint(RESTART).

CL.
  • 173,858
  • 17
  • 217
  • 259
  • Can you provide an example please ? It looks like it needs the database as well ? Can you get it from a managedContext or something ? – vivien.destpern Oct 01 '13 at 13:30
  • 3
    Never a good idea to talk to SQLite directly when using Core Data. You're supposed to use Objective C methods for this, for your own benefit. – Jay Versluis Nov 29 '13 at 20:30
2
$ sqlite3 yourFile.sqlite
SQLite version 3.7.12 2012-04-03 19:43:07
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> PRAGMA wal_checkpoint(RESTART);
0|20|20
sqlite> .exit
$ 
Alan Zhiliang Feng
  • 1,774
  • 18
  • 20