博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ContentResolver.query()的参数 说明
阅读量:4038 次
发布时间:2019-05-24

本文共 1564 字,大约阅读时间需要 5 分钟。

public final Cursorquery (Uri uri,String[] projection, String selection, String[] selectionArgs,String sortOrder)

Since: API Level 1

Query the given URI, returning a Cursor over the result set.

For best performance, the caller should follow theseguidelines:

  • Provide an explicit projection, to prevent reading data fromstorage that aren't going to be used.
  • Use question mark parameter markers such as 'phone=?' insteadof explicit values in theselection parameter, so thatqueries that differ only by those values will be recognized as thesame for caching purposes.
Parameters
uri The URI, using the content:// scheme, for the content toretrieve.
projection A list of which columns to return. Passing null will return allcolumns, which is inefficient.
selection A filter declaring which rows to return, formatted as an SQLWHERE clause (excluding the WHERE itself). Passing null will returnall rows for the given URI.
selectionArgs You may include ?s in selection, which will be replaced by thevalues from selectionArgs, in the order that they appear in theselection. 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 defaultsort order, which may be unordered.
Returns
  • A Cursor object, which is positioned before the first entry, ornull
解释一下:假如一条sql语句如下:
select * from anyTable where var='const'
那么anyTable就是uri,*就是projection,selection是“var=?",selectionArgs写成这样:newString[]{'const‘}

至于最后一个就简单了,就是排序方式。

其实 第三个参数是sql语句where部分,如果第三个参数不带 “?”,那么第四个参数 写成 null;

转载地址:http://kppdi.baihongyu.com/

你可能感兴趣的文章
iOS __block和__weak的区别
查看>>
Android(三)数据存储之XML解析技术
查看>>
Spring JTA应用之JOTM配置
查看>>
spring JdbcTemplate 的若干问题
查看>>
Servlet和JSP的线程安全问题
查看>>
GBK编码下jQuery Ajax中文乱码终极暴力解决方案
查看>>
Oracle 物化视图
查看>>
PHP那点小事--三元运算符
查看>>
解决国内NPM安装依赖速度慢问题
查看>>
Brackets安装及常用插件安装
查看>>
Centos 7(Linux)环境下安装PHP(编译添加)相应动态扩展模块so(以openssl.so为例)
查看>>
fastcgi_param 详解
查看>>
Nginx配置文件(nginx.conf)配置详解
查看>>
标记一下
查看>>
IP报文格式学习笔记
查看>>
autohotkey快捷键显示隐藏文件和文件扩展名
查看>>
Linux中的进程
查看>>
学习python(1)——环境与常识
查看>>
学习设计模式(3)——单例模式和类的成员函数中的静态变量的作用域
查看>>
自然计算时间复杂度杂谈
查看>>