如何使用 SQLITE3 LIKE 语句
我在项目中运行动态 LIKE 语句时遇到问题: 这个查询的工作方式就像一个魅力,并返回名称中带有“t”的所有项目:
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%t%%'";
当我尝试动态执行此操作时,我不会收到错误,而只是一个空结果。该值似乎为空。我尝试绑定一个输出正确值的字符串值's'
NSLog(@"bbc_ : search menu items from db based on: %@",s);
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%?%%'";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
sqlite3_bind_text(statement, 1, [s UTF8String],-1,SQLITE_TRANSIENT);
我应该如何绑定这个值而不是使用:
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%?%%'";
I have problems running a dynamic LIKE statement in my project:
this query works like a charm and returns all items with a 't' in their name:
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%t%%'";
When I try to do this dynamically I do not get errors, but just an empty result. It seems that the value is null. I try to bind a string value 's' which outputs a correct value
NSLog(@"bbc_ : search menu items from db based on: %@",s);
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%?%%'";
sqlite3_stmt *statement;
if (sqlite3_prepare_v2(database, sql, -1, &statement, NULL) == SQLITE_OK) {
sqlite3_bind_text(statement, 1, [s UTF8String],-1,SQLITE_TRANSIENT);
How should I bind this value instead of using:
const char *sql = "select * from bbc_ipad_v1_node where name LIKE '%%?%%'";
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
刚刚在 http: //www.innerexception.com/2008/10/using-like-statement-in-sqlite-3-from.html
我更改了以下几行:
和
Just found a great explanation at http://www.innerexception.com/2008/10/using-like-statement-in-sqlite-3-from.html
I changed following lines:
and
实际上你可以直接说
(注意单
%
s)You can actually just say
(Note the single-
%
s)