Persistent Store Error
Persistent Store Error
- Subject: Persistent Store Error
- From: Arved von Brasch <email@hidden>
- Date: Sat, 16 Sep 2006 18:39:30 +1000
Hi Cocoa Dev List,
I have encountered a problem with NSPersistentStoreCoordinator that I
can't figure out. I have a simple CoreData application. I have
modified the data store from the first version and thus needed to
write conversion code. My method has been as follows:
When the persistentStoreCoordinator is created, if it can't add the
SQLite store because of the version problems, then it presents an
alert and uses the error recovery mechanism to try and convert the
store.
My recovery code looks like this:
if (recoveryOptionIndex == 0) {
NSManagedObjectModel *oldModel = [[[NSManagedObjectModel alloc]
initWithContentsOfURL: oldModelURL] autorelease];
NSPersistentStoreCoordinator *oldStore =
[[[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:
oldModel] autorelease];
NSError *error;
if (![oldStore addPersistentStoreWithType: NSSQLiteStoreType
configuration: nil URL: dataStore options: nil error: &error]) {
/* Convert from version 1 to current */
...
/* Delete old store */
int tag;
if ([[NSWorkspace sharedWorkspace] performFileOperation:
NSWorkspaceRecycleOperation source: [dataStore
stringByDeletingLastPathComponent] destination: @"" files: [NSArray
arrayWithObject: [dataStore lastPathComponent]] tag: &tag]) {
if (![persistentStoreCoordinator addPersistentStoreWithType:
NSSQLiteStoreType configuration: nil URL: [NSURL fileURLWithPath:
dataStore] options: nil error: &error]) {
success = YES;
}
}
}
else {
[[NSApplication sharedApplication] presentError: error];
}
}
The current model, context and persistent store are created at
runtime, as usual, but obviously the addPersistentStoreWithType: call
failed. My method in words is to create a new managedObjectModel,
persistentStoreCoordinator and managedObjectContxt for the old
format. The old persistentStoreCoordinator would load in the old
store, do the conversion in memory to the new store. Then the old
data store would be moved to the trash, allowing the new one to be
created.
My problem is that the [oldStore addPresistentStoreWithType: ...]
method is failing, but with no details in the error presented. Thus,
I don't know what I'm doing wrong in order to fix the problem.
Any ideas?
Cheers,
Arved
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden