<small id='HhGGD'></small><noframes id='HhGGD'>

        <bdo id='HhGGD'></bdo><ul id='HhGGD'></ul>
      <i id='HhGGD'><tr id='HhGGD'><dt id='HhGGD'><q id='HhGGD'><span id='HhGGD'><b id='HhGGD'><form id='HhGGD'><ins id='HhGGD'></ins><ul id='HhGGD'></ul><sub id='HhGGD'></sub></form><legend id='HhGGD'></legend><bdo id='HhGGD'><pre id='HhGGD'><center id='HhGGD'></center></pre></bdo></b><th id='HhGGD'></th></span></q></dt></tr></i><div id='HhGGD'><tfoot id='HhGGD'></tfoot><dl id='HhGGD'><fieldset id='HhGGD'></fieldset></dl></div>
      1. <tfoot id='HhGGD'></tfoot>

        <legend id='HhGGD'><style id='HhGGD'><dir id='HhGGD'><q id='HhGGD'></q></dir></style></legend>

        Android SQLite 数据库,为什么要删除表并在升级时重新创建

        Android SQLite Database, WHY drop table and recreate on upgrade(Android SQLite 数据库,为什么要删除表并在升级时重新创建)
        <i id='A5YQ3'><tr id='A5YQ3'><dt id='A5YQ3'><q id='A5YQ3'><span id='A5YQ3'><b id='A5YQ3'><form id='A5YQ3'><ins id='A5YQ3'></ins><ul id='A5YQ3'></ul><sub id='A5YQ3'></sub></form><legend id='A5YQ3'></legend><bdo id='A5YQ3'><pre id='A5YQ3'><center id='A5YQ3'></center></pre></bdo></b><th id='A5YQ3'></th></span></q></dt></tr></i><div id='A5YQ3'><tfoot id='A5YQ3'></tfoot><dl id='A5YQ3'><fieldset id='A5YQ3'></fieldset></dl></div>
        <legend id='A5YQ3'><style id='A5YQ3'><dir id='A5YQ3'><q id='A5YQ3'></q></dir></style></legend>
          <tbody id='A5YQ3'></tbody>
        1. <tfoot id='A5YQ3'></tfoot>
        2. <small id='A5YQ3'></small><noframes id='A5YQ3'>

              <bdo id='A5YQ3'></bdo><ul id='A5YQ3'></ul>

                • 本文介绍了Android SQLite 数据库,为什么要删除表并在升级时重新创建的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在我正在关注的教程以及我看到的更多地方,onUpgrade -> 如果存在则删除表,然后重新创建表.

                  In the tutorials I am following and a lot of more places I see this, onUpgrade -> drop table if exists, then recreate table.

                  这样做的目的是什么?

                  private static class DbHelper extends SQLiteOpenHelper{
                  
                      public DbHelper(Context context) {
                          super(context, DATABASE_NAME, null, DATABASE_VERSION);
                      }
                  
                      @Override
                      public void onCreate(SQLiteDatabase db) {
                          db.execSQL("CREATE TABLE " + DATABASE_TABLE + " (" +
                                  KEY_ROWID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
                                  KEY_NAME + " TEXT NOT NULL, " +
                                  KEY_HOTNESS + " TEXT NOT NULL);"
                          );  
                      }
                  
                      @Override
                      public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
                          db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE);
                          onCreate(db);
                      }       
                  }
                  

                  推荐答案

                  我同意,当您升级时,您应该在数据库中添加列或添加表.大多数 onupgrade 样本实际上都很糟糕,因为为什么我要删除所有这些数据然后重新创建表?我发现这篇博文我称之为Adams 增量更新方法.它还可以处理用户可能没有在每个版本中升级您的应用的情况.

                  I agree when you upgrade you should be adding columns or adding tables to your database. Most of the onupgrade samples actually suck because why am I deleting all this data then recreating the table? I found this blog entry I call it the Adams Incremental Update Method. It also handles situations where users may have not upgraded your app with each release.

                  这是一个关于 sqlite onupgrade 的不错的博客,它不会删除表.

                  这篇关于Android SQLite 数据库,为什么要删除表并在升级时重新创建的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Cannot solve SonarQube error quot;Make this line start at column 3quot;(无法解决 SonarQube 错误“使此行从第 3 列开始)
                  SonarQube for multi module project for Android(适用于 Android 的多模块项目的 SonarQube)
                  How to integrate sonarqube in android studio?(如何在 android studio 中集成 sonarqube?)
                  Android What is the easist way Upgrade Database for existing DB(Android 为现有数据库升级数据库的简单方法是什么)
                  Updating SQLite database android(更新 SQLite 数据库 android)
                  Android: onUpgrade not calling at database upgrade(Android:onUpgrade 不在数据库升级时调用)

                    <tfoot id='5PdIE'></tfoot>
                      <tbody id='5PdIE'></tbody>
                    • <bdo id='5PdIE'></bdo><ul id='5PdIE'></ul>

                        1. <legend id='5PdIE'><style id='5PdIE'><dir id='5PdIE'><q id='5PdIE'></q></dir></style></legend>
                        2. <small id='5PdIE'></small><noframes id='5PdIE'>

                            <i id='5PdIE'><tr id='5PdIE'><dt id='5PdIE'><q id='5PdIE'><span id='5PdIE'><b id='5PdIE'><form id='5PdIE'><ins id='5PdIE'></ins><ul id='5PdIE'></ul><sub id='5PdIE'></sub></form><legend id='5PdIE'></legend><bdo id='5PdIE'><pre id='5PdIE'><center id='5PdIE'></center></pre></bdo></b><th id='5PdIE'></th></span></q></dt></tr></i><div id='5PdIE'><tfoot id='5PdIE'></tfoot><dl id='5PdIE'><fieldset id='5PdIE'></fieldset></dl></div>