Cursor & Content Value
Cursor & Content Value
Cursor
● Cursor is used to Retrieving the data from SQLite Database
● The basic purpose of a cursor is to point to a single row of the result fetched by the query.
● We load the row pointed by the cursor object.
● By using cursor we can save lot of ram and memory.
● Cursor is the Interface which represents a 2 dimensional table of any database.
● When you try to retrieve some data using SELECT statement, then the database will first create a
CURSOR object and return its reference to you.
● To use Cursors android.database. Cursor must be imported.
● Cursors store query result records in rows and grant many methods to access and iterate through the
records.
● Cursors should be closed when no longer used, and will be deactivated with a call to Cursor.deactivate()
when the application pauses or exists.
● On resume the Cursor.requery statement is executed to re-enable the Cursor with fresh data.
● These functions can be managed by the parent Activity by calling startManagingCursor().
Public Methods Cursor
abstract close() Closes the Cursor, releasing all of its resources and
void making it completely invalid.
abstract copyStringToBuffer(int Retrieves the requested column text and stores it in the
void columnIndex, buffer provided.
CharArrayBuffer buffer)
abstract int getColumnIndex(String Returns the zero-based index for the given column name,
columnName) or -1 if the column doesn't exist.
abstract int getColumnIndexOrThrow(St Returns the zero-based index for the given column name,
ring columnName) or throws IllegalArgumentException if the column doesn't
exist.
abstract getColumnName(int Returns the column name at the given zero-based column
String columnIndex) index.
abstract getColumnNames() Returns a string array holding the names of all of the
String[] columns in the result set in the order in which they were
listed in the result.
abstract getDouble(int columnIndex) Returns the value of the requested column as a double.
double
abstract getFloat(int columnIndex) Returns the value of the requested column as a float.
float
abstract getExtras() Returns a bundle of extra values.
Bundle
abstract getFloat(int columnIndex) Returns the value of the requested column as a float.
float
abstract int getInt(int columnIndex) Returns the value of the requested column as an int.
abstract getLong(int columnIndex) Returns the value of the requested column as a long.
long
abstract int getPosition() Returns the current position of the cursor in the row set.
abstract getShort(int columnIndex) Returns the value of the requested column as a short.
short
abstract getString(int columnIndex) Returns the value of the requested column as a String.
String
Public Methods
abstract int getType(int Returns data type of the given column's value.
columnIndex)
abstract isAfterLast() Returns whether the cursor is pointing to the position after the last
boolean row.
abstract isBeforeFirst() Returns whether the cursor is pointing to the position before the
boolean first row.
abstract isFirst() Returns whether the cursor is pointing to the first row.
boolean
abstract isLast() Returns whether the cursor is pointing to the last row.
boolean
abstract isNull(int Returns true if the value in the indicated column is null.
boolean columnIndex)
abstract move(int offset) Move the cursor by a relative amount, forward or backward, from
boolean the current position.
CRUD is nothing but an abbreviation for the basic operations that we perform in any database. And
the operations are
● Create
● Read
● Update
● Delete
Create Table
UPDATE employees
SET
name = 'Belal Haque',
department = 'Research and Development',
salary = '100000'
WHERE id = 1;