public final Cursor query (Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder)
Parameters
uri | The URI, using the content:// scheme, for the content to retrieve. |
---|---|
projection | A list of which columns to return. Passing null will return all columns, which is inefficient. |
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 URI. |
selectionArgs | You may include ?s in selection, which will be replaced by the values from selectionArgs, in the order that they appear in the selection. The values will be bound as Strings. |
sortOrder | How to order the rows, formatted as an SQL ORDER BY clause (excluding the ORDER BY itself). Passing null will use the default sort order, which may be unordered. |
URI 也就是要查询的表的 URI;
projection :要查询的列
selection :也就是一般的Sql语句跟在where后面的条件
selectionArgs:跟在where条件后面的 查询条件的值
sortOrder: 不多说. 根据字段排序
Cursor 返回值 我们可以理解为 一个list集合
示例 : 表名 sms 有 id name gender age address number sessionId 等字段
假设要查询 sms表中 name,sessionId字段信息 根据 gender 为 woman 且 number 值为 1022的查询条件来查询
uri= content://com.feng.jck /sms
String [] colums = {"name","sessionId"};
query(uri,colums,"gender = ? and number = ? ",new String[]{"woman","1022"},null);