Re: Core Data Fetch Error
Re: Core Data Fetch Error
- Subject: Re: Core Data Fetch Error
- From: Greg Herlihy <email@hidden>
- Date: Fri, 10 Mar 2006 15:50:12 -0800
- Thread-topic: Core Data Fetch Error
I would add an NSLog(@"searchText is %@", searchText) to this routine since
it seems evident that searchText inadvertently contains at least one regular
expression metacharacter. I would guess a "." (period) as the most likely
candidate- after all, is "Korea" really the full text? Not "N. Korea" or "S.
Korea"?
One way to avoid the regular expression parsing would be to specify
"CONTAINS" instead of "LIKE" for the match. In fact there seems little
reason to perform a "LIKE" search unless the search text does in fact
contain a regular expression. Otherwise, for literal string searches a
"CONTAINS" predicate would probably not only be faster but would avoid
having any of its characters unintentionally be treated as regular
expression metacharacters (and such characters - if meant to be literal -
have to be escaped - a task which the current program is apparently
neglecting to perform).
Greg
On 3/10/06 2:31 PM, "John Bishop" <email@hidden> wrote:
> I'm doing a fairly simple fetch:
>
> NSFetchRequest *request = [[NSFetchRequest alloc] init];
> NSSortDescriptor *sortDescriptor = [[[NSSortDescriptor alloc]
> initWithKey:@"countryName" ascending:YES] autorelease];
> NSPredicate *searchPredicate = [NSPredicate
> predicateWithFormat:@"countryName like[c] %@", searchText];
> NSEntityDescription *entity = [NSEntityDescription
> entityForName:@"Country" inManagedObjectContext:[self managedObjectContext]];
> [request setEntity:entity];
> [request setPredicate:searchPredicate];
> [request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]];
> NSError *error = nil;
> NSArray *countries = [[self managedObjectContext]
> executeFetchRequest:request error:&error];
> if (error != nil)
> [NSException raise:@"CountrySearchError" format:@"Country search
> failed - %@", [error localizedDescription]];
> [request release];
> return countries;
>
> Which fails (intermittently unfortunately) with:
>
> 2006-03-10 16:08:23.035 App[2060] Can't do regex matching, reason: Can't open
> pattern U_ILLEGAL_ARGUMENT_ERROR (string Korea, pattern , case 1, canon 0)
>
> Yes, I note that the "pattern" seems to be missing in this error message. And
> no, the database is not corrupted - this fails on a fairly small set of data
> (about 50 "Thing"s).
>
> I'd certainly bet that I have some addressing run amok, but I can't seem to
> locate it... I'd like to track it down by finding out how this error happens
> (ie: Is this an error raised during the fetch? If so, why doesn't it get
> returned in &error?). Has anyone seen this error before?
>
> Thanks.
> ------------------------------------------------------------------
> John Bishop <mailto:email@hidden>
> Mulligan Software <http://www.mulligansoftware.com>
> Mulligan's Golf Personal - Stats & Handicapping for the Mac Golfer
> _______________________________________________
> 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
_______________________________________________
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