Android TutorialsBrief Description On SQLite

Brief Description On SQLite

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 ?
  1. SQLite is an implementation of (Structured Query Language) which is present on all android devices.
  2. It allows the access of the data structured as an SQL database within an app.
  3. SQLite statements are similar to that of SQL statements.
  4. In apps we interact with a SQLite database using the SQLiteOpenHelper class and the SQLiteDatabase class.
  • Data-Types used in SQLite:
  1. TEXT – like a Java String type.
  2. INTEGER – Size of a long in java.
  3. REAL – Like a Java double type.
  • What is SQLiteOpenHelper ?
  1. It is a subclass which is used to create database.
  2. In the constructor, it is called through super, providing it with the name of the database and the current version.
  3. There is requirement of overriding two methods :
    1. OnCreate() – Which is called by the system if the database does not exists.
    2. OnUpgrade()– Called when the version number changes.

  4. Access to the database is obtained through two methods:
    1. getReadableDatabase : Accesses the database in the read – only mode.
    2. getWritableDatabase : Accesses the database in the writable mode.
    3. Both methods return a SQLite Database instance.
  • SQLiteDatabase :
  1. Once the database is created or connected to ,we can use the instance of SQLiteDatabase to access it.
  2. It also provides the method to open , query , update and close the database.
  3. We can execute any SQL statement using execSQL(String query).
  4. There are also insert( ) , update( ) , delete( ) methods.
  5. It also provides rawQuery( ) and query( ) :
    1. rawQuery accepts a raw SQL query with replacement parameters.
    2. query provides a structured interface.
  6. Queries return an object of type Cursor :
    1. getCount( ) – returns the number of rows.
    2. moveToFirst( ) , moveToNext() – to navigate the rows.
    3. isAfterLast( ) – to find the last row.
    4. get(column index) : getString , for example : the column index is the number of the column.
    5. Close( ) – Cursor objects must always closed.
  • What is SimpleCursorAdapter ?
  1. It is a convenience class to allow the use of a database cursor as a ListAdapter.
  2. It allows to set a layout for the rows of a ListView.
  3. It maps the columns in the SQL table to the views in the list item layout.

Exclusive content

- Advertisement -

Latest article

21,501FansLike
4,106FollowersFollow
106,000SubscribersSubscribe

More article

- Advertisement -