Android SQLite onupgrade从数据库中删除表 [英] Android Sqlite onupgrade delete table from database

查看:217
本文介绍了Android SQLite onupgrade从数据库中删除表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中使用预填充的数据库,并且创建了两个表Dictionary和Bookmark表. 字典表包含我要显示的数据,如果用户将某些内容标记为收藏夹",则书签"表将保存数据. 我想做的是调用onupgrade方法时,更新字典表中的数据并将数据保存到书签表中.谁能给我榜样.

I am using prepopulated database in my app and i have created two tables, Dictionary and Bookmark table . Dictionary table has the data i want to show and the Bookmark table saves the data if the user marks something as Favourite. What i want to do is when onupgrade method is called update the data in dictionary table and save the data in Bookmark table. Can anyone give me example to do that.

P.S.我没有使用Sqlite的经验

P.S. I don't have much experience with Sqlite

推荐答案

以下是用于回答上一个问题(下面的链接)的代码,该代码经过修改以包括一个新方法,即 restoreTable >在 DatabaseAssetHandler.java

The following is the code as used for the answer to a previous question (link below) amended to include a new method, namely restoreTable in DatabaseAssetHandler.java

该方法将从传递的数据库中复制任何表(传递时)(从资产文件夹复制新数据库时生成(根据上一个答案)).它不包括检查传递的表是否存在的复杂性.

The method will copy any table, as passed, from the backed-up database (made when copying a new database form the asset folder (as per the previous answer)). It does not include the complications of checking to see if the passed table exists.

它将打开两个SQLiteDatabase实例,即新数据库和旧备份数据库.从旧数据库中提取所有行,并将它们插入新数据库中具有相同名称的表中.

It opens two SQLiteDatabase instances the new database and the old backed up database. Extracts all rows from the old database and inserts them into table with the same name in the new database.

此方法本身就是:-

/**
 *
 * @param context   The context so that the respective package is used
 * @param dbname    The name of the database (the old will have -backup appended)
 * @param table     The table from which to copy the data
 */
public static void restoreTable(Context context, String dbname, String table) {
    ContentValues cv = new ContentValues();
    SQLiteDatabase dbnew = SQLiteDatabase.openDatabase(context.getDatabasePath(dbname).toString(), null,SQLiteDatabase.OPEN_READWRITE);
    SQLiteDatabase dbold = SQLiteDatabase.openDatabase(context.getDatabasePath(dbname + backup).toString(),null,SQLiteDatabase.OPEN_READONLY);
    Cursor csr = dbold.query(table,null,null,null,null,null,null);
    dbnew.beginTransaction();
    while (csr.moveToNext()) {
        cv.clear();
        int offset = 0;
        for (String column: csr.getColumnNames()) {
            switch (csr.getType(offset++)){
                case Cursor.FIELD_TYPE_NULL:
                    break;
                case Cursor.FIELD_TYPE_INTEGER:
                    cv.put(column,csr.getLong(csr.getColumnIndex(column)));
                    break;
                case Cursor.FIELD_TYPE_FLOAT:
                    cv.put(column,csr.getFloat(csr.getColumnIndex(column)));
                    break;
                case Cursor.FIELD_TYPE_STRING:
                    cv.put(column,csr.getString(csr.getColumnIndex(column)));
                    break;
                case Cursor.FIELD_TYPE_BLOB:
                    cv.put(column,csr.getBlob(csr.getColumnIndex(column)));
            }
        }
        dbnew.insert(DatabaseHelper.TABLE_BOOKMARK,null,cv);
    }
    dbnew.setTransactionSuccessful();
    dbnew.endTransaction();
    csr.close();
    dbnew.close();
    dbold.close();
}

  • 该方法需要添加到DatabaseAssetHandler代码中来自上一个答案.
    • This method would need to be added to the DatabaseAssetHandler code from the previous answer.
    • 为了便于测试上述内容,对 DatabaseHelper.java 进行了一些更改,现在为:-

      To facilitate testing of the above a few changes have been made to DatabaseHelper.java, this is now :-

      public class DatabaseHelper extends SQLiteOpenHelper {
      
          private  static final String DB_NAME = "dictionary.db";
          private static final int DB_VERSION = 2;
          public static final String TABLE_DICTIONARY = "dictionary";
          public static final String TABLE_BOOKMARK= "bookmark";
          public static final String COL_ID = "id";
          public static final String COL_WORD = "word";
          public static final String COL_DEFINITION = "definition";
          public static final String COL_WORID = "wordid"; //<<<<<<<<<< ADDED
          public Context mcontext;
          public SQLiteDatabase mDatabase;
      
          public DatabaseHelper(Context context) {
              super(context, DB_NAME, null, DB_VERSION);
              this.mcontext = context;
              Log.d("DBVERSION","The Database Version (as hard coded) is " + String.valueOf(DB_VERSION));
      
              int dbversion = DatabaseAssetHandler.getVersionFromDBFile(context,DB_NAME);
              Log.d("DBVERSION","The Database Version (as per the database file) is " + String.valueOf(dbversion));
      
              // Copy the Database if no database exists
              if (!DatabaseAssetHandler.checkDataBase(context,DB_NAME)) {
                  DatabaseAssetHandler.copyDataBase(context,DB_NAME,true,DB_VERSION);
              } else {
                  if (DB_VERSION > dbversion && DatabaseAssetHandler.checkDataBase(context, DB_NAME)) {
                      DatabaseAssetHandler.copyDataBase(context, DB_NAME, true, DB_VERSION);
                      DatabaseAssetHandler.restoreTable(context,DB_NAME,TABLE_BOOKMARK); //<<<<<<<<<< ADDED for keeping the BOOKMARKS
                      DatabaseAssetHandler.clearForceBackups(context, DB_NAME); // Clear the backups
                  }
              }
              mDatabase = this.getWritableDatabase();
          }
      
          @Override
          public void onCreate(SQLiteDatabase db) {
          }
      
          @Override
          public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
          }
      
          public void openDatabase() throws SQLException {
              mDatabase = this.getWritableDatabase();
          }
      
          //<<<<<<<<<< ADDED to allow some bookmarks to be added
          public long addBookMark(long wordid) {
              ContentValues cv = new ContentValues();
              cv.put(DatabaseHelper.COL_WORID,wordid);
              return mDatabase.insert(DatabaseHelper.TABLE_BOOKMARK,null,cv);
          }
      
          // Added to retrieve the database name (could make DB_NAME public)
          public String getDBNAME() {
              return this.DB_NAME;
          }
      
          //ADDED to dump the bookmarks along with the related word and definition
          public void logBookmarksWithWord() {
      
              String table_part = TABLE_BOOKMARK +
                      " JOIN " + TABLE_DICTIONARY +
                      " ON " + COL_WORID +
                      " = " + TABLE_DICTIONARY + "." + COL_ID;
              String[] columns = new String[]{TABLE_BOOKMARK + "." + COL_ID, COL_WORID, COL_WORD, COL_DEFINITION};
              Cursor csr = mDatabase.query(table_part,columns,null,null,null,null,COL_WORD);
              DatabaseUtils.dumpCursor(csr);
              csr.close();
          }
      
          @Override
          public synchronized void close() {
              if (mDatabase != null)
                  mDatabase.close();
              super.close();
          }
      }
      

      根据先前的答案,使用了相同的2个版本的数据库.但是,调用活动中添加了其他代码:a)从资产文件夹复制数据库时添加一些书签,并且b)始终将书签输出到日志中(以显示它们已被保留) ).

      The same 2 versions of databases were used as per the previous answer. However, the invoking activity had additional code added to a) add some bookmarks when the the DB is copied from the assets folder, and to b) always output the bookmarks to the log (to show they are retained).

      使用的调用活动是:-

      public class MainActivity extends AppCompatActivity {
      
          DatabaseHelper mDBHlpr;
      
          @Override
          protected void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
              mDBHlpr = new DatabaseHelper(this);
              Cursor csr = mDBHlpr.getWritableDatabase().query(
                      DatabaseHelper.TABLE_DICTIONARY,
                      null,null,null,null,null,null
              );
              DatabaseUtils.dumpCursor(csr);
              //<<<<<<<<<< ADDED CODE
              // Add a couple of bookmarks only if database is copied for testing
              if (DatabaseUtils.queryNumEntries(mDBHlpr.mDatabase,DatabaseHelper.TABLE_BOOKMARK) < 1) {
                  mDBHlpr.addBookMark(1);
                  mDBHlpr.addBookMark(3);
              }
              // Always dump the bookmarks to the log
              mDBHlpr.logBookmarksWithWord();
              //<<<<<<<<<< END OF ADDED CODE
              csr.close();
          }
      }
      

      • 请注意,已假设书签表已存在(尽管它为空)(尽管它没有).如果它不存在,那么它将失败.
      • 此运行用于新安装的App,DB_VERSION为1(因此从资产文件夹复制了预先存在的数据库(初始版本).

        This run is for a new installation of the App and DB_VERSION is 1 (so the pre-exisiting database (initial version) is copied from the assets folder).

        04-22 18:06:17.603 8734-8734/? D/DBVERSION: The Database Version (as hard coded) is 1
        04-22 18:06:17.603 8734-8734/? D/DBVERSION: The Database Version (as per the database file) is -666666666
        04-22 18:06:17.603 8734-8734/? D/DBPATH: DB Path is /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
        04-22 18:06:17.603 8734-8734/? D/COPYDATABASE: Initiated Copy of the database file dictionary.db from the assets folder.
        04-22 18:06:17.603 8734-8734/? D/COPYDATABASE: Asset file dictionary.db found so attmepting to copy to /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
        04-22 18:06:17.604 8734-8734/? D/COPYDATABASE: Attempting copy of block 1 which has 4096 bytes.
        04-22 18:06:17.604 8734-8734/? D/COPYDATABASE: Attempting copy of block 2 which has 4096 bytes.
        04-22 18:06:17.604 8734-8734/? D/COPYDATABASE: Attempting copy of block 3 which has 4096 bytes.
        04-22 18:06:17.604 8734-8734/? D/COPYDATABASE: Finished copying Database dictionary.db from the assets folder, to  /data/user/0/m.example.so55711282dictionary/databases/dictionary.db12288were copied, in 3 blocks of size 4096.
        04-22 18:06:17.604 8734-8734/? D/COPYDATABASE: All Streams have been flushed and closed.
        04-22 18:06:17.625 8734-8734/? I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@3396ef
        04-22 18:06:17.625 8734-8734/? I/System.out: 0 {
        04-22 18:06:17.625 8734-8734/? I/System.out:    id=1
        04-22 18:06:17.625 8734-8734/? I/System.out:    word=Apple
        04-22 18:06:17.625 8734-8734/? I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:06:17.625 8734-8734/? I/System.out: }
        04-22 18:06:17.625 8734-8734/? I/System.out: 1 {
        04-22 18:06:17.625 8734-8734/? I/System.out:    id=2
        04-22 18:06:17.625 8734-8734/? I/System.out:    word=Bucket
        04-22 18:06:17.625 8734-8734/? I/System.out:    definition=Hand held container with carrying hanlde.
        04-22 18:06:17.625 8734-8734/? I/System.out: }
        04-22 18:06:17.625 8734-8734/? I/System.out: <<<<<
        
        
        04-22 18:06:17.631 8734-8734/? D/BOOKMARKDUMP: Dumping the bookmarks table to the log.
        04-22 18:06:17.631 8734-8734/? I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@9ce45fc
        04-22 18:06:17.631 8734-8734/? I/System.out: 0 {
        04-22 18:06:17.631 8734-8734/? I/System.out:    id=1
        04-22 18:06:17.631 8734-8734/? I/System.out:    wordid=1
        04-22 18:06:17.631 8734-8734/? I/System.out:    word=Apple
        04-22 18:06:17.631 8734-8734/? I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:06:17.631 8734-8734/? I/System.out: }
        04-22 18:06:17.631 8734-8734/? I/System.out: <<<<<
        

        运行2

        只需再次运行就不会更改,因此不存在复制书签.

        Run 2

        Simply run again no changes, so no copy bookmark exists.

        04-22 18:40:56.304 8858-8858/m.example.so55711282dictionary D/DBVERSION: The Database Version (as hard coded) is 1
        04-22 18:40:56.304 8858-8858/m.example.so55711282dictionary D/DBVERSION: The Database Version (as per the database file) is 1
        04-22 18:40:56.304 8858-8858/m.example.so55711282dictionary D/DBPATH: DB Path is /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
        04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@11697ce
        04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: 0 {
        04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out:    id=1
        04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out:    word=Apple
        04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: }
        04-22 18:40:56.308 8858-8858/m.example.so55711282dictionary I/System.out: 1 {
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out:    id=2
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out:    word=Bucket
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out:    definition=Hand held container with carrying hanlde.
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: }
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: <<<<<
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary D/BOOKMARKDUMP: Dumping the bookmarks table to the log.
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@3396ef
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: 0 {
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out:    id=1
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out:    wordid=1
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out:    word=Apple
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: }
        04-22 18:40:56.309 8858-8858/m.example.so55711282dictionary I/System.out: <<<<<
        

        运行3

        数据库引入的新版本DB_VERSION更改为2(更多单词,因此ID为3的单词的书签具有相关单词).复制了新版本的数据库.这两个书签已保留.

        Run 3

        New version of database introduced DB_VERSION changed to 2 (some more words so the bookmark for word with the id 3 has a related word). New version of DB copied. The two bookmarks have been retained.

        04-22 18:44:58.749 8975-8975/? D/DBVERSION: The Database Version (as hard coded) is 2
        04-22 18:44:58.749 8975-8975/? D/DBVERSION: The Database Version (as per the database file) is 1
        04-22 18:44:58.749 8975-8975/? D/DBPATH: DB Path is /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
        04-22 18:44:58.749 8975-8975/? D/DBPATH: DB Path is /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
        04-22 18:44:58.750 8975-8975/? D/COPYDATABASE: Initiated Copy of the database file dictionary.db from the assets folder.
        04-22 18:44:58.750 8975-8975/? D/COPYDATABASE: Asset file dictionary.db found so attmepting to copy to /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
        04-22 18:44:58.750 8975-8975/? D/COPYDATABASE: Attempting copy of block 1 which has 4096 bytes.
        04-22 18:44:58.750 8975-8975/? D/COPYDATABASE: Attempting copy of block 2 which has 4096 bytes.
        04-22 18:44:58.750 8975-8975/? D/COPYDATABASE: Attempting copy of block 3 which has 4096 bytes.
        04-22 18:44:58.750 8975-8975/? D/COPYDATABASE: Finished copying Database dictionary.db from the assets folder, to  /data/user/0/m.example.so55711282dictionary/databases/dictionary.db12288were copied, in 3 blocks of size 4096.
        04-22 18:44:58.750 8975-8975/? D/COPYDATABASE: All Streams have been flushed and closed.
        04-22 18:44:58.783 8975-8975/? I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@10862da
        04-22 18:44:58.784 8975-8975/? I/System.out: 0 {
        04-22 18:44:58.784 8975-8975/? I/System.out:    id=1
        04-22 18:44:58.784 8975-8975/? I/System.out:    word=Apple
        04-22 18:44:58.784 8975-8975/? I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:44:58.784 8975-8975/? I/System.out: }
        04-22 18:44:58.784 8975-8975/? I/System.out: 1 {
        04-22 18:44:58.784 8975-8975/? I/System.out:    id=2
        04-22 18:44:58.784 8975-8975/? I/System.out:    word=Bucket
        04-22 18:44:58.784 8975-8975/? I/System.out:    definition=Hand held container with carrying hanlde.
        04-22 18:44:58.784 8975-8975/? I/System.out: }
        04-22 18:44:58.784 8975-8975/? I/System.out: 2 {
        04-22 18:44:58.784 8975-8975/? I/System.out:    id=3
        04-22 18:44:58.784 8975-8975/? I/System.out:    word=Yelllow
        04-22 18:44:58.784 8975-8975/? I/System.out:    definition=A colour.
        04-22 18:44:58.784 8975-8975/? I/System.out: }
        04-22 18:44:58.784 8975-8975/? I/System.out: 3 {
        04-22 18:44:58.784 8975-8975/? I/System.out:    id=4
        04-22 18:44:58.784 8975-8975/? I/System.out:    word=Zebra
        04-22 18:44:58.784 8975-8975/? I/System.out:    definition=A balck and white, horse-like animal.
        04-22 18:44:58.784 8975-8975/? I/System.out: }
        04-22 18:44:58.784 8975-8975/? I/System.out: <<<<<
        04-22 18:44:58.784 8975-8975/? D/BOOKMARKDUMP: Dumping the bookmarks table to the log.
        04-22 18:44:58.785 8975-8975/? I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@d4cb30b
        04-22 18:44:58.785 8975-8975/? I/System.out: 0 {
        04-22 18:44:58.785 8975-8975/? I/System.out:    id=1
        04-22 18:44:58.785 8975-8975/? I/System.out:    wordid=1
        04-22 18:44:58.785 8975-8975/? I/System.out:    word=Apple
        04-22 18:44:58.785 8975-8975/? I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:44:58.785 8975-8975/? I/System.out: }
        04-22 18:44:58.785 8975-8975/? I/System.out: 1 {
        04-22 18:44:58.785 8975-8975/? I/System.out:    id=2
        04-22 18:44:58.785 8975-8975/? I/System.out:    wordid=3
        04-22 18:44:58.785 8975-8975/? I/System.out:    word=Yelllow
        04-22 18:44:58.785 8975-8975/? I/System.out:    definition=A colour.
        04-22 18:44:58.785 8975-8975/? I/System.out: }
        04-22 18:44:58.785 8975-8975/? I/System.out: <<<<<
        

        运行4

        什么都没有改变,所以仍然没有保留数据库复制书签.

        RUN 4

        Nothing changed, so no DB copy bookmarks still retained.

        04-22 18:47:19.300 9047-9047/m.example.so55711282dictionary D/DBVERSION: The Database Version (as hard coded) is 2
        04-22 18:47:19.300 9047-9047/m.example.so55711282dictionary D/DBVERSION: The Database Version (as per the database file) is 2
        04-22 18:47:19.300 9047-9047/m.example.so55711282dictionary D/DBPATH: DB Path is /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
        04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@11697ce
        04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out: 0 {
        04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out:    id=1
        04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out:    word=Apple
        04-22 18:47:19.302 9047-9047/m.example.so55711282dictionary I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 1 {
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    id=2
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    word=Bucket
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    definition=Hand held container with carrying hanlde.
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 2 {
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    id=3
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    word=Yelllow
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    definition=A colour.
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 3 {
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    id=4
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    word=Zebra
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    definition=A balck and white, horse-like animal.
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: <<<<<
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary D/BOOKMARKDUMP: Dumping the bookmarks table to the log.
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@3396ef
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 0 {
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    id=1
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    wordid=1
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    word=Apple
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: 1 {
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    id=2
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    wordid=3
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    word=Yelllow
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out:    definition=A colour.
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: }
        04-22 18:47:19.303 9047-9047/m.example.so55711282dictionary I/System.out: <<<<<
        

        运行5

        应用已卸载.使用了新版本.作为新DB BUT版本添加的书签是最新版本,即2

        RUN 5

        App uninstalled. New version used.Bookmarks added as new DB BUT version is latest i.e. 2

        04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/DBVERSION: The Database Version (as hard coded) is 2
        04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/DBVERSION: The Database Version (as per the database file) is -666666666
        04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/DBPATH: DB Path is /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
        04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Initiated Copy of the database file dictionary.db from the assets folder.
        04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Asset file dictionary.db found so attmepting to copy to /data/user/0/m.example.so55711282dictionary/databases/dictionary.db
        04-22 18:50:55.297 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Attempting copy of block 1 which has 4096 bytes.
        04-22 18:50:55.298 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Attempting copy of block 2 which has 4096 bytes.
        04-22 18:50:55.298 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Attempting copy of block 3 which has 4096 bytes.
        04-22 18:50:55.298 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: Finished copying Database dictionary.db from the assets folder, to  /data/user/0/m.example.so55711282dictionary/databases/dictionary.db12288were copied, in 3 blocks of size 4096.
        04-22 18:50:55.298 9243-9243/m.example.so55711282dictionary D/COPYDATABASE: All Streams have been flushed and closed.
        04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@3396ef
        04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: 0 {
        04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out:    id=1
        04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out:    word=Apple
        04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: }
        04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out: 1 {
        04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out:    id=2
        04-22 18:50:55.320 9243-9243/m.example.so55711282dictionary I/System.out:    word=Bucket
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out:    definition=Hand held container with carrying hanlde.
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: }
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: 2 {
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out:    id=3
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out:    word=Yelllow
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out:    definition=A colour.
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: }
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: 3 {
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out:    id=4
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out:    word=Zebra
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out:    definition=A balck and white, horse-like animal.
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: }
        04-22 18:50:55.321 9243-9243/m.example.so55711282dictionary I/System.out: <<<<<
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary D/BOOKMARKDUMP: Dumping the bookmarks table to the log.
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@9ce45fc
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: 0 {
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out:    id=1
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out:    wordid=1
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out:    word=Apple
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out:    definition=Thing that drops from an Apple Tree.
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: }
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: 1 {
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out:    id=2
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out:    wordid=3
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out:    word=Yelllow
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out:    definition=A colour.
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: }
        04-22 18:50:55.328 9243-9243/m.example.so55711282dictionary I/System.out: <<<<<
        

        这篇关于Android SQLite onupgrade从数据库中删除表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆