【发布时间】:2018-12-25 09:05:23
【问题描述】:
在 android studio 中发布我的新版 android 应用后,我遇到了问题。
问题出在这里: 我有一个带有 SQlite 数据库的测验应用程序,其中问题和答案已使用 SQLite 数据库浏览器填充。现在,当我向数据库表添加新问题并创建新的数据库版本时,数据库似乎没有反映在更新的应用程序中。 我在网上找到的有关数据库升级的教程仅强调在应用程序启动时创建的数据库。喜欢this
问题:只有在 SQLite 中将新记录添加到现有表时,如何处理数据库升级?
我尝试过的:
(1) 在 DatabaseOpenHelper OnUpgrade() 方法中,我删除了添加新记录的表。
结果:应用崩溃的活动开始
(2) 将OnUpdrade() 方法留空。
结果:新添加的记录没有反映
额外数据:DatabaseOpenHelper OnCreate() 方法也是空的
代码
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("drop table if exists "+ DatabaseDescription.LectureNotes.TABLE_NAME);
db.execSQL("drop table if exists "+ DatabaseDescription.QuestionAnswer.TABLE_NAME);
db.execSQL("drop table if exists "+ DatabaseDescription.Test.TABLE_NAME);
db.execSQL("drop table if exists "+ DatabaseDescription.Subjects.TABLE_NAME);
db.execSQL("drop table if exists "+ DatabaseDescription.Topics.TABLE_NAME);
db.execSQL("drop table if exists "+ DatabaseDescription.Year.TABLE_NAME);
}
【问题讨论】:
标签: android android-sqlite sqliteopenhelper