http://blog.csdn.net/wcs542882916
/*
*Cursor详解---之源码中的注释
*/
//query()查询数据库结束后会返回Cursor对象,Cursor对象里封装了一张由查询结果组成的数据表(该数据表独立于数据库,互不影响)
//Cursor的结构好比游标卡尺,Cursor里放着一张数据表好比游标里放着刻度尺,移动之后读出数据
//源码注释常用方法说明——本人菜鸟中的菜鸟,不对请多多包涵和指正
package android.database;
import android.content.ContentResolver;
import android.net.Uri;
import android.os.Bundle;
import java.io.Closeable;
/**
* This interface provides random read-write access to theresult set returned
* by a database query.
*
* <p>
* Cursor implementations are not required tobe synchronized so code using a
* Cursor from multiple threads should performits own synchronization when
* using the Cursor.
* </p>
* <p>
* Implementations should subclass {@link AbstractCursor}.
* </p>
*/
/*
* Cursor接口提供对结果集合的随机存取,由数据库查询返回(只要不通过api更新这张表,就算数据库已发生变化它依然不变)。
* Cursor的实现没有要求同步(相对异步),所以在多线程中使用Cursor时应该注意Cursor同步化。多线程就不说了。
* 实现子类 AbstractCursor
*/
public interfaceCursor extendsCloseable {
/*
* Values returned by {@link #getType(int)}.These should be consistent with
* the corresponding types defined inCursorWindow.h
*/
/** Value returned by {@link #getType(int)} if the specifiedcolumn is null */
static final int FIELD_TYPE_NULL= 0;
/**
* Value returned by {@link #getType(int)} if the specifiedcolumn type is
* integer
*/
static final int FIELD_TYPE_INTEGER= 1;
/**
* Value returned by {@link #getType(int)} if the specifiedcolumn type is
* float
*/
static final int FIELD_TYPE_FLOAT= 2;
/**
* Value returned by {@link #getType(int)} if the specifiedcolumn type is
* string
*/
static final int FIELD_TYPE_STRING= 3;
/**
* Value returned by {@link #getType(int)} if the specifiedcolumn type is
* blob
*/
static final int FIELD_TYPE_BLOB= 4;
/**
* Returns the numbers of rows in the cursor.
*
* @return the number of rows in the cursor.
*/
//返回结果集的行数,每一行的位置从0开始编号,比如有3行,编号0,1,2
int getCount();
/**
* Returns the current position of the cursorin the row set. The value is
* zero-based. When the row set is first returnedthe cursor will be at
* positon -1, which is before the first row. After thelast row is returned
* another call to next() will leave the cursorpast the last entry, at a
* position of count().
*
* @return the current cursor position.
*/
//返回Cursor所在结果集上的当前位置(这个结果集以行为数据单位,相当于一张不变的数据表)
//结果集的位置编号从0位置开始递增。Cursor里-1和3位置是虚拟存在的,move方法都可以将Cursor移动到此处,但是都返回false。
//假设返回的结果集为3条数据getCount()的值为3,那么Cursor里包裹的实际数据表结构如下,至于-1位置的时候获取值不知道会返回什么。
/* Cursor | 位置 | _id\coloumName | PersonName | ... |
* --> -1(虚拟位置,move方法使用)
* 0 0 LiLei(第一行)
* 1 1 LiLi
* 2 2 HanMei(最后行)
* 3 (虚拟位置)
*/
//当获取Cursor时指在-1位置,当Cursor移动到最后行,再移动一行则会指在3位置,返回3 == getCount();
int getPosition();
/**
* Move the cursor by a relative amount,forward or backward, from the
* current position. Positive offsets moveforwards, negative offsets move
* backwards. If the final position is outsideof the bounds of the result
* set then the resultant position will bepinned to-1 or count()depending
* on whether the value is off the front or endof the set, respectively.
*
* <p>
* This method will return true if therequested destination was reachable,
* otherwise, it returns false. For example, ifthe cursor is at currently
* on the second entry in the result set andmove(-5) is called,the
* position will be pin