English | Site Directory

Android - An Open Handset Alliance Project

android.database.sqlite
public abstract class

android.database.sqlite.SQLiteOpenHelper

java.lang.Object
android.database.sqlite.SQLiteOpenHelper

A helper class to manage database creation and version management. See the Notepad ContentProvider sample for example code.

Summary

Public Constructors

          SQLiteOpenHelper()

Public Methods

abstract        void  onCreate(SQLiteDatabase db)
Called when the database is created for the first time.
        void  onOpen(SQLiteDatabase db)
Called when the database has been opened.
abstract        void  onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)
Called when the database needs to be upgraded.
        SQLiteDatabase  openDatabase(Context context, String name, CursorFactory factory, int newVersion)
Methods inherited from class java.lang.Object

Details

Public Constructors

public SQLiteOpenHelper()

Public Methods

public abstract void onCreate(SQLiteDatabase db)

Called when the database is created for the first time. This is where the creation of tables and the initial population of the tables should happen.

Parameters

db The database.

public void onOpen(SQLiteDatabase db)

Called when the database has been opened.

Parameters

db The database.

public abstract void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)

Called when the database needs to be upgraded. The implementation should use this method to drop tables, add tables, or do anything else it needs to upgrade to the new database.

Parameters

db The database.
oldVersion The old database version.
newVersion The new database version.

public SQLiteDatabase openDatabase(Context context, String name, CursorFactory factory, int newVersion)

Parameters

context A context to use to open or create the database.
name The name of the database to open.
factory An optional factory class that is called to instantiate a cursor when the database is opened.
newVersion The version of the database to open. If this is a new version (that is, newVersion is > the existing version number), then onUpgrade() will be called, and the implementation has the option to update the database.

Returns

  • Returns a SQLiteDatabase to use.
Build m5-rc15i - 10 Jun 2008 13:54