SQLiteCursor
public
class
SQLiteCursor
extends AbstractWindowedCursor
A Cursor implementation that exposes results from a query on a
SQLiteDatabase
.
SQLiteCursor is not internally synchronized so code using a SQLiteCursor from multiple
threads should perform its own synchronization when using the SQLiteCursor.
Summary
Public methods |
void
|
close()
Closes the Cursor, releasing all of its resources and making it completely invalid.
|
void
|
deactivate()
Deactivates the Cursor, making all calls on it fail until requery() is called.
|
int
|
getColumnIndex(String columnName)
Returns the zero-based index for the given column name, or -1 if the column doesn't exist.
|
String[]
|
getColumnNames()
Returns a string array holding the names of all of the columns in the
result set in the order in which they were listed in the result.
|
int
|
getCount()
Returns the numbers of rows in the cursor.
|
SQLiteDatabase
|
getDatabase()
Get the database that this cursor is associated with.
|
boolean
|
onMove(int oldPosition, int newPosition)
This function is called every time the cursor is successfully scrolled
to a new position, giving the subclass a chance to update any state it
may have.
|
boolean
|
requery()
Performs the query that created the cursor again, refreshing its
contents.
|
void
|
setFillWindowForwardOnly(boolean fillWindowForwardOnly)
Controls fetching of rows relative to requested position.
|
void
|
setSelectionArguments(String[] selectionArgs)
Changes the selection arguments.
|
void
|
setWindow(CursorWindow window)
Sets a new cursor window for the cursor to use.
|
Protected methods |
void
|
finalize()
Release the native resources, if they haven't been released yet.
|
Inherited methods |
From class
android.database.AbstractWindowedCursor
void
|
checkPosition()
This function throws CursorIndexOutOfBoundsException if
the cursor position is out of bounds.
|
void
|
copyStringToBuffer(int columnIndex, CharArrayBuffer buffer)
Retrieves the requested column text and stores it in the buffer provided.
|
byte[]
|
getBlob(int columnIndex)
Returns the value of the requested column as a byte array.
|
double
|
getDouble(int columnIndex)
Returns the value of the requested column as a double.
|
float
|
getFloat(int columnIndex)
Returns the value of the requested column as a float.
|
int
|
getInt(int columnIndex)
Returns the value of the requested column as an int.
|
long
|
getLong(int columnIndex)
Returns the value of the requested column as a long.
|
short
|
getShort(int columnIndex)
Returns the value of the requested column as a short.
|
String
|
getString(int columnIndex)
Returns the value of the requested column as a String.
|
int
|
getType(int columnIndex)
Returns data type of the given column's value.
|
CursorWindow
|
getWindow()
If the cursor is backed by a CursorWindow , returns a pre-filled
window with the contents of the cursor, otherwise null.
|
boolean
|
hasWindow()
Returns true if the cursor has an associated cursor window.
|
boolean
|
isBlob(int columnIndex)
This method was deprecated
in API level 15.
Use getType(int)
|
boolean
|
isFloat(int columnIndex)
This method was deprecated
in API level 15.
Use getType(int)
|
boolean
|
isLong(int columnIndex)
This method was deprecated
in API level 15.
Use getType(int)
|
boolean
|
isNull(int columnIndex)
Returns true if the value in the indicated column is null.
|
boolean
|
isString(int columnIndex)
This method was deprecated
in API level 15.
Use getType(int)
|
void
|
setWindow(CursorWindow window)
Sets a new cursor window for the cursor to use.
|
|
From class
android.database.AbstractCursor
void
|
checkPosition()
This function throws CursorIndexOutOfBoundsException if
the cursor position is out of bounds.
|
void
|
close()
Closes the Cursor, releasing all of its resources and making it completely invalid.
|
void
|
copyStringToBuffer(int columnIndex, CharArrayBuffer buffer)
Retrieves the requested column text and stores it in the buffer provided.
|
void
|
deactivate()
Deactivates the Cursor, making all calls on it fail until requery() is called.
|
void
|
fillWindow(int position, CursorWindow window)
Copies cursor data into the window.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
byte[]
|
getBlob(int column)
Returns the value of the requested column as a byte array.
|
int
|
getColumnCount()
Return total number of columns
|
int
|
getColumnIndex(String columnName)
Returns the zero-based index for the given column name, or -1 if the column doesn't exist.
|
int
|
getColumnIndexOrThrow(String columnName)
Returns the zero-based index for the given column name, or throws
IllegalArgumentException if the column doesn't exist.
|
String
|
getColumnName(int columnIndex)
Returns the column name at the given zero-based column index.
|
abstract
String[]
|
getColumnNames()
Returns a string array holding the names of all of the columns in the
result set in the order in which they were listed in the result.
|
abstract
int
|
getCount()
Returns the numbers of rows in the cursor.
|
abstract
double
|
getDouble(int column)
Returns the value of the requested column as a double.
|
Bundle
|
getExtras()
Returns a bundle of extra values.
|
abstract
float
|
getFloat(int column)
Returns the value of the requested column as a float.
|
abstract
int
|
getInt(int column)
Returns the value of the requested column as an int.
|
abstract
long
|
getLong(int column)
Returns the value of the requested column as a long.
|
Uri
|
getNotificationUri()
Return the URI at which notifications of changes in this Cursor's data
will be delivered, as previously set by setNotificationUri(ContentResolver, Uri) .
|
List<Uri>
|
getNotificationUris()
Return the URIs at which notifications of changes in this Cursor's data
will be delivered, as previously set by setNotificationUris(ContentResolver, List) .
|
final
int
|
getPosition()
Returns the current position of the cursor in the row set.
|
abstract
short
|
getShort(int column)
Returns the value of the requested column as a short.
|
abstract
String
|
getString(int column)
Returns the value of the requested column as a String.
|
int
|
getType(int column)
Returns data type of the given column's value.
|
Object
|
getUpdatedField(int columnIndex)
This method was deprecated
in API level 15.
Always returns null since Cursors do not support updating rows
|
boolean
|
getWantsAllOnMoveCalls()
onMove() will only be called across processes if this method returns true.
|
CursorWindow
|
getWindow()
If the cursor is backed by a CursorWindow , returns a pre-filled
window with the contents of the cursor, otherwise null.
|
final
boolean
|
isAfterLast()
Returns whether the cursor is pointing to the position after the last
row.
|
final
boolean
|
isBeforeFirst()
Returns whether the cursor is pointing to the position before the first
row.
|
boolean
|
isClosed()
return true if the cursor is closed
|
boolean
|
isFieldUpdated(int columnIndex)
This method was deprecated
in API level 15.
Always returns false since Cursors do not support updating rows
|
final
boolean
|
isFirst()
Returns whether the cursor is pointing to the first row.
|
final
boolean
|
isLast()
Returns whether the cursor is pointing to the last row.
|
abstract
boolean
|
isNull(int column)
Returns true if the value in the indicated column is null.
|
final
boolean
|
move(int offset)
Move the cursor by a relative amount, forward or backward, from the
current position.
|
final
boolean
|
moveToFirst()
Move the cursor to the first row.
|
final
boolean
|
moveToLast()
Move the cursor to the last row.
|
final
boolean
|
moveToNext()
Move the cursor to the next row.
|
final
boolean
|
moveToPosition(int position)
Move the cursor to an absolute position.
|
final
boolean
|
moveToPrevious()
Move the cursor to the previous row.
|
void
|
onChange(boolean selfChange)
Subclasses must call this method when they finish committing updates to notify all
observers.
|
boolean
|
onMove(int oldPosition, int newPosition)
This function is called every time the cursor is successfully scrolled
to a new position, giving the subclass a chance to update any state it
may have.
|
void
|
registerContentObserver(ContentObserver observer)
Register an observer that is called when changes happen to the content backing this cursor.
|
void
|
registerDataSetObserver(DataSetObserver observer)
Register an observer that is called when changes happen to the contents
of the this cursors data set, for example, when the data set is changed via
requery() , deactivate() , or close() .
|
boolean
|
requery()
Performs the query that created the cursor again, refreshing its
contents.
|
Bundle
|
respond(Bundle extras)
This is an out-of-band way for the user of a cursor to communicate with the cursor.
|
void
|
setExtras(Bundle extras)
Sets a Bundle that will be returned by getExtras() .
|
void
|
setNotificationUri(ContentResolver cr, Uri notifyUri)
Specifies a content URI to watch for changes.
|
void
|
setNotificationUris(ContentResolver cr, List<Uri> notifyUris)
Similar to setNotificationUri(android.content.ContentResolver, android.net.Uri) , except this version allows
to watch multiple content URIs for changes.
|
void
|
unregisterContentObserver(ContentObserver observer)
Unregister an observer that has previously been registered with this
cursor via registerContentObserver(ContentObserver) .
|
void
|
unregisterDataSetObserver(DataSetObserver observer)
Unregister an observer that has previously been registered with this
cursor via registerContentObserver(ContentObserver) .
|
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait()
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted.
|
|
From interface
android.database.CrossProcessCursor
abstract
void
|
fillWindow(int position, CursorWindow window)
Copies cursor data into the window.
|
abstract
CursorWindow
|
getWindow()
Returns a pre-filled window that contains the data within this cursor.
|
abstract
boolean
|
onMove(int oldPosition, int newPosition)
This function is called every time the cursor is successfully scrolled
to a new position, giving the subclass a chance to update any state it
may have.
|
|
From interface
android.database.Cursor
abstract
void
|
close()
Closes the Cursor, releasing all of its resources and making it completely invalid.
|
abstract
void
|
copyStringToBuffer(int columnIndex, CharArrayBuffer buffer)
Retrieves the requested column text and stores it in the buffer provided.
|
abstract
void
|
deactivate()
This method was deprecated
in API level 16.
Since requery() is deprecated, so too is this.
|
abstract
byte[]
|
getBlob(int columnIndex)
Returns the value of the requested column as a byte array.
|
abstract
int
|
getColumnCount()
Return total number of columns
|
abstract
int
|
getColumnIndex(String columnName)
Returns the zero-based index for the given column name, or -1 if the column doesn't exist.
|
abstract
int
|
getColumnIndexOrThrow(String columnName)
Returns the zero-based index for the given column name, or throws
IllegalArgumentException if the column doesn't exist.
|
abstract
String
|
getColumnName(int columnIndex)
Returns the column name at the given zero-based column index.
|
abstract
String[]
|
getColumnNames()
Returns a string array holding the names of all of the columns in the
result set in the order in which they were listed in the result.
|
abstract
int
|
getCount()
Returns the numbers of rows in the cursor.
|
abstract
double
|
getDouble(int columnIndex)
Returns the value of the requested column as a double.
|
abstract
Bundle
|
getExtras()
Returns a bundle of extra values.
|
abstract
float
|
getFloat(int columnIndex)
Returns the value of the requested column as a float.
|
abstract
int
|
getInt(int columnIndex)
Returns the value of the requested column as an int.
|
abstract
long
|
getLong(int columnIndex)
Returns the value of the requested column as a long.
|
abstract
Uri
|
getNotificationUri()
Return the URI at which notifications of changes in this Cursor's data
will be delivered, as previously set by setNotificationUri(ContentResolver, Uri) .
|
default
List<Uri>
|
getNotificationUris()
Return the URIs at which notifications of changes in this Cursor's data
will be delivered, as previously set by setNotificationUris(ContentResolver, List) .
|
abstract
int
|
getPosition()
Returns the current position of the cursor in the row set.
|
abstract
short
|
getShort(int columnIndex)
Returns the value of the requested column as a short.
|
abstract
String
|
getString(int columnIndex)
Returns the value of the requested column as a String.
|
abstract
int
|
getType(int columnIndex)
Returns data type of the given column's value.
|
abstract
boolean
|
getWantsAllOnMoveCalls()
onMove() will only be called across processes if this method returns true.
|
abstract
boolean
|
isAfterLast()
Returns whether the cursor is pointing to the position after the last
row.
|
abstract
boolean
|
isBeforeFirst()
Returns whether the cursor is pointing to the position before the first
row.
|
abstract
boolean
|
isClosed()
return true if the cursor is closed
|
abstract
boolean
|
isFirst()
Returns whether the cursor is pointing to the first row.
|
abstract
boolean
|
isLast()
Returns whether the cursor is pointing to the last row.
|
abstract
boolean
|
isNull(int columnIndex)
Returns true if the value in the indicated column is null.
|
abstract
boolean
|
move(int offset)
Move the cursor by a relative amount, forward or backward, from the
current position.
|
abstract
boolean
|
moveToFirst()
Move the cursor to the first row.
|
abstract
boolean
|
moveToLast()
Move the cursor to the last row.
|
abstract
boolean
|
moveToNext()
Move the cursor to the next row.
|
abstract
boolean
|
moveToPosition(int position)
Move the cursor to an absolute position.
|
abstract
boolean
|
moveToPrevious()
Move the cursor to the previous row.
|
abstract
void
|
registerContentObserver(ContentObserver observer)
Register an observer that is called when changes happen to the content backing this cursor.
|
abstract
void
|
registerDataSetObserver(DataSetObserver observer)
Register an observer that is called when changes happen to the contents
of the this cursors data set, for example, when the data set is changed via
requery() , deactivate() , or close() .
|
abstract
boolean
|
requery()
This method was deprecated
in API level 15.
Don't use this. Just request a new cursor, so you can do this
asynchronously and update your list view once the new cursor comes back.
|
abstract
Bundle
|
respond(Bundle extras)
This is an out-of-band way for the user of a cursor to communicate with the cursor.
|
abstract
void
|
setExtras(Bundle extras)
Sets a Bundle that will be returned by getExtras() .
|
abstract
void
|
setNotificationUri(ContentResolver cr, Uri uri)
Register to watch a content URI for changes.
|
default
void
|
setNotificationUris(ContentResolver cr, List<Uri> uris)
Similar to setNotificationUri(android.content.ContentResolver, android.net.Uri) , except this version allows
to watch multiple content URIs for changes.
|
abstract
void
|
unregisterContentObserver(ContentObserver observer)
Unregister an observer that has previously been registered with this
cursor via registerContentObserver(ContentObserver) .
|
abstract
void
|
unregisterDataSetObserver(DataSetObserver observer)
Unregister an observer that has previously been registered with this
cursor via registerContentObserver(ContentObserver) .
|
|
From interface
java.io.Closeable
abstract
void
|
close()
Closes this stream and releases any system resources associated
with it.
|
|
|
Public constructors
SQLiteCursor
public SQLiteCursor (SQLiteDatabase db,
SQLiteCursorDriver driver,
String editTable,
SQLiteQuery query)
This constructor is deprecated.
use SQLiteCursor(android.database.sqlite.SQLiteCursorDriver, java.lang.String, android.database.sqlite.SQLiteQuery)
instead
Execute a query and provide access to its result set through a Cursor
interface. For a query such as: SELECT name, birth, phone FROM
myTable WHERE ... LIMIT 1,20 ORDER BY...
the column names (name, birth,
phone) would be in the projection argument and everything from
FROM
onward would be in the params argument.
Parameters |
db |
SQLiteDatabase : a reference to a Database object that is already constructed
and opened. This param is not used any longer |
driver |
SQLiteCursorDriver |
editTable |
String : the name of the table used for this query |
query |
SQLiteQuery : the rest of the query terms
cursor is finalized |
SQLiteCursor
public SQLiteCursor (SQLiteCursorDriver driver,
String editTable,
SQLiteQuery query)
Execute a query and provide access to its result set through a Cursor
interface. For a query such as: SELECT name, birth, phone FROM
myTable WHERE ... LIMIT 1,20 ORDER BY...
the column names (name, birth,
phone) would be in the projection argument and everything from
FROM
onward would be in the params argument.
Parameters |
driver |
SQLiteCursorDriver |
editTable |
String : the name of the table used for this query |
query |
SQLiteQuery : the SQLiteQuery object associated with this cursor object. |
Public methods
close
public void close ()
Closes the Cursor, releasing all of its resources and making it completely invalid.
Unlike deactivate()
a call to requery()
will not make the Cursor valid
again.
deactivate
public void deactivate ()
Deactivates the Cursor, making all calls on it fail until requery()
is called.
Inactive Cursors use fewer resources than active Cursors.
Calling requery()
will make the cursor active again.
getColumnIndex
public int getColumnIndex (String columnName)
Returns the zero-based index for the given column name, or -1 if the column doesn't exist.
If you expect the column to exist use getColumnIndexOrThrow(java.lang.String)
instead, which
will make the error more clear.
Parameters |
columnName |
String : the name of the target column. |
Returns |
int |
the zero-based column index for the given column name, or -1 if
the column name does not exist.
Value is -1 or greater |
getColumnNames
public String[] getColumnNames ()
Returns a string array holding the names of all of the columns in the
result set in the order in which they were listed in the result.
Returns |
String[] |
the names of the columns returned in this query. |
getCount
public int getCount ()
Returns the numbers of rows in the cursor.
Returns |
int |
the number of rows in the cursor.
Value is 0 or greater |
getDatabase
public SQLiteDatabase getDatabase ()
Get the database that this cursor is associated with.
Returns |
SQLiteDatabase |
the SQLiteDatabase that this cursor is associated with. |
onMove
public boolean onMove (int oldPosition,
int newPosition)
This function is called every time the cursor is successfully scrolled
to a new position, giving the subclass a chance to update any state it
may have. If it returns false the move function will also do so and the
cursor will scroll to the beforeFirst position.
Parameters |
oldPosition |
int : the position that we're moving from |
newPosition |
int : the position that we're moving to |
Returns |
boolean |
true if the move is successful, false otherwise |
requery
public boolean requery ()
Performs the query that created the cursor again, refreshing its
contents. This may be done at any time, including after a call to deactivate()
.
Since this method could execute a query on the database and potentially take
a while, it could cause ANR if it is called on Main (UI) thread.
A warning is printed if this method is being executed on Main thread.
Returns |
boolean |
true if the requery succeeded, false if not, in which case the
cursor becomes invalid. |
setFillWindowForwardOnly
public void setFillWindowForwardOnly (boolean fillWindowForwardOnly)
Controls fetching of rows relative to requested position.
Calling this method defines how rows will be loaded, but it doesn't affect rows that
are already in the window. This setting is preserved if a new window is
set
Parameters |
fillWindowForwardOnly |
boolean : if true, rows will be fetched starting from requested position
up to the window's capacity. Default value is false. |
setSelectionArguments
public void setSelectionArguments (String[] selectionArgs)
Changes the selection arguments. The new values take effect after a call to requery().
Parameters |
selectionArgs |
String |
setWindow
public void setWindow (CursorWindow window)
Sets a new cursor window for the cursor to use.
The cursor takes ownership of the provided cursor window; the cursor window
will be closed when the cursor is closed or when the cursor adopts a new
cursor window.
If the cursor previously had a cursor window, then it is closed when the
new cursor window is assigned.
Parameters |
window |
CursorWindow : The new cursor window, typically a remote cursor window. |
Protected methods
finalize
protected void finalize ()
Release the native resources, if they haven't been released yet.