Package android.database.sqlite
Class SQLiteCursor
- java.lang.Object
-
- android.database.AbstractCursor
-
- android.database.AbstractWindowedCursor
-
- android.database.sqlite.SQLiteCursor
-
- All Implemented Interfaces:
CrossProcessCursor,Cursor,Closeable,AutoCloseable
public class SQLiteCursor extends AbstractWindowedCursor
A Cursor implementation that exposes results from a query on aSQLiteDatabase. SQLiteCursor is not internally synchronized so code using a SQLiteCursor from multiple threads should perform its own synchronization when using the SQLiteCursor.
-
-
Field Summary
-
Fields inherited from class android.database.AbstractWindowedCursor
mWindow
-
Fields inherited from class android.database.AbstractCursor
mClosed, mCurrentRowID, mPos, mRowIdColumnIndex, mUpdatedRows
-
Fields inherited from interface android.database.Cursor
FIELD_TYPE_BLOB, FIELD_TYPE_FLOAT, FIELD_TYPE_INTEGER, FIELD_TYPE_NULL, FIELD_TYPE_STRING
-
-
Constructor Summary
Constructors Constructor Description SQLiteCursor(SQLiteCursorDriver driver, String editTable, SQLiteQuery query)Execute a query and provide access to its result set through a Cursor interface.SQLiteCursor(SQLiteDatabase db, SQLiteCursorDriver driver, String editTable, SQLiteQuery query)Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the Cursor, releasing all of its resources and making it completely invalid.voiddeactivate()Deactivates the Cursor, making all calls on it fail untilCursor.requery()is called.protected voidfinalize()Release the native resources, if they haven't been released yet.intgetColumnIndex(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.intgetCount()Returns the numbers of rows in the cursor.SQLiteDatabasegetDatabase()Get the database that this cursor is associated with.booleanonMove(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.booleanrequery()Performs the query that created the cursor again, refreshing its contents.voidsetSelectionArguments(String[] selectionArgs)Changes the selection arguments.voidsetWindow(CursorWindow window)Sets a new cursor window for the cursor to use.-
Methods inherited from class android.database.AbstractWindowedCursor
checkPosition, clearOrCreateWindow, closeWindow, copyStringToBuffer, getBlob, getDouble, getFloat, getInt, getLong, getShort, getString, getType, getWindow, hasWindow, isBlob, isFloat, isLong, isNull, isString, onDeactivateOrClose
-
Methods inherited from class android.database.AbstractCursor
fillWindow, getColumnCount, getColumnIndexOrThrow, getColumnName, getExtras, getPosition, getUpdatedField, getWantsAllOnMoveCalls, isAfterLast, isBeforeFirst, isClosed, isFieldUpdated, isFirst, isLast, move, moveToFirst, moveToLast, moveToNext, moveToPosition, moveToPrevious, onChange, registerDataSetObserver, respond, setExtras, unregisterDataSetObserver
-
-
-
-
Constructor Detail
-
SQLiteCursor
@Deprecated public SQLiteCursor(SQLiteDatabase db, SQLiteCursorDriver driver, String editTable, SQLiteQuery query)
Deprecated.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 fromFROMonward would be in the params argument.- Parameters:
db- a reference to a Database object that is already constructed and opened. This param is not used any longereditTable- the name of the table used for this queryquery- 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 fromFROMonward would be in the params argument.- Parameters:
editTable- the name of the table used for this queryquery- theSQLiteQueryobject associated with this cursor object.
-
-
Method Detail
-
getDatabase
public SQLiteDatabase getDatabase()
Get the database that this cursor is associated with.- Returns:
- the SQLiteDatabase that this cursor is associated with.
-
onMove
public boolean onMove(int oldPosition, int newPosition)Description copied from class:AbstractCursorThis 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.- Specified by:
onMovein interfaceCrossProcessCursor- Overrides:
onMovein classAbstractCursor- Parameters:
oldPosition- the position that we're moving fromnewPosition- the position that we're moving to- Returns:
- true if the move is successful, false otherwise
-
getCount
public int getCount()
Description copied from interface:CursorReturns the numbers of rows in the cursor.- Specified by:
getCountin interfaceCursor- Specified by:
getCountin classAbstractCursor- Returns:
- the number of rows in the cursor.
-
getColumnIndex
public int getColumnIndex(String columnName)
Description copied from interface:CursorReturns the zero-based index for the given column name, or -1 if the column doesn't exist. If you expect the column to exist useCursor.getColumnIndexOrThrow(String)instead, which will make the error more clear.- Specified by:
getColumnIndexin interfaceCursor- Overrides:
getColumnIndexin classAbstractCursor- Parameters:
columnName- the name of the target column.- Returns:
- the zero-based column index for the given column name, or -1 if the column name does not exist.
- See Also:
Cursor.getColumnIndexOrThrow(String)
-
getColumnNames
public String[] getColumnNames()
Description copied from interface:CursorReturns 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.- Specified by:
getColumnNamesin interfaceCursor- Specified by:
getColumnNamesin classAbstractCursor- Returns:
- the names of the columns returned in this query.
-
deactivate
public void deactivate()
Description copied from interface:CursorDeactivates the Cursor, making all calls on it fail untilCursor.requery()is called. Inactive Cursors use fewer resources than active Cursors. CallingCursor.requery()will make the cursor active again.- Specified by:
deactivatein interfaceCursor- Overrides:
deactivatein classAbstractCursor
-
close
public void close()
Description copied from interface:CursorCloses the Cursor, releasing all of its resources and making it completely invalid. UnlikeCursor.deactivate()a call toCursor.requery()will not make the Cursor valid again.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceCursor- Overrides:
closein classAbstractCursor
-
requery
public boolean requery()
Description copied from interface:CursorPerforms the query that created the cursor again, refreshing its contents. This may be done at any time, including after a call toCursor.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.- Specified by:
requeryin interfaceCursor- Overrides:
requeryin classAbstractCursor- Returns:
- true if the requery succeeded, false if not, in which case the cursor becomes invalid.
-
setWindow
public void setWindow(CursorWindow window)
Description copied from class:AbstractWindowedCursorSets 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.
- Overrides:
setWindowin classAbstractWindowedCursor- Parameters:
window- The new cursor window, typically a remote cursor window.
-
setSelectionArguments
public void setSelectionArguments(String[] selectionArgs)
Changes the selection arguments. The new values take effect after a call to requery().
-
finalize
protected void finalize()
Release the native resources, if they haven't been released yet.- Overrides:
finalizein classAbstractCursor
-
-