SQLiteQueryBuilder multiple selection



如何将多个选择(where子句(添加到SQLliteQueryBuilder查询中?例如(年龄在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.

基本上你在selection字符串中传递条件,你提到像

String selection = "arg1 = ? and arg2 = ?" ...

selectionArgs是字符串数组,因此在此处给出选择值:

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.

希望这有帮助!

最新更新