0

I have an application published in the android market, and now I want to make a new version with changes in the database. The problem is, my version of the app that is already published has this onUpgrade method:

    @Override
    public void onUpgrade(SQLiteDatabase _db, int _oldVersion, int _newVersion) {
    Log.w("TaskDBAdapter", "Upgrading from version " +
    _oldVersion + " to " +
    _newVersion + ", which will destroy all old data");
    // Drop the old table.
    _db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_1);
    _db.execSQL("DROP TABLE IF EXISTS " + DATABASE_TABLE_2);
    // Create a new one.
    onCreate(_db);
    }

Because I want to add a new table, I know that I have to make some changes here to keep the data from the tables I already created with the previous version. So what onUpgrade method will be called, from the old or from the new .apk. Can I keep the data from the tables? Please let me know. Thank u in advance.

Sandra
  • 4,239
  • 10
  • 47
  • 80

2 Answers2

1

So what onUpgrade method will be called, from the old or from the new .apk.

From new .apk. Old one is gone at this point.

Can I keep the data from the tables?

You have to code your upgrade in such a way that you retain data that you need including old data as required.

Alex Gitelman
  • 24,429
  • 7
  • 52
  • 49
  • Thank u, I was mostly concerned about will it be from the new or the old .apk. You answered my question – Sandra Sep 01 '11 at 17:29
0

Dropping the tables will kill all of your current data. In order to preserve the data, you're going to need to write a custom onUpgrade method to do this. Here's a previous post that discusses this and may give you some ideas on what you need to do:

SQLiteOpenHelper onUpgrade() Confusion Android

Community
  • 1
  • 1
SBerg413
  • 14,515
  • 6
  • 62
  • 88