Execute Query in android 搜索插入列中的字符串中是否包含字符串
Execute Query in android searching if a string is contained inside the string inserted in a column
我在 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是table的名称):
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_TIPO
和 COL_DIFFICOLTA
的值,并且有效。
在p2[]
中有2个字符串:p2[0] = "hi", p2[1]= "try"
。
我会修改查询以获取 COL_INGREDIENTI
中包含世界 hi
和 try
.
的列
例如:
我会尝试获得这个
COL_INGREDIENTI "hi, would you try?"
而不是这个
COL_INGREDIENTI "hi, how are you?"
如何修改查询?有没有办法让它不区分大小写?
您可以添加:
AND COL_INGREDIENTI like '%hi%' and COL_INGREDIENTI like '%try%'
The LIKE operator is case sensitive by default for unicode characters that are beyond the ASCII range. For example, the expression 'a' LIKE 'A' is TRUE but 'æ' LIKE 'Æ' is FALSE
因此,如果您使用的是 de ASCII 范围内的字符,则无需担心大小写问题
我在 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是table的名称):
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_TIPO
和 COL_DIFFICOLTA
的值,并且有效。
在p2[]
中有2个字符串:p2[0] = "hi", p2[1]= "try"
。
我会修改查询以获取 COL_INGREDIENTI
中包含世界 hi
和 try
.
例如:
我会尝试获得这个
COL_INGREDIENTI "hi, would you try?"
而不是这个
COL_INGREDIENTI "hi, how are you?"
如何修改查询?有没有办法让它不区分大小写?
您可以添加:
AND COL_INGREDIENTI like '%hi%' and COL_INGREDIENTI like '%try%'
The LIKE operator is case sensitive by default for unicode characters that are beyond the ASCII range. For example, the expression 'a' LIKE 'A' is TRUE but 'æ' LIKE 'Æ' is FALSE
因此,如果您使用的是 de ASCII 范围内的字符,则无需担心大小写问题