上更新部署的Android应用程序升级数据库 [英] Upgrade database on deployed Android app on update
问题描述
我有部署在Play商店的应用程序。我使用的SQLite数据库。这个应用程序是玩店有DB版本3.现在为即将到来的更新我想另一列添加到数据库中的表,所以我要以增加分贝版本4.我已经作出了我的onUpgrade内部逻辑( )方法。我只是想知道你如何找到它,你周围的这种情况怎么弄,甚至像一个与数据库版本5.我只是希望得到你的意见进一步更新。非常感谢。
@覆盖
公共无效onUpgrade(SQLiteDatabase分贝,INT oldVersion,诠释静态网页){
//部署Play商店版本时为3
//更新数据库表。并加大在上面DB版本 字符串queryForDBVersion4 =ALTER TABLE+ TABLE_NAME +ADD noteColor TEXT;
//字符串queryForDBVersion5; 开关(静态网页){
情况4:
db.execSQL(queryForDBVersion4);
打破;
//案例5://以备将来使用
//如果(oldVersion == 4){db.execSQL(queryForDBVersion5);}
//其他{
// db.execSQL(queryForDBVersion4);
// db.execSQL(queryForDBVersion5);
//}
//突破;
//案例6:等等...
}
}
我preFER这种方式,因为它是干净和简单的:
公共无效onUpgrade(最终SQLiteDatabase分贝,INT oldVersion,诠释静态网页){ 如果(oldVersion 2){
//升级从V1到V2
} 如果(oldVersion 3;){
//从升级到V2 V3
} 如果(oldVersion 4;){
//从升级到V3 V4
}}
使用这个工具,数据库将逐步升级。
I have an app deployed on play store. I use SQLite database. The app that is on play store have db version 3. Now for the upcoming update I want to add another column to the table in the database, so I am going to increase db version to 4. I have made that logic inside my onUpgrade() method. I am just wondering how you find it, how you get around this kind of situation, for even further updates like the one with db version 5. I just want to get your opinions. Thanks a lot.
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
//when deployed to play store version was 3
//update db table. And increase db version on top
String queryForDBVersion4 = "ALTER TABLE " + TABLE_NAME + " ADD noteColor TEXT";
// String queryForDBVersion5;
switch (newVersion){
case 4:
db.execSQL(queryForDBVersion4);
break;
// case 5: //FOR FUTURE USE
// if(oldVersion==4){db.execSQL(queryForDBVersion5);}
// else{
// db.execSQL(queryForDBVersion4);
// db.execSQL(queryForDBVersion5);
// }
// break;
// case 6: SO ON...
}
}
I prefer this way as it is clean and simple:
public void onUpgrade(final SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < 2){
// Upgrade from V1 to V2
}
if (oldVersion < 3){
// Upgrade from V2 to V3
}
if (oldVersion < 4){
// Upgrade from V3 to V4
}
}
Using this, the database will incrementally upgrade.
这篇关于上更新部署的Android应用程序升级数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!