project-imas / encrypted-core-data

v2.0 - iOS Core Data encrypted SQLite store using SQLCipher
Other
786 stars 237 forks source link

Database locking behavior differing on Mac vs iOS. #256

Open vlozko opened 8 years ago

vlozko commented 8 years ago

I took Apple's earthquake sample app and created both a macOS and iOS version of it. The Core Data components stayed the same between the two (other than DB path). I've tried the following scenarios:

  1. Use iOS and macOS app with NSSQLStoreType - No issues.
  2. Use macOS app with EncryptedStoreType and sqlcipher - No issues.
  3. Use iOS app with EncryptedStoreType with sqlcipher - (see below)
  4. Use iOS app with EncryptedStoreType with iOS's libsql3 static lib and set/change database passphrase stuff commented out and return YES - (see below)

In the iOS cases using encrypted store, I'm frequently getting error messages indicating that the database is locked. It appears to be set in the unixLock function (sqlite3.c:30873 on my side). The project itself does use two different persistent store coordinators for the same database file, though this doesn't appear to be an issue on macOS. I've attached both the iOS and macOS project that demonstrate this difference. EarthquakesIOS.zip EarthquakesMACOS.zip

AKoulabukhov commented 6 years ago

You can use SQLite Pragmas ["journal_mode": "WAL", "busy_timeout": "60000"] to get rid of this error. But current version of ECD not supports NSSQLitePragmasOption in parameters, so u need to fork it and use one of the variants of code update from #212 and all will be ok.