Core Data: [NSPersistentStoreCoordinator metadataForPersistentStoreOfType:URL:error:] doesn’t handle SQLLite databases, which are in the recovery mode

Originator:stephan.michels
Number:rdar://17708880 Date Originated:17-Jul-2014 11:46 AM
Status:Open Resolved:
Product:OS X SDK Product Version:Mac OS X 10.9.4 (13E28)
Classification:Serious Bug Reproducible:Always
 
Summary:
[NSPersistentStoreCoordinator metadataForPersistentStoreOfType:URL:error:] doesn’t handle SQLLite databases, which are in the recovery mode.

Steps to Reproduce:
After a crash of the whole system my database in the recovery mode. At the start my app try get the metadata of the database to get the actual version. I get following error:

Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo=0x60800007c540 {NSSQLiteErrorDomain=264, NSUnderlyingException=error during prepareSQL for SQL string 'SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA' : attempt to write a readonly database}

Seems to get equivalent to SQLITE_READONLY_RECOVERY. If setup a PSC with a merged model, then can get the metadata from PSC.
metadataForPersistentStoreOfType:URL:error: should handle this case as well.

Expected Results:
I would expect not error from metadataForPersistentStoreOfType:URL:error:

Actual Results:
I get following error:
Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo=0x60800007c540 {NSSQLiteErrorDomain=264, NSUnderlyingException=error during prepareSQL for SQL string 'SELECT Z_VERSION, Z_UUID, Z_PLIST FROM Z_METADATA' : attempt to write a readonly database}

Comments

Metadata is stored in the database in the case of NSSQLCore, so this is somewhat to be expected. If you can update this issue with a sample project and application data that includes a corrupt or recovery mode database it's much more likely to get fixed.


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!