provide case- insensitive search of DB (core data)

0

I am a starter in iPhone. I wanted to do case-insensitive search. Database helper used: Core Data.

Following is my code:

   -(WebAttendee *) FindAttendeeBy:(NSString *) badgeID_
    {

        AppDelegate_Shared *delegate1 = [[UIApplication sharedApplication]delegate];


        badgeID_=[badgeID_ stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];

        badgeID_=[badgeID_ stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"];

        self.managedObjectContext = delegate1.managedObjectContext;

        return (WebAttendee *)[self FetchManagedObject:@"WebAttendee" :[NSString stringWithFormat:@ "Barcode LIKE [c] %@",badgeID_ ]];


    }
    -(NSManagedObject *)FetchManagedObject:(NSString *)entity_:(NSString *)predicate_
        {

            NSFetchRequest *request = [[NSFetchRequest alloc] init];
            NSEntityDescription *entity = [NSEntityDescription entityForName:entity_ inManagedObjectContext:managedObjectContext];
            [request setEntity:entity];

            NSPredicate *predicate = [NSPredicate predicateWithFormat:predicate_];
            [request setPredicate:predicate];

            NSError *error = nil;

//--------------------------crashes at this step---------------------------------           
            mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];

            NSLog(@"FetchResult=%@",mutableFetchResults);
            [request release];
            if (mutableFetchResults == nil) {
                // Handle the error.
            }

            if([mutableFetchResults count]!=0)
            return [mutableFetchResults objectAtIndex:0];
            else {
                return nil;
            }

        }

but i am getting the following error:

    2012-07-05 12:58:52.917 SpotLighter[963:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unimplemented SQL generation for predicate (Barcode LIKE[c] 1123)'
    *** Call stack at first throw:
    (
        0   CoreFoundation                      0x01783be9 __exceptionPreprocess + 185
        1   libobjc.A.dylib                     0x018d85c2 objc_exception_throw + 47
        2   CoreData                            0x00fe4676 -[NSSQLGenerator newSQLStatementForFetchRequest:ignoreInheritance:countOnly:nestingLevel:] + 1270
        3   CoreData                            0x00f1ca78 -[NSSQLAdapter _newSelectStatementWithFetchRequest:ignoreInheritance:] + 488
        4   CoreData                            0x00f1c881 -[NSSQLAdapter newSelectStatementWithFetchRequest:] + 49
        5   CoreData                            0x00f1c72e -[NSSQLCore newRowsForFetchPlan:] + 430
        6   CoreData                            0x00f1bab5 -[NSSQLCore objectsForFetchRequest:inContext:] + 357
        7   CoreData                            0x00f1b66e -[NSSQLCore executeRequest:withContext:error:] + 206
        8   CoreData                            0x00fcb0ec -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 1084
        9   CoreData                            0x00f18807 -[NSManagedObjectContext executeFetchRequest:error:] + 359
        10  SpotLighter                         0x0000ff26 -[EntityCommands FetchManagedObject::] + 310
        11  SpotLighter                         0x0001436e -[WebAttendeeController FindAttendeeBy:] + 300
        12  SpotLighter                         0x0009aac6 -[MapBadge Map:::] + 4673
        13  SpotLighter                         0x000687d7 -[SpotLighterHomeScreen SpotLighterDataReceived::::] + 1111
        14  SpotLighter                         0x0002ca83 -[SpotlighterViewController txtNumericBadgeFieldDone:] + 445
        15  UIKit                               0x0051da6e -[UIApplication sendAction:to:from:forEvent:] + 119
        16  UIKit                               0x005ac1b5 -[UIControl sendAction:to:forEvent:] + 67
        17  UIKit                               0x005ae647 -[UIControl(Internal) _sendActionsForEvents:withEvent:] + 527
        18  UIKit                               0x005ad1f4 -[UIControl touchesEnded:withEvent:] + 458
        19  UIKit                               0x007a8987 _UIGestureRecognizerSortAndSendDelayedTouches + 3609
        20  UIKit                               0x007a90fc _UIGestureRecognizerUpdateObserver + 927
        21  CoreFoundation                      0x01764fbb __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 27
        22  CoreFoundation                      0x016fa0e7 __CFRunLoopDoObservers + 295
        23  CoreFoundation                      0x016c2bd7 __CFRunLoopRun + 1575
        24  CoreFoundation                      0x016c2240 CFRunLoopRunSpecific + 208
        25  CoreFoundation                      0x016c2161 CFRunLoopRunInMode + 97
        26  GraphicsServices                    0x01f07268 GSEventRunModal + 217
        27  GraphicsServices                    0x01f0732d GSEventRun + 115
        28  UIKit                               0x0052c42e UIApplicationMain + 1160
        29  SpotLighter                         0x00002168 main + 102
        30  SpotLighter                         0x000020f9 start + 53
    )
    terminate called after throwing an instance of 'NSException'
iphone
case-sensitive
asked on Stack Overflow Jul 5, 2012 by Pallavi • edited Jul 5, 2012 by Pallavi

1 Answer

0
    return (WebAttendee *)[self FetchManagedObject:@"WebAttendee" :[NSString stringWithFormat:@ "Barcode LIKE [c] %@",badgeID_ ]];

was giving error...

I replaced the above line with

return (WebAttendee *)[self FetchManagedObject:@"WebAttendee" :[NSString stringWithFormat:@ "Barcode LIKE [c] '%@'",badgeID_ ]];

and it worked fine!

answered on Stack Overflow Jul 5, 2012 by Pallavi

User contributions licensed under CC BY-SA 3.0