Successfully reported this slideshow.
Your SlideShare is downloading. ×

Cursor & Content Value.pdf

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Upcoming SlideShare
Android Database
Android Database
Loading in …3
×

Check these out next

1 of 13 Ad

More Related Content

Similar to Cursor & Content Value.pdf (20)

Recently uploaded (20)

Advertisement

Cursor & Content Value.pdf

  1. 1. Cursor & Content Value
  2. 2. 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().
  3. 3. Public Methods 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 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(St ring 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.
  4. 4. 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.
  5. 5. 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 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.
  6. 6. Public Methods abstract int getType(int columnIndex) Returns data type of the given column's value. 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.
  7. 7. 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.
  8. 8. ● ContentValues is a maplike class that matches a value to a String key ● A content provider manages access to a central repository of data. ● A provider is part of an Android application, which often provides its own UI for working with the data. ● However, content providers are primarily intended to be used by other applications, which access the provider using a provider client object. . public final class ContentValues extends Object implements Parcelable Content Values
  9. 9. Create Database - Create Table - Provide data in row formate - Abc, xyz,pqr
  10. 10. ContentProvider ● onCreate() This method is called when the provider is started. ● query() This method receives a request from a client. The result is returned as a Cursor object. ● insert()This method inserts a new record into the content provider. ● delete() This method deletes an existing record from the content provider. ● update() This method updates an existing record from the content provider. ● getType() This method returns the MIME type of the data at the given URI.
  11. 11. CRUD is nothing but an abbreviation for the basic operations that we perform in any database. And the operations are ● Create ● Read ● Update ● Delete CRUD
  12. 12. CREATE TABLE employees ( id INTEGER NOT NULL CONSTRAINT employees_pk PRIMARY KEY AUTOINCREMENT, name varchar(200) NOT NULL, department varchar(200) NOT NULL, joiningdate datetime NOT NULL, salary double NOT NULL ); Create Table INSERT INTO employees (name, department, joiningdate, salary) VALUES ('Belal Khan', 'Technical', '2017-09-30 10:00:00', '40000'); Creating a new Record
  13. 13. UPDATE employees SET name = 'Belal Haque', department = 'Research and Development', salary = '100000' WHERE id = 1; Updating Data

×