Example usage for android.database.sqlite SQLiteOpenHelper SQLiteOpenHelper

List of usage examples for android.database.sqlite SQLiteOpenHelper SQLiteOpenHelper

Introduction

In this page you can find the example usage for android.database.sqlite SQLiteOpenHelper SQLiteOpenHelper.

Prototype

public SQLiteOpenHelper(@Nullable Context context, @Nullable String name, int version,
        @NonNull SQLiteDatabase.OpenParams openParams) 

Source Link

Document

Create a helper object to create, open, and/or manage a database.

Usage

From source file:com.google.android.apps.forscience.whistlepunk.sensordb.SensorDatabaseImpl.java

public SensorDatabaseImpl(Context context, String name) {
    mOpenHelper = new SQLiteOpenHelper(context, name, null, DbVersions.CURRENT) {
        @Override/*from  w w  w . j a  va2s.c om*/
        public void onCreate(SQLiteDatabase db) {
            db.execSQL(ScalarSensorsTable.CREATION_SQL);
            db.execSQL(ScalarSensorsTable.INDEX_SQL);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            while (oldVersion != newVersion) {
                if (oldVersion == DbVersions.V1_START) {
                    db.execSQL(ScalarSensorsTable.INDEX_SQL);
                    oldVersion = DbVersions.V2_INDEX;
                } else if (oldVersion == DbVersions.V2_INDEX) {
                    db.execSQL("ALTER TABLE " + ScalarSensorsTable.NAME + " ADD COLUMN "
                            + ScalarSensorsTable.Column.RESOLUTION_TIER + " INTEGER DEFAULT 0;");
                    oldVersion = DbVersions.V3_TIER;
                }
            }
        }
    };
}