通配符不工作的SQLite [英] Wildcard not working in SQLite

查看:128
本文介绍了通配符不工作的SQLite的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图在一个Android应用程序中使用通配符搜索,并保持运行到错误。

I keep trying to use wildcards in a search in an android app, and keep running into errors.

我在我的应用程序中使用下面的字符串进行搜索:

I'm performing a search on my application using the string below:

Cursor c_name = b.query("namedrxns", new String[] { "_id", "name" },
              "name LIKE %?%", new String[] { query }, null, null, null);

当我使用名称,比如%?%名称=%?%我得到一个近% :语法错误:在编制:选择_id,名字来自namedrxns其中name =%%。误差

when I use name LIKE %?% or name=%?% I get a "near "%": syntax error: , while compiling: SELECT _id, name FROM namedrxns WHERE name=%?%" error.

名LIK​​E'%?% NAME =%?%我得到的,而不是绑定或列索引超出范围:办理0x40cb70

but with name LIKE '%?%' or name='%?%' I get instead "bind or column index out of range: handle 0x40cb70"

可能有人请告诉我,我做错了什么?

Could someone please tell me what I'm doing wrong?

谢谢!

推荐答案

追加查询参数。

即:

Cursor c_name = b.query("namedrxns", new String[] { "_id", "name" },
          "name LIKE ?", new String[] { "%"+query+"%" }, null, null, null);

像托马斯·穆勒已经说了,请注意, _ 中的值仍然工作作为通配符。

Like Thomas Mueller already said, please note that % and _ within the value still work as wildcards.

这篇关于通配符不工作的SQLite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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