【问题标题】:Execute Query in android searching if a string is contained inside the string inserted in a column如果字符串包含在插入列中的字符串中,则在android中执行查询
【发布时间】:2016-10-20 06:38:28
【问题描述】:

我在一个 android 应用程序中有一个数据库,以下是它的列:

public class DBhelper extends SQLiteOpenHelper {
    public static final String COL_TIPO = "ColonnaTipo";
    public static final String COL_DIFFICOLTA="ColonnaDifficolta";
    public static final String COL_INGREDIENTI = "ColonnaIngredienti";

    //code
}

我使用这个函数对其进行查询(TAB是表名):

public Cursor query_filtri(String[] param, String[] p2) {
    String whereClause="";
    String[] whereArgs=new String[50];
    whereClause=COL_TIPO+"=? AND "+COL_DIFFICOLTA+"=?";
    whereArgs=new String[] {param[0],param[1]};

    return  getWritableDatabase().query(TAB,null,whereClause,whereArgs,null,null,null);
}

param[] 中有我正在搜索的COL_TIPOCOL_DIFFICOLTA 的值,它可以工作。

p2[] 中有 2 个字符串:p2[0] = "hi", p2[1]= "try"。 我将修改查询以获取 COL_INGREDIENTI 中包含世界 hitry 的列。

例如:

我会尝试获得这个

COL_INGREDIENTI "hi, would you try?"

不是这个

COL_INGREDIENTI "hi, how are you?"

如何修改查询?有没有办法让它不区分大小写?

【问题讨论】:

    标签: android sql string sqliteopenhelper contain


    【解决方案1】:

    您可以添加:

    AND COL_INGREDIENTI like '%hi%' and COL_INGREDIENTI like '%try%'
    

    来自the documentation

    默认情况下,对于超出 ASCII 范围的 unicode 字符,LIKE 运算符区分大小写。例如,表达式 'a' LIKE 'A' 为 TRUE,但 'æ' LIKE 'Æ' 为 FALSE

    因此,如果您使用 de ASCII 范围内的字符,则无需担心大小写

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多