views:

404

answers:

1

I'm using the following code to grab a few objects from SQLite store (which is a prepared SQLite db file, generated with Core Data on desktop):

        NSFetchRequest * request = [[NSFetchRequest alloc] init];
        [request setEntity: wordEntityDescription];
        [request setPredicate: [NSPredicate predicateWithFormat: @"word = %@", searchText]];

        NSError * error = [[NSError alloc] init];
        NSArray * results = [[dao managedObjectContext] executeFetchRequest: request error: &error];

Eveyrthing seems to be setup properly, but executeFetchRequest:error: fails deeply inside Core Data (on NSSQLCore _newRowsForFetchPlan:selectedBy:withArgument) producing 256 error to the outside code.

The only kink I had setting up managedObjectContext is I had to specify NSIgnorePersistentStoreVersioningOption option to addPersistentStoreWithType as it was constantly producing 134100 error (and yes, I'm sure my models are just identical: I re-used the model from the project that produced the SQL file).

Any ideas?

P.S. Don't mind code style, it's just a scratch pad. And, of course, feel free to request any additional info. It would be really great if someone could help.

Update 1 Alex Reynolds, thanks for willingness to help :) The code (hope that's what you wanted to see):

NSEntityDescription * wordEntityDescription; //that's the declaration (Captain Obviousity :)
wordEntityDescription = [NSEntityDescription entityForName: @"Word" inManagedObjectContext: ctx];

As for predicate – never mind. I was removing the predicate at all (to just grab all records) and this didn't make any differences.

Again, the same code works just fine in the desktop application, and that drives me crazy (of course, I would need to add some memory management stuff, but it at least should produce nearly the same behavior, shouldn't it?)

A: 

Can you add code to show how wordEntityDescription is defined?

Also, I think you want:

NSError *error = nil;

You may want to switch the equals symbol to like and use tick marks around the searchText field:

[request setPredicate: [NSPredicate predicateWithFormat: @"word like '%@'", searchText]];

NSPredicate objects are not put together like SQL, unfortunately. Check out Apple's NSPredicate programming guide for more info.

Alex Reynolds
I've updated the question.
Anton
I don't see enough from the code and error to offer more help, sorry. Maybe you can delete your iPhone app from the simulator/phone to build a fresh data store, as a control? (If a fresh store works, there's a problem with your pre-packaged SQLite store.) Have you recently changed the schema for the iPhone app?
Alex Reynolds
I haven't changed anything in the schema. Probably you can direct me to the solution if I explain what I've done:1) Created a regular desktop app w/Core Data support2) Defined a schema3) Prepoluted SQLite using Core Data from Desktop app4) Transfered SQLite file to iPhone (folders, path etc are ok, checked it)5) Linked my schema and entities to an iPhone project6) Tried to use it on the iPhoneiPhone and simulator suck in the same way.Hope this explains unclear stuff.
Anton
Ah, yes, I tried re-generating SQLite file a bit more than 100500 times :)
Anton
So if you *don't* use your pre-generated SQLite file, you still get the same error message?
Alex Reynolds
Yes, the results are the same. However, I suspect there're problems with SQLite schema versions or something like this. I can't understand one thing: if I re-use the same model, why do I encounter wrong version errors?
Anton
If you make a fresh store (*not* re-using your SQLite store or regenerating it) that you're getting wrong version errors is very strange. I would make sure you are making a fresh, clean store: delete the app to clear out settings and store, and then make a new store made separate from the pre-built SQLite data.
Alex Reynolds