문제

Im using ORMLite as the data persistence option in my android application. I want to ensure data backup and recovery on re-install. If i make some changes in the app logic and re-install the application the data is unchanged, but how can i handle the schema change, i the new version of app has some database schema changes how can i handle the import of user data into newer schema. Please guide me towards possible solutions i can avail.

Regards.

도움이 되었습니까?

해결책

but how can i handle the schema change, i the new version of app has some database schema changes how can i handle the import of user data into newer schema

If I'm understanding the question, it's not about import but it is about schema updating when you install a new version of the OS. ORMLite actually has a section about that:

http://ormlite.com/docs/upgrade-schema

To quote, you need to override the onUpgrade(...) method and do something like:

abstract void onUpgrade(SQLiteDatabase database,
      ConnectionSource connectionSource, int oldVersion, int newVersion) {
    if (oldVersion < 2) {
      // we added the age column in version 2
      dao.executeRaw("ALTER TABLE `account` ADD COLUMN age INTEGER;");
    }
    if (oldVersion < 3) {
      // we added the weight column in version 3
      dao.executeRaw("ALTER TABLE `account` ADD COLUMN weight INTEGER;");
    }
}

If I'm not getting your question then please edit your post and I'll add more information.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top