Core Data Predicate:Unimplemented SQL Generation for Predicate

Core Data predicate : unimplemented SQL generation for predicate

"ANY" in a Core Data predicate works only for a single to-many relationship.
Since your query involves two to-many relationships, you have to use a SUBQUERY:

[NSPredicate predicateWithFormat:@"SUBQUERY(models, $m, ANY $m.trims IN %@).@count > 0",
arrayOfTrims];

Unimplemented SQL generation for predicate

If properties is a to-many relationship, then you need to indicate which property's display type you want to match against your array. There are three options: any, all, or none. I suspect you want any of the properties' display types to match, so you would use:

NSPredicate *predicate = [NSPredicate predicateWithFormat:@"ANY properties.displayType IN %@", energyDisplayTypes];

Core Data unimplemented SQL generation for predicate

As you can see here contains keyword is used for string comparison.

try modifying your predicate to (not tested):

Edit:

I have tested both:

[NSPredicate predicateWithFormat:@"ANY group.AddressElements = %@",someAddressElement]

And:

[NSPredicate predicateWithFormat:@"%@ IN manufactur.manufactures",someAddressElement]

Both resulting in the following SQL statement:

SELECT DISTINCT 0, t0.Z_PK, t0.Z_OPT, t0.ZSOMEPROP, t0.ZTOONE FROM ZSOMEENTITY t0 JOIN ZTHEONEENTITY t1 ON t0.ZTOONE = t1.Z_PK JOIN ZTHEMANY t2 ON t1.Z_PK = t2.ZTOMANY WHERE  t2.Z_PK = ?

(testing on iOS 6.1)

Unimplemented SQL generation for predicate in iOS

Because you're trying to access NSString in array which doesn't contain NSString, your array contains only MSaveRemainders
so you should get the objects of kind of MSaveRemainders and check it's properties,
your method should look like the following

-(void) deleteRemainders:(NSMutableArray*) deleteArray{
NSEntityDescription *entity = [NSEntityDescription entityForName:@"MSaveRemainders" inManagedObjectContext:self.managedObjectContext];
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
for (MSaveRemainders *savedReminder in deleteArray) {
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"mRemainderId LIKE %@", [savedReminder.data valueForKey:@"mRemainderId"]];

// or like the follwing if "data" is a property of a class ( model )
/*
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"mRemainderId LIKE %@", savedReminder.data.mRemainderId ];

*/
[fetchRequest setEntity:entity];
[fetchRequest setPredicate:predicate];
[fetchRequest setReturnsObjectsAsFaults:NO];
NSError *error;
NSArray *fetchedObjects = [self.managedObjectContext executeFetchRequest:fetchRequest error:&error];
for (NSManagedObject *managedObject in fetchedObjects) {
[self.managedObjectContext deleteObject:managedObject];
}
}
}

iphone- core data error 'NSInvalidArgumentException', reason: 'Unimplemented SQL generation for predicate'

According to Predicate Programming Guide Constraints and Limitations section you cannot use MATCHES keyword with sqlite persistent store.

Quote:

The matches operator uses regex, so is not supported by Core Data’s SQL store— although it does work with in-memory filtering.

In your case I would use BEGINSWITH or LIKE. Note, that BEGINSWITH has a performance edge, so I recommend using that whenever possible.

Here are the available predicate comparisons for strings:

String comparisons are by default case and diacritic sensitive. You can modify an operator using the key characters c and d within square braces to specify case and diacritic insensitivity respectively, for example firstName BEGINSWITH[cd] $FIRST_NAME.

BEGINSWITH

The left-hand expression begins with the right-hand expression.

CONTAINS

The left-hand expression contains the right-hand expression.

ENDSWITH

The left-hand expression ends with the right-hand expression.

LIKE

The left hand expression equals the right-hand expression: ? and * are allowed as wildcard characters, where ? matches 1 character and * matches 0 or more characters. In Mac OS X v10.4, wildcard characters do not match newline characters.

MATCHES

The left hand expression equals the right hand expression using a regex-style comparison according to ICU v3 (for more details see the ICU User Guide for Regular Expressions).

The exception here is MATCHES which cannot be used with sqlite persistent store as I said before. On top of those you can use plain == for strict equality comparison.



Related Topics



Leave a reply



Submit