How to Upgrade Sqlite DataBase to Next Version in Android?

how to upgrade the android app version one Own SQLite Database without losing the existing data

  • I need to update my android application in the market to next version.next version i need to update the sqlite DB without losing the exsiting data. In version one i did not create the tables in runtime instead get the database file from the "assets" folder and copies into the system database path of my application. Refer to this link http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/ next version of my app i have modify the exsting table columns and add extra records and there are few new tables as well.I have updated the data base and copied to asset folder. This will work for users who buy the app for first time,but not for existing users,my question is how can i update the version one users data base without losing existing data Sam.

  • Answer:

    Prepare sql query to upgrade database. If database exists then perform updating else copy database from assets. In tutorial that you provided is such code: if(dbExist){ //do nothing - database already exist }else{ In place where is //do nothing - database already exist put your upgrading code.

Sam at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { Log.w(TAG, "Upgrading database from version " + oldVersion + " to " + newVersion + ", which will destroy all old data"); if(oldVersion == 2 && newVersion == 3) { db.execSQL("ALTER TABLE xyz ADD bobby int default 0"); } else { db.execSQL("DROP TABLE IF EXISTS xyz"); onCreate(db); } } }

Chris

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.