Hi!!! in this tutorial we are going to have a brief description about SQLite,its contents,etc which will help us understand it thoroughly:
- What is SQLite ?
- SQLite is an implementation of (Structured Query Language) which is present on all android devices.
- It allows the access of the data structured as an SQL database within an app.
- SQLite statements are similar to that of SQL statements.
- In apps we interact with a SQLite database using the SQLiteOpenHelper class and the SQLiteDatabase class.
- Data-Types used in SQLite:
- TEXT – like a Java String type.
- INTEGER – Size of a long in java.
- REAL – Like a Java double type.
- What is SQLiteOpenHelper ?
- It is a subclass which is used to create database.
- In the constructor, it is called through super, providing it with the name of the database and the current version.
- There is requirement of overriding two methods :
- OnCreate() – Which is called by the system if the database does not exists.
- OnUpgrade()– Called when the version number changes.
- Access to the database is obtained through two methods:
- getReadableDatabase : Accesses the database in the read – only mode.
- getWritableDatabase : Accesses the database in the writable mode.
- Both methods return a SQLite Database instance.
- SQLiteDatabase :
- Once the database is created or connected to ,we can use the instance of SQLiteDatabase to access it.
- It also provides the method to open , query , update and close the database.
- We can execute any SQL statement using execSQL(String query).
- There are also insert( ) , update( ) , delete( ) methods.
- It also provides rawQuery( ) and query( ) :
- rawQuery accepts a raw SQL query with replacement parameters.
- query provides a structured interface.
- Queries return an object of type Cursor :
- getCount( ) – returns the number of rows.
- moveToFirst( ) , moveToNext() – to navigate the rows.
- isAfterLast( ) – to find the last row.
- get(column index) : getString , for example : the column index is the number of the column.
- Close( ) – Cursor objects must always closed.
- What is SimpleCursorAdapter ?
- It is a convenience class to allow the use of a database cursor as a ListAdapter.
- It allows to set a layout for the rows of a ListView.
- It maps the columns in the SQL table to the views in the list item layout.