Say, I have a searchfield called name. If the user types 'John' in the searchfield I should check the 'Name' field for the value "John" and select all the corresponding field values. 'John' will be of NSString which is got from searchBar.text, and it has to be added as parameter to the query. I structured a sql statement like this which never worked.
NSString *query = [NSString stringWithFormat:@"select * from Employee where EmployeeName LIKE '%%@%'", searchText.text];
const char *sqlStatement = [query UTF8String];
I tried this also
NSString *query = [NSString stringWithFormat:@"select * from Employee where EmployeeName LIKE %'%@'%", searchText.text];
const char *sqlStatement = [query UTF8String];
Nothing worked.
The trick is to get the percents in there. It's awkward, but you can do it like this:
@"select * from Employee where EmployeeName LIKE '%%%@%%'"
%% is a percent, %@ is the substitution string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With