开发者

How to Upgrade My database in app up gradation process?

开发者 https://www.devze.com 2023-04-06 04:56 出处:网络
I am developing an app where i have to update my data base when user selects app upgrade process. Simply i want to do a database changes when my app is migrated to new version.

I am developing an app where i have to update my data base when user selects app upgrade process. Simply i want to do a database changes when my app is migrated to new version. How to do this job please suggest.

AND

I am developing an app to which already have some versions in market now i want to release an update to my app but i haven't got any info how to do it. Is it like a normal apk file creation?? if it is the开发者_StackOverflow社区n do i need to use any adb commands to test this apk file?? Please Suggest..!!!

Thanks, Ram.


Please see this doc for information on SQLiteOpenHelper. It provides the functionality for you to do updates, and onCreates (when db is created).

The way the onUpgrade method should work is that you pass it the db, the old version number, and the new version number, so you can do comparisons of that. You would do something like this:

public void onUpgrade(SQLiteDatabase db, int oldVer, int newVer)
{
    if (oldVer == 1 && newVer == 2)
    {
        db.exec("ALTER TABLE tbl_names RENAME TO names");
        //.....

    }


}

The version number is generally stored as a class level variable somewhere either in your SQLiteOpenHelper or your main database helper.

This will require a restart of your application. If you are referring to the ability of a user to do an in-app upgrade then this might not work for you.


If you are using SQLiteOpenHelper (which you should), just override the onUpgrade method. Then, every time your database structure changes, you up the version number of the database. Read this topic on data storage form the dev guide. Also, look at the NotePad sample which implements this.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号