Question

I was trying to populate my iOS sqlite database from a json file. I've wrote a script using python to do this, which read the json file and the coredata Model.xcdatamodeld file. Using mogenerator, it creates the necessary h and m files, and write the information into a sqlite file as below (below is part of the code for generating the sqlite file)

psc = NSPersistentStoreCoordinator.alloc().initWithManagedObjectModel_(mom)
psc_option = {
    NSMigratePersistentStoresAutomaticallyOption : True,
    NSInferMappingModelAutomaticallyOption : True,
}
psc.addPersistentStoreWithType_configuration_URL_options_error_(NSSQLiteStoreType, None, dataURL, psc_option, None)
moc = NSManagedObjectContext.new()
moc.setPersistentStoreCoordinator_(psc)

Everything used to work, but after I upgraded to Maverick, the output file generated 2 additional files (.sqlite-shm and .sqlite-wal). And the output sqlite file appear to be empty (even though the script successfully interpreted the coredata files and the json file). I'm just wondering if anyone know what those files are? and any suggestion on what may cause this? (I suspect some behaviour must have changed during save, but I'm not sure).

Était-ce utile?

La solution

Apple has changed the default journal mode to WAL mode (SQLite Write-Ahead Logging) as described in Core Data and iOS 7: Different behavior of persistent store

It's done by passing the associated SQLite pragma options to NSPersistentStoreCordinator. Look for Configuring a SQLite Store’s Save Behavior

OR perhaps this web article might be more clarifying: Problems with Core Data Migration Manager and journal_mode WAL

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top