Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Loading SQL vs. XML Core Data Stores

Loading SQL vs. XML Core Data Stores
Thread Tools
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Sep 7, 2006, 10:21 AM
 
I am trying to create a small application that can read in SQL-based
core data stores from another application. To get the basics working
I made a test application that can load the core data store from the
Core Recipes example. If I save the data in XML (the default in the
CR example) my application can read it in and fetch entities without
any issues. If I have CR save the data as an SQL file, and I try to
have my application read the data in, any fetch requests return an
empty array. Am I missing something obvious that I need to do for
the SQL case? Has anyone else run into this issue?

Thanks for your time,
Ian

(this is a cross post on Cocoa-Dev list from which I could not get a reply :-()
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Sep 9, 2006, 01:01 AM
 
Well, you do have to adjust the code a little bit for the different formats -- check the Core Data docs.
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Sep 9, 2006, 08:21 AM
 
Thanks for the reply Mithras. I looked through the documentation more this morning and didn't find anything specific about SQLite accept to let the persistent store coordinator know which type of store you are adding to it. Below is my code if you want to have a look. Thanks for your help thus far, I really appreciate it.

//load the model from app resources
NSArray *bundles = [NSArray arrayWithObject:[NSBundle mainBundle]];
NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:bundles];

//add model to store coordinator
NSPersistentStoreCoordinator *store = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel: managedObjectModel];

//add persistent store w/appropriate type from the URL
NSError *error;
if (![store addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:url options:nil error:&error]){
[[NSApplication sharedApplication] presentError:error];
}

//create context and set the store
NSManagedObjectContext *managedObjectContext = nil;
if (store != nil) {
managedObjectContext = [[NSManagedObjectContext alloc] init];
[managedObjectContext setPersistentStoreCoordinator: store];
}

//try a fetch request
NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MyEntity" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];


this array is always empty :-( even though I know there are "MyEntities"
NSArray *entities = [managedObjectContext executeFetchRequest:request error:&error];


//do cleanup
     
Professional Poster
Join Date: Oct 1999
Location: :ИOITAↃO⅃
Status: Offline
Reply With Quote
Sep 9, 2006, 11:38 AM
 
Dumb question, but are you setting the URL appropriately?
     
Mac Enthusiast
Join Date: Sep 2000
Location: Vermont, USA
Status: Offline
Reply With Quote
Sep 9, 2006, 05:05 PM
 
Good to check that, but yeah, the URL is valid and if use it to load an XML store, it works fine. Any other thoughts?
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 10:59 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2