Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FMDB query isn't acting right with LIKE

I am using FMDB, which is a wrapper for SQLite. http://github.com/ccgus/fmdb

Here is my query line:

FMResultSet *athlete = [db executeQuery:@"SELECT * FROM athletes WHERE athlete_name LIKE ?", search_text];

Using this I can get a result back if I type in the exact name of the athlete. But, I'm trying to use LIKE so I can search on the name. But, when I add %?% instead of just ? ... nothing returns. And there are no errors.

Has anyone ran into this before and know what I'm doing wrong?

Thanks everyone!

like image 562
TheTC Avatar asked Jan 25 '12 19:01

TheTC


1 Answers

The wildcard characters (%) have to be part of the substituted variable, not the query string:

FMResultSet *rs = [db executeQuery:@"SELECT * FROM athletes WHERE athlete_name LIKE ?",
                  [NSString stringWithFormat:@"%%%@%%", search_text]];
like image 164
omz Avatar answered Oct 13 '22 01:10

omz