0

我有一个关于 android SQLite 的问题:我在一个表中有一组记录。我正在使用一些特殊字符查询记录,例如 {" , [ , ], *, &, ^, %, $, #}" 。它在游标中返回正确的结果。

当我使用特殊字符 { ' } (单引号)时,它会显示所有结果,而我的数据库中没有该字符的结果。我在 SQLita 工具中执行了相同的查询,它运行良好,但在我的程序中它返回了所有结果。为什么会这样?如何解决这个问题。请帮我解决这个问题。

代码在这里:

if( search_tag!=null && search_tag.length() > 0 )
        {
            query_filtered.append("("+DatabaseHelper.TABLE_DOCS.COL_TITLE+" like "+"'%"+search_tag+"%')");
        }

查询在这里:

select 
    id as _id, category_array, title, 
    building_name, content_type_array, url, type_of_level 
from 
    documents_list 
where 
    (title like '%'%')
4

2 回答 2

3

在 SQL 字符串中,引号必须通过加倍来转义:

... WHERE title LIKE '%''%'

为避免此类格式问题,您应该改用参数:

String title = "'";
db.query(..., "title LIKE ?", new String[] { "%" + title + "%" }, ...);
于 2013-03-22T12:43:35.817 回答
0

This query is working fine for me

String select = "Select time from english_details where title = '"
                + title + "'";

So you can try like this

String select = "Select time from english_details where title = '%"
                + title + "%'";
于 2013-03-22T11:55:04.073 回答