1 of 14

Android Databases

Unit V

Mobile Application Development

By

Michael.K

2 of 14

SQLite

  • SQLite is an in-process library that implements a self-containedserverlesszero-configurationtransactional SQL database engine.
  • Free of cost ( code also available)
  • SQLite is an embedded SQL database engine
    • database library inside an application and there is no need for administrator
  • A complete SQL database with multiple tables, indices, triggers, and views, is contained in a single disk file.

3 of 14

Android SQLite

  • android.database.sqlite - package name
      • Contains the SQLite database management classes that an application would use to manage its own private database.
      • Applications use these classes to manage private databases. 

4 of 14

SQLite classes

SQLiteCursor

A Cursor implementation that exposes results from a query on a SQLiteDatabase. 

SQLiteDatabase

Exposes methods to manage a SQLite database. 

SQLiteOpenHelper

A helper class to manage database creation and version management. 

SQLiteQuery

Represents a query that reads the resulting rows into a SQLiteQuery. 

SQLiteQueryBuilder

This is a convenience class that helps build SQL queries to be sent to SQLiteDatabase objects. 

SQLiteException

A SQLite exception that indicates there was an error with SQL parsing or execution. 

5 of 14

android.database.sqlite.SQLiteOpenHelper

SQLiteDatabase getReadableDatabase()

Create and/or open a database.

SQLiteDatabase getWritableDatabase()

Create and/or open a database that will be used for reading and writing.

abstract void onCreate(SQLiteDatabase db)

Called when the database is created for the first time.

6 of 14

SQLiteDatabase

  • Provides methods to manage an SQLite database.
  • SQLiteDatabase has methods to create, delete, execute SQL commands, and perform other common database management tasks.

https://www.javatpoint.com/android-sqlite-tutorial

7 of 14

SQLiteDatabase

Long insert(String table, String nullColumnHack, ContentValues values)

Convenience method for inserting a row into the database.

Int update(String table, ContentValues values, String whereClause, String[] whereArgs)

Convenience method for updating rows in the database.

Int delete(String table, String whereClause, String[] whereArgs)

Convenience method for deleting rows in the database.

https://www.javatpoint.com/android-sqlite-tutorial

8 of 14

Extending "SQLiteOpenHelper" class

9 of 14

Upgrading DB & inserting data

10 of 14

Retrieving data

11 of 14

Cursor for retrieving data

12 of 14

Update

13 of 14

delete

14 of 14

rawQuery