iosdbaccess

DBAccess format structure of whereWithFormat for like queries


I want to make sure I am formatting the right way the clause like in a query. For example, I have the following code:

int count = [[[MyDBObject query] whereWithFormat:@"url like '%%@%'", mySearchString] count];

My question is: am I using the correct formatting for like clause ?

Thank you and happy coding :)


Solution

  • Because the string formatter hates this we had to adapt and make a special parameter type, so we can identify it as a like parameter. Because string formatting is one part, but then the parameters are then supplied to the query the formatting gets quite screwed up and you have to get quite inventive with the escape characters.

    So the thing you need is dbMakeLike()

    Example:

    whereWithFormat:@"lower(text) LIKE %@“, dbMakeLike(searchString.lowercaseString)
    

    Thanks