SQLite的(像)查询返回所有结果时有特殊字符查询 [英] SQLite (like) query returning all results when queried with special characters
问题描述
我有一个关于Android的SQLite的一个问题:我在一个表中有一组记录。我使用了一些特殊字符,如{,[,],*&安培;,^,%,$#}查询记录。它返回一个指针正确的结果。
当我使用特殊字符{'}(单引号),它显示所有的结果,其中有我的数据库这个角色没有结果。我执行相同的查询中SQLita工具,它正在完美的,但在我的程序它返回所有结果。为什么会这样?如何解决这个问题。请帮我解决这个问题。
在code是在这里:
如果(SEARCH_TAG = NULL&放大器;!&安培; search_tag.length()0)
{
query_filtered.append((+ DatabaseHelper.TABLE_DOCS.COL_TITLE +象+%+ SEARCH_TAG +%));
}
查询是在这里:
选择
id作为_id,category_array,标题,
building_name,content_type_array,网址,type_of_level
从
documents_list
哪里
(标题LIKE'%'%')
在SQL字符串,报价必须由他们加倍进行转义:
... WHERE标题LIKE'%''%'
要避免这样的格式问题,您应该使用参数而不是:
字符串标题=';
db.query(...称号样?,新的String [] {%+标题+%},...);
I have a question regarding android SQLite: I have a group of records in a table. I am querying the records using some special characters like {" , [ , ], *, &, ^, %, $, #}" . It returning the correct results in a cursor.
When I am using a special character { ' } (single quote), it displaying all results where no results with that character in my database. I executed the same query in SQLita tool it is working perfect, but in my program it is returning all the results. Why this is happening ? How to resolve this issue. please help me in resolving this issue.
The code is here:
if( search_tag!=null && search_tag.length() > 0 )
{
query_filtered.append("("+DatabaseHelper.TABLE_DOCS.COL_TITLE+" like "+"'%"+search_tag+"%')");
}
The query is here:
select
id as _id, category_array, title,
building_name, content_type_array, url, type_of_level
from
documents_list
where
(title like '%'%')
In SQL strings, quotes must be escaped by doubling them:
... WHERE title LIKE '%''%'
To avoid formatting problems like this, you should use parameters instead:
String title = "'";
db.query(..., "title LIKE ?", new String[] { "%" + title + "%" }, ...);
这篇关于SQLite的(像)查询返回所有结果时有特殊字符查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!