SQLiteCursor

public class SQLiteCursor
extends AbstractWindowedCursor

java.lang.Object
   ↳ android.database.AbstractCursor
     ↳ android.database.AbstractWindowedCursor
       ↳ android.database.sqlite.SQLiteCursor


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

Inherited constants

Inherited fields

Public constructors

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

SQLiteCursor(SQLiteCursorDriver driver, String editTable, SQLiteQuery query)

Execute a query and provide access to its result set through a Cursor interface.

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

Public constructors

SQLiteCursor

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
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

Added in API level 1
public SQLiteDatabase getDatabase ()

Get the database that this cursor is associated with.

Returns
SQLiteDatabase the SQLiteDatabase that this cursor is associated with.

onMove

Added in API level 1
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

Added in API level 1
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

Added in API level 28
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

Added in API level 1
public void setSelectionArguments (String[] selectionArgs)

Changes the selection arguments. The new values take effect after a call to requery().

Parameters
selectionArgs String

setWindow

Added in API level 1
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

Added in API level 1
protected void finalize ()

Release the native resources, if they haven't been released yet.