Code example for SQLiteDatabase

Methods: execSQLsetVersion

0
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(PROFILES_TABLE_CREATE);
	} 
	 
	private void upgrade6to7(SQLiteDatabase db){
		db.execSQL(PROFILES_TABLE_UPGRADE_6_7_1);
		db.execSQL(PROFILES_TABLE_UPGRADE_6_7_2);
		db.execSQL(PROFILES_TABLE_UPGRADE_6_7_3);
		db.execSQL(PROFILES_TABLE_UPGRADE_6_7_4);
	} 
	 
	/* (non-Javadoc) 
	 * @see android.database.sqlite.SQLiteOpenHelper#onUpgrade(android.database.sqlite.SQLiteDatabase, int, int) 
	 */ 
	@Override 
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (oldVersion == 2) {
			db.execSQL(PROFILES_TABLE_UPGRADE_2_3);
			db.execSQL(PROFILES_TABLE_UPGRADE_3_4);
			db.execSQL(PROFILES_TABLE_UPGRADE_4_5);
			db.execSQL(PROFILES_TABLE_UPGRADE_5_6);
			upgrade6to7(db);
			db.setVersion(DATABASE_VERSION);
		} else if (oldVersion == 3) {
			db.execSQL(PROFILES_TABLE_UPGRADE_3_4);
			db.execSQL(PROFILES_TABLE_UPGRADE_4_5);
			db.execSQL(PROFILES_TABLE_UPGRADE_5_6);
			upgrade6to7(db);
			db.setVersion(DATABASE_VERSION);
		} else if (oldVersion == 4){
			db.execSQL(PROFILES_TABLE_UPGRADE_4_5);
			db.execSQL(PROFILES_TABLE_UPGRADE_5_6);
			upgrade6to7(db);
			db.setVersion(DATABASE_VERSION);
		} else if (oldVersion == 5){
			db.execSQL(PROFILES_TABLE_UPGRADE_5_6);
			upgrade6to7(db);
			db.setVersion(DATABASE_VERSION);
		} else if(oldVersion == 6){
			upgrade6to7(db);
			db.setVersion(DATABASE_VERSION);
		} else { 
			db.execSQL("DROP TABLE IF EXISTS " + PROFILES_TABLE_NAME);
			db.setVersion(0);
		} 
		if(oldVersion < newVersion)