ORMLite update of the database

前端 未结 4 742
陌清茗
陌清茗 2020-12-09 04:18

I\'m actually developing an app which is using ORMLite library (which is wonderful btw) but I\'m a beginner using it.

I have a question about the update of the datab

4条回答
  •  感动是毒
    2020-12-09 05:07

    Little information, is not clear whether the changes you have table structure.

    a) If you do not change the database structure.

    1 In the new version of your program when you start checking a previously saved version (eg in preferences) with the current (see PackageManager.getPackageInfo)

    saved = 0 - User just installed the new version

    saved < current - User updates your program

    2 Add new data to base

    3 Save current version on preferences

    b) If the table structure has changed (added or remove fields)

    1 Increase the version number of your database (see your extends OrmLiteSqliteOpenHelper class)

    2 When the user first runs into your program, method 'onUpgrade' will be called (in your extends OrmLiteSqliteOpenHelper class) which will be transferred to old and new version numbers.

    • Read the existing data in the cache (temp)
    • recreate table
    • Add the data from the cache + your new data

提交回复
热议问题