• 从数据库中查询数据


    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.

  • 相关阅读:
    day7随笔
    day6随笔
    day5笔记
    uniapp 全屏蒙版下的其他view禁止滑动
    uniapp scroll-view 组件右侧的滚动条
    uni 组件 头部
    根据两点的经纬度查询两点间的距离
    仅供学习使用的一些 相关vue类
    仅供学习使用的一些样式+行为
    百度地图简单调用
  • 原文地址:https://www.cnblogs.com/fengzhblog/p/2792257.html
Copyright © 2020-2023  润新知