Using SQLite database with Android...

        Android default Database engine is Lite. SQLite is a lightweight transactional database engine that occupies small amount of disk storage and memory, so its a perfect choice for creating databases on many mobile operating systems such as Android, IOS.

Things to consider when dealing with SQLite:
  1. Data type integrity is not maintained in SQLite, you can put a value of a certain data type in a column of another data type (put string in an integer and vice versa).
  2. Referential integrity is not maintained in SQLite, there is no FOREIGN KEY constraints or JOIN statements.
  3. SQLite Full Unicode support is optional and not installed by default.

In this tutorial we will create a simple database application to store employees data.
This DB has:
Tables:
  1. Employees
  2. Dept.
Views:
  1. ViewEmps: to display employees and their relative departments.
Creating SQLite Database:

      By default SQLite on Android does not have a management interface or an application to create and manage data bases from, so we're going to create the database ourselves by code.

     First we will create a class that handles all the operations required to deal with the database such as creating the database, creating tables, inserting and deleting records and so on.

     The first step is to create a class that inherits from SQLiteOpenHelper class. this class provides two methods to override to deal with the database:
  1. onCreate(SQLiteDatabase db): invoked when the database is created, this is where we can create tables and columns to them, create views or triggers.
  2. onUpgrade(SQLiteDatabse db, int oldVersion, int newVersion): invoked when we make a modification to the database such as altering, dropping , creating new tables.
Our class will have the following members :

public class DatabaseHelper extends SQLiteOpenHelper {

 static final String dbName="demoDB";
 static final String employeeTable="Employees";
 static final String colID="EmployeeID";
 static final String colName="EmployeeName";
 static final String colAge="Age";
 static final String colDept="Dept";
 
 static final String deptTable="Dept";
 static final String colDeptID="DeptID";
 static final String colDeptName="DeptName";
 
 static final String viewEmps="ViewEmps";
The Constructor:
 
public DatabaseHelper(Context context) {
  super(context, dbName, null,33); 
  }
The constructor of the super class has the following parameters:

Context con: The context attached to the database.
DataBaseName: The name of the database.

CursorFactory: some times we may use a class that extends the 
Cursor class to implement some extra validations or operations on the 
queries run on the database. In this case we pass an instance of 
CusrsorFactory to return a reference to our derived class to be used 
instead of the default cursor,

         In this example we are going to use the standard Cursor Interface to 
retrieve results, so the CursorFactory parameter is going to be null.

Version: The version of the schema of the database.

The constructor creates a new blank database with the specified name and version.