0

I've got a problem with an update of an SQLite database in iOS7. I think it might be as a result of the lack of a wal file on the new db version, but I might be wrong, as the error is the same when I load i=either the ios6.1 or the iOS 7.0 simulator. I have the simulator loading a local file, using the following code:

    NSString *dbPath = [[NSBundle mainBundle] pathForResource:@"NLancs" ofType:@"sqlite"];
    NSURL *storeURL = [NSURL fileURLWithPath:dbPath];
    // set up for iphone with SQL database in local files. If using simulator comment out "NSString *dbPath = [[NSBundle mainBundle] pathForResource:@"NLancs" ofType:@"sqlite"];" and "[NSURL fileURLWithPath:dbPath];"  above and remove comment from line below
   //[[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"NLancs.sqlite"];

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:
                             [NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
                             [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption, [NSNumber numberWithBool:YES], @{ NSSQLitePragmasOption : @{ @"journal_mode" : @"DELETE" } },nil];

On running the app in the simulator I get the following error:

2014-03-15 15:57:22.974 North Lancashire CCG[40813:907] AppDelegate Setting up a Fetched Results Controller for the Entity named Condition 2014-03-15 15:57:22.981 North Lancashire CCG[40813:907] AppDelegate created new MOM 2014-03-15 15:57:23.056 North Lancashire CCG[40813:907] Unresolved error Error Domain=NSCocoaErrorDomain Code=259 "The operation couldn’t be completed. (Cocoa error 259.)" UserInfo=0xa48a7f0 {NSUnderlyingException=An error occurred converting the metadata plist: Unexpected character a at line 1}, { NSUnderlyingException = "An error occurred converting the metadata plist: Unexpected character a at line 1"; } (lldb)

I've also tried creating an empty database in the simulator, which runs fine. How do I replace it with the populated database without tripping over wal files? The populated database opens fine in SQLite Professional, but if I overwrite the empty simulator database with it, I get the following error (with or without .wal or .shm deleted):

2014-03-15 16:14:32.855 North Lancashire CCG[43265:70b] AppDelegate Setting up a Fetched Results Controller for the Entity

named Condition 2014-03-15 16:14:32.857 North Lancashire CCG[43265:70b] The application Document Directory is: 2014-03-15 16:14:32.870 North Lancashire CCG[43265:70b] AppDelegate created new MOM 2014-03-15 16:14:32.893 North Lancashire CCG[43265:70b] CoreData: error: (11) Fatal error. The database at /Users/Neil/Library/Application Support/iPhone Simulator/7.0.3/Applications/BD12C12C-2DA2-4164-BCAE-B42A2064AABC/Documents/NLancs.sqlite is corrupted. SQLite error code:11, 'database disk image is malformed'

Any ideas?

Neil MCCABE
  • 67
  • 1
  • 10
  • have you tried turning off [WAL journal](http://stackoverflow.com/questions/20062197/how-to-disable-wal-journal-mode) – Flexicoder Mar 15 '14 at 16:27
  • Thanks - I ended up fixing this by doing a CSV data import into the empty simulator database. So I got around the problem, even if I didn't fix the root cause – Neil MCCABE Mar 16 '14 at 13:11

0 Answers0