FMDB查询与LIKE无法正常工作 [英] FMDB query isn't acting right with LIKE

查看:321
本文介绍了FMDB查询与LIKE无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用FMDB,它是SQLite的包装器。 http://github.com/ccgus/fmdb

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

这是我的查询行:

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

如果我输入运动员的确切姓名,我可以得到一个结果。但是,我正在尝试使用LIKE,所以我可以搜索名称。但是,当我添加%?%而不仅仅是? ......没有回报。并且没有错误。

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?

谢谢大家!

推荐答案

通配符()必须是替换变量的一部分,而不是查询字符串:

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]];

这篇关于FMDB查询与LIKE无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆