Create New Table In Existing Db In Separate Sqliteopenhelper Class
In my already created and deployed application, I've created a database MainDB, using a single class file which extended SQLiteOpenHelper, viz. public class BaseSQLiteOpenHelper ex
Solution 1:
First check the current database version for this database
privatefinalstaticStringDATABASE_NAME="MainDB";
privatestaticfinalintDATABASE_VERSION=1;
publicBaseSQLiteOpenHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
and increment the database version(DATABASE_VERSION), and add your new table query in on Upgrade and oncreate method like below.
@OverridepublicvoidonCreate(SQLiteDatabase db) {
db.execSQL("old query no need to change");
db.execSQL("Create your new table here");
}
@OverridepublicvoidonUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < 2) {
db.execSQL("Create your new table here as well this for update the old DB");
}
}
Done!!!
Post a Comment for "Create New Table In Existing Db In Separate Sqliteopenhelper Class"