如何升级新表和现有应用程序?

发布于 2024-12-18 00:35:16 字数 260 浏览 0 评论 0原文

朋友,

我已经发布了一个现有的应用程序,在升级过程中,我想向我的数据库添加一个新表,但在升级应用程序时也不会丢失其他表中的数据。有人可以告诉我(但如果你也能向我展示一些例子)这是如何完成的以及如何测试它。因为我浏览过论坛,但主要是关于添加新列等的讨论。我认为我必须使用 alter table 以某种方式完成此操作,但我并不理解所有内容。如果您能告诉我这个过程的步骤,我将非常感激。我已经使用了 DBAdapter 类扩展 SQLiteOpenHelper。接受我的问题并尽快给我解决方案。

Friends,

I have an existing apps published and during an upgrade, I want to add a new table to my database, but also not lose the data from the other tables when upgrading the application. Can someone tell me, (but if you could show me some example also) of how this is done and how to test it. Because I've looked through the forums but mainly there are discussions about adding a new column etc. I figured that I have to do it somehow with alter table, but I did not understand everything. If you can tell me the steps of this process I would really appreciate it.I have used DBAdapter class extends SQLiteOpenHelper.Accept my question and asap give me solution..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沒落の蓅哖 2024-12-25 00:35:16

一切都发生在您的类DBAdapter 中。在那里,您必须实现一个方法onUpgrade,它将新表添加到数据库中。这是执行此操作的框架:

class DBAdapter extends SQLiteOpenHelper {

    // Implement the other methods

    // This method is called when your application is being upgraded. 
    public void inUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i(TAG, "adding table to the database") ;
        db.execSQL("CREATE TABLE MyNewTable(_id INTEGER, name TEXT)") ;
        Log.i(TAG, "upgrade done") ;
    }

您可以查看类 的文档SQLiteOpenHelper

Everything happens in your class DBAdapter. There you must implement a method onUpgrade which adds your new table to the database. Here is a skeleton for doing this:

class DBAdapter extends SQLiteOpenHelper {

    // Implement the other methods

    // This method is called when your application is being upgraded. 
    public void inUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.i(TAG, "adding table to the database") ;
        db.execSQL("CREATE TABLE MyNewTable(_id INTEGER, name TEXT)") ;
        Log.i(TAG, "upgrade done") ;
    }

You may look at the documentation of the class SQLiteOpenHelper

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文