How can I add new columns to a SQLite database after the Android app is released?(发布 Android 应用程序后,如何向 SQLite 数据库添加新列?)
问题描述
我想向 SQLite 数据库添加新列,但我已经在 Play Store 上发布了我的应用,所以如果我对其进行编辑,用户需要卸载并重新安装该应用,但我不希望那样.请帮忙,我是 Android 新手.
(1) 增加(或简单地更改)您的数据库版本
(2) 会导致onUpgrade()
方法调用
(3) 在 onUpgrade()
方法中执行您的查询(用于添加新列).
本博客中提到了正确的做法.p>
有时用户可能会从 1.1 版本更新到 1.5 版本.换句话说,他们可能会跳过 1.1 到 1.5 之间的其他版本.您可能会在 1.1 到 1.5 之间更改数据库几次.因此,为了让用户从所有数据库更改中受益,您需要采用如下 onUpgrade() 方法.
@Override公共无效 onUpgrade(SQLiteDatabase db,int oldVersion,int newVersion){如果(旧版本 <2){db.execSQL(DATABASE_ALTER_TEAM_1);}如果(旧版本 <3){db.execSQL(DATABASE_ALTER_TEAM_2);}}
希望对你有帮助.
I want to add new columns to a SQLite database, but I already released my app on the Play Store so, if I edit it, users need to uninstall and reinstall the app, but I don't want that. Please, help, I am new to Android.
(1) Increment (or simply change) your database version
(2) It would lead to onUpgrade()
method call
(3) Execute your query(for adding a new column) in the onUpgrade()
method.
The Right Way of doing is mentioned here in this blog.
Sometimes user may update the version 1.5 from the version 1.1.In other words, They may skip the other versions between the 1.1 to 1.5. You might changed database couple of time between 1.1 to 1.5. So in order to give the user a benefit of all the database changes, you need to take of onUpgrade() method as below.
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if (oldVersion < 2) {
db.execSQL(DATABASE_ALTER_TEAM_1);
}
if (oldVersion < 3) {
db.execSQL(DATABASE_ALTER_TEAM_2);
}
}
Hope it helps.
这篇关于发布 Android 应用程序后,如何向 SQLite 数据库添加新列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:发布 Android 应用程序后,如何向 SQLite 数据库添加新列?


基础教程推荐
- Android:对话框关闭而不调用关闭 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01