android - How to initiate the call onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion)? -
i need upgrade android sqlite database version 1 version 2. not understand how call public void onupgrade(sqlitedatabase db, int oldversion, int newversion)
is initiated? how , when method called? don't understand pass version number 2?
[edit] think need clarify question. here class:
public class mysqliteopenhelper extends sqliteopenhelper { public mysqliteopenhelper(context context){ super(context, constants.db_name, null, 1); } public mysqliteopenhelper(context context, int version){ super(context, constants.db_name, null, version); } public mysqliteopenhelper(context context, string name, cursorfactory factory, int version) { super(context, constants.db_name, factory, version); // todo auto-generated constructor stub } public mysqliteopenhelper(context context, string name, cursorfactory factory, int version, databaseerrorhandler errorhandler) { super(context, constants.db_name, factory, version, errorhandler); // todo auto-generated constructor stub } public void oncreate(sqlitedatabase db) { // creation stuff } public void onupgrade(sqlitedatabase db, int oldversion, int newversion) { // upgrade stuff } }
so, how android trigger onupgrade?
the sqliteopenhelper
constructor takes name , version number, , helper invoke oncreate
or onupgrade
callback necessary. need maintain database version numbers yourself, bumping version number when schema change necessary.
when need update database version 1 version 2 change
super(context, constants.db_name, null, 1);
to
super(context, constants.db_name, null, 2);
then in onupgrade
method drop tables, add tables, or else needed upgrade 1 2. onupgrade
invoked first time sqliteopenhelper instantiated after version number changes.
Comments
Post a Comment