2
votes

I am checking my app with iOS9.

A problem happens when I try to reset the database.

See the below code: (Its in AppDelegate)

- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
   if(persistentStoreCoordinator == nil)
   {
       ....
       ....
       persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];

       [persistentStoreCoordinator lock];

        if (![persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error])
        {     
        }

        [persistentStoreCoordinator unlock];
   }

   return persistentStoreCoordinator;
}

Here, the options are..

NSDictionary *options = [NSDictionary dictionaryWithObjectsAndKeys:[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption, [NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,nil];

This code works fine with iOS8 and below. But when I run it with iOS9, the following exception happens.

CoreData: error: -addPersistentStoreWithType:SQLite configuration:(null) URL:file:///var/mobile/Containers/Data/Application/…..sqlite options:{ NSInferMappingModelAutomaticallyOption = 1; NSMigratePersistentStoresAutomaticallyOption = 1; } ... returned error Error Domain=NSCocoaErrorDomain Code=522 "(null)" UserInfo={NSUnderlyingException=I/O error for database at /var/mobile/Containers/Data/Application/….sqlite. SQLite error code:522, 'not an error', NSSQLiteErrorDomain=522} with userInfo dictionary { NSSQLiteErrorDomain = 522; NSUnderlyingException = "I/O error for database at /var/mobile/Containers/Data/Application/….*.sqlite. SQLite error code:522, 'not an error'"; }

But if I add the key-value pair as "journal_mode" = "MEMORY" in my existing "options" dictionary, this error was not happening.

Question:

What does "journal_mode" means in options dictionary? Is it the real problem in my case?

1
It is happening to me too! did the journal_mode add any other collateral issue? - Jordi Puigdellívol
In my case I found that iOS9 creates 2 more files, when deleting the DB I had to delete them all to make it work - Jordi Puigdellívol
@JordiPuigdellívol: can you show some code please? - Grace
@Grace here you have : pastebin.com/Qx4mvUuc - Jordi Puigdellívol

1 Answers

2
votes

So I don't have enough reputation points to comment on your post. But most of what you need to know about journal_mode can be found here.

If my opinion counts, I would never use MEMORY, it just scares me.

I would recommend either DELETE or WAN. Both of these remove the errors that you're seeing and seem much safer to use rather than using MEMORY.