• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
More CoreData questions...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

More CoreData questions...


  • Subject: More CoreData questions...
  • From: Mike McCabe <email@hidden>
  • Date: Tue, 15 Jan 2008 11:00:01 -0500

I am doing something very similar to what Martin is doing...

I have a legacy Access DB that I am loading via an ODBC connection into Obj-C arrays. I am then cycling thru each table picking out only specific fields of the table to put under CoreData's control in a SQLLite store. I am cycling thru doing fetches based on integer ID's to recreate the relationships that I need.

I already have my indexes indexed and have some pretty simple fetch requests defined that make the code easy to write and implement.

When I get to the first table that I need to recreate a one-to many relationship I find that if after specifying the first connection if I don't force a save of the managedObjectContext then the next fetch that is for the index comes up with 0 results. Here is part of my code...

SessionTable *st = [clientCountsDB st];
numRows = [st getNumberOfRows];

for ( i=0; i < numRows; i++ )
{
sold = [clientCountsDB getSession:i];

Classes *c = [[Classes alloc] initWithEntity:classesEntity insertIntoManagedObjectContext:moc];
c.Class_ID = [NSNumber numberWithUnsignedLong:[[sold Session_ID] integerValue]];
c.Date_Held = [NSDate dateWithString:[[sold Class_Datetime] stringByAppendingString:@" -0500"]];

NSDictionary *substitutionDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[sold Teacher_ID], @"FETCH_ID", nil];
NSFetchRequest *fetchRequest = [[coreDataDelegate managedObjectModel]
fetchRequestFromTemplateWithName:@"GetPersonByID"
substitutionVariables:substitutionDictionary];
NSArray *results = [moc executeFetchRequest:fetchRequest error:&error];

if ( results != nil ) {
if ( [results count] == 0 ) {
NSLog(@"Teacher Not Found in Database - %@\n", [sold Teacher_ID]);
t1 = nil;
} else {
t1 = [results objectAtIndex:0];
NSLog(@"Teacher[%ld] = %@\n", i, [t1 description]);
}
} else {
[[NSApplication sharedApplication] presentError:error];
}

if ( (c != nil) && (t1 != nil) ) {
[t1 addClasses_TaughtObject:c];
}

// If I don't do this then the next time I search for the same Teacher_ID I get 0 results back...


	if (![moc save: &error]) {
		NSLog(@"Error while saving\n%@",[error description]);
		exit(1);
	}

	[c release], c = nil;
}

Any help figuring this out would be appreciated...

Thanks
Mike
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: Distributed Object validity
  • Next by Date: Re: Core Data performance advice... creating relationships.
  • Previous by thread: Re: NSTrackingArea, Pie charts and not rectangular areas
  • Next by thread: re: More CoreData questions...
  • Index(es):
    • Date
    • Thread