博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
从数据库中查询数据
阅读量:6364 次
发布时间:2019-06-23

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

ContentResolver的query方法

Cursor android.content.ContentResolver.query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder)

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

For best performance, the caller should follow these guidelines:

•Provide an explicit(明确的、清晰的) projection, to prevent(预防、防止) reading data from storage that aren't going to be used.

•Use question mark parameter markers such as 'phone=?' instead of explicit values in the selection parameter, so that queries that differ only by those values will be recognized as the same for caching purposes.

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.

Returns:

A Cursor object, which is positioned before the first entry, or null

See Also:Cursor


android.database.Cursor

This interface provides random read-write access to the result set returned by a database query. Cursor implementations are not required to be synchronized so code using a Cursor from multiple threads should perform its own synchronization when using the Cursor.


Uri android.content.ContentResolver.insert(Uri url, ContentValues values)

Inserts a row into a table at the given URL. If the content provider supports transactions the insertion will be atomic.

Parameters:

url The URL of the table to insert into.

values The initial values for the newly inserted row. The key is the column name for the field. Passing an empty ContentValues will create an empty row.

Returns:

the URL of the newly created row.


int android.content.ContentResolver.update(Uri uri, ContentValues values, String where, String[] selectionArgs)

Update row(s) in a content URI. If the content provider supports transactions the update will be atomic.

Parameters:

uri The URI to modify.

values The new field values. The key is the column name for the field. A null value will remove an existing field value.

where A filter to apply to rows before updating, formatted as an SQL WHERE clause (excluding the WHERE itself).

selectionArgs

Returns:

the number of rows updated.

Throws:

NullPointerException - if uri or values are null


int android.content.ContentResolver.delete(Uri url, String where, String[] selectionArgs)

Deletes row(s) specified by a content URI. If the content provider supports transactions, the deletion will be atomic.

Parameters:

url The URL of the row to delete.

where A filter to apply to rows before deleting, formatted as an SQL WHERE clause (excluding the WHERE itself).

selectionArgs

Returns:

The number of rows deleted.


android.content.ContentValues

This class is used to store a set of values that the ContentResolver can process.


android.net.Uri

Immutable(不变的、不可变的) URI reference. A URI reference includes a URI and a fragment, the component of the URI following a '#'. Builds and parses URI references which conform to RFC 2396.

In the interest of performance(性能), this class performs little to no validation(验证). Behavior(行为) is undefined for invalid input. This class is very forgiving(容许有错误的)--in the face of invalid input, it will return garbage(垃圾) rather than throw an exception unless otherwise specified.

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

你可能感兴趣的文章
Java 8 比较器:如何对 List 排序
查看>>
CVPR 2017最佳论文作者解读:DenseNet 的“what”、“why”和“how”|CVPR 2017
查看>>
SCRM火了,SaaS服务再现新风口
查看>>
苹果是否步思科后尘折戟中国
查看>>
漏洞预警!微软曝光震网三代漏洞,隔离网面临重大危机
查看>>
协鑫集成第二批1000台E-KwBe光伏储能设备即将启运澳洲
查看>>
爱立信物联网广州路演
查看>>
云计算企业业绩分化明显 9家上市公司中期预喜
查看>>
《VMware Virtual SAN权威指南(原书第2版)》一3.5 可能发生的网络配置问题
查看>>
SK电讯发布Q2财报 净利润同比下降26.9%
查看>>
零售品牌如何驾驭大数据主导商业决策?
查看>>
经济模式UPS在数据中心的应用(上)
查看>>
Intel首款32核Xeon E5 v5跑分曝光:史上最强
查看>>
中国基于国产龙芯处理器的大数据一体机
查看>>
物联网影响商业发展三要素
查看>>
干货分享-FASTJSON那些事.pptx
查看>>
China Unicom and Chunghwa Telecom work together&nb
查看>>
Java图片上查找图片算法
查看>>
Python fabric实现远程操作和部署
查看>>
详解Java中staitc关键字
查看>>