FMDB query isn't acting right with LIKE

2019-02-21 11:16发布

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!

1条回答
疯言疯语
2楼-- · 2019-02-21 11:46

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]];
查看更多
登录 后发表回答