special character in back endless iOS query

Hello everybody, I’m performing a query on my tableView to show the names of the regions of Italy … I have no problem to show results for nearly all regions but it seems there are problems for regions that have in their character name special such as “Valle d’Aosta” … the character “d '” returns me an error

04/03/2016 11: 57: 06,994 Unistit [4566: 1,292,755] Valle d’Aosta
04/03/2016 11: 57: 07,009 Unistit [4566: 1,292,755] VALUE (null)
04/03/2016 11: 57: 07,582 Unistit [4566: 1,292,755] Server reported an error: FAULT = ‘1017’ [Invalid where clause] <Invalid where clause>

How can I fix?

This is my where clause used

 query.whereClause = [NSString stringWithFormat: @ "region = \ '% @ \'", passData.signup_region];

What did I do wrong?

Hi Fabio,

This looks like a bug, I was able to reproduce it. I am assigning it to a developer.

Regards,
Mark

Hi Fabio,

Use ‘’ (double ') in the where clause to escape a single ’ and enclose the whole value into ` instead of '.

So if your want to find Valle d’Aosta, your where clause should look like:

region=`Valle d''Aosta`

Sergey Hello, thanks for your support … Your advice is correct and it works perfectly, but the problem is that I do not only need “Valle d’Aosta” but also of other regions and entering the whereClause in your way gives me only one query for the Aosta valley and not for any other … I made other attempts but it seems that I can not find a solution … any other ideas ???

P.S. Thanks Mark look forward

You may always enclose the values with xxx and always replace single ’ with two such symbols - and it won’t affect your plain strings.

Fabio,

Before you run a query, you need to check if the string contains any ’ characters. if it does, then you need to make sure that in the query you escape ’ with another '.

Regards,
Mark

Guys forgive me, probably so tired that I can not understand even the little things … forgive me … but I just can not … anyway this is my query, you can show me how to modify it to get my results?

QueryOptions *option = [[QueryOptions alloc] init];
    option.sortBy = @[@"universita ASC"];
    BackendlessDataQuery *query = [BackendlessDataQuery query];
    query.queryOptions = option;
    query.whereClause = [NSString stringWithFormat:@"regione = \'%@\'",passData.signup_region];
    [backendless.persistenceService find:[NGUniversity_DB class] dataQuery:query response:^(BackendlessCollection *universityList) {
        _universityArray = [universityList getCurrentPage];
            [self.tableView reloadData];
        [_activityIndicator stopAnimating];


    } error:^(Fault *fault) {
        NSLog(@"Server reported an error: %@", fault);


    }];

I did not understand how I close this post without having resolved now … I also wrong to close the post by mistake. However nothing … I tried in every way and I continue always ricervere the same mistake

Server reported an error: FAULT = ‘1017’ [Invalid where clause] <Invalid where clause>

Maybe you were right Mark, it’s probably a Bug! I currently-stop app development for this thing … amazing …

Fabio,

In this post Sergey wrote how to format the query. Did you read it? Did it make sense?

Mark

First, you replace any single ’ with ‘’ (I suppose Objective-C has some “replace” function). This won’t change plain strings, but will correct the ones that contain ’ symbol.
Second, in your where clause, use ` symbol instead of ’ on the leftmost and rightmost places.

Here are some examples of what you need to send as a result:

    region=`Valle d''Aosta` region=`San Francisco` region=`USA`
All these whereClauses will be handled properly.

the problem is that my where clause is not static but changes according to the tableView cell that you selected by returning the value of NSString that I need … anyway I solved with a simple IF dividing the query and its where clause

  if ([passData.signup_region isEqualToString:@"Valle d'Aosta"])
        query.whereClause = [NSString stringWithFormat:@"regione = `Valle d''Aosta`"];
    
    else
        query.whereClause = [NSString stringWithFormat:@"regione = `%@`", passData.signup_region];

I believe this one is better (but not sure about the exact syntax as I’ve never written in obj-c):

NSString *escaped_region = [passData.signup_region stringByReplacingOccurrencesOfString:@"'" withString:@"''"];
query.whereClause = [NSString stringWithFormat:@"regione=`%@`", escaped_region];

Sergey this is also a good way, and I confirm that it works to perfection

Hello Guys are always me … I explained why this quesry does not work ?? I always returns the same mistake that I had before, but I had changed all the code according to your advice … the error is:

12/20/2016 19: 13: 09,285 UNISTit [20630: 5124305] Server reported an error: FAULT = ‘1017’ [Invalid where clause: Abruzzo] <Invalid where clause: Abruzzo>

Tell me where I’m wrong because I’m going crazy … Until a few months ago everything worked …

#pragma mark -

#pragma mark QUERY UNIVERISTY FROM DB

-(void)retrieveUniversityListFromDb {

    UPPassData *passData = [UPPassData sharedInstance];

    

    QueryOptions *option = [[QueryOptions alloc] init];

    //option.sortBy = @[@"universita ASC"];

    BackendlessDataQuery *query = [BackendlessDataQuery query];

    query.queryOptions = option;

    

    NSString *escaped_region = [passData.signup_region stringByReplacingOccurrencesOfString:@"'" withString:@"''"];

    

    query.whereClause = [NSString stringWithFormat:@"regione=`%@`", escaped_region];

    

    [backendless.persistenceService find:[UPUniversity_DB class] dataQuery:query response:^(BackendlessCollection *universityList) {

        

        _universityArray = [universityList getCurrentPage];

        NSLog(@" %@", _universityArray);




        [self.tableView reloadData];

        

    } error:^(Fault *fault) {

        NSLog(@"Server reported an error: %@", fault);

        

    }];

}



I believe this was answered in another topic, am I wrong?