如何在SQLliteQueryBuilder查询中添加多个选择(where子句)?例如, (年龄在10到20之间,身高= 60)或(性别='F')
public Cursor query (SQLiteDatabase db, String[] projectionIn, String selection, String[] selectionArgs, String groupBy, String having, String sortOrder)
selection A filter declaring which rows to return, formatted as an SQL WHERE clause (excluding the WHERE itself). Passing null will return all rows for the given URL.
selectionArgs You may include ?s in selection, which will be replaced by the values from selectionArgs, in order that they appear in the selection. The values will be bound as Strings.
答案 0 :(得分:10)
基本上你传递selection
字符串中的条件,你提到像
String selection = "arg1 = ? and arg2 = ?" ...
并且selectionArgs
是String数组,因此选择值在此处给出:
selectionArgs[0] = "value of arg1";
selectionArgs[1] = "value of arg2";
and so on
所以你可以使用:
String selection = "Age between ? and ? and Height = ?";
selectionArgs[0] = "10";
selectionArgs[1] = "20";
selectionArgs[2] = "168";
然后将这些字符串传递给query
。
希望这有帮助!