how to test upgrading sqlite database before uploading new version of my app on play store in android how to test upgrading sqlite database before uploading new version of my app on play store in android database database

how to test upgrading sqlite database before uploading new version of my app on play store in android


Version of db stored inside db. Just create a db (db_old) with older version than in your DbHelper. Use DbHelper to connect to db_old and your onUpgrade method will be called.

You can use your existing db as db_old, just decrement it's version. To change version you can use any sqlite db editor.

If do not want to write test for DbHelper and want to simulate app upgrade, you can use adb install -r command. Read more here.


After long search and testing my application, finally...

I got it working! In the createDataBase-class a line was missing:

I have just added below line in my code createDataBase()

this.getWritableDatabase();

We have to give permission to write database while we create database, this permission will be give permission to write the database while we upgrade the application from the play store.

Once opened successfully, the database is cached, so you can call this method every time you need to write to the database. (Make sure to call close() when you no longer need the database.) Errors such as bad permissions or a full disk may cause this method to fail, but future attempts may succeed if the problem is fixed.

Database upgrade may take a long time, you should not call this method from the application main thread, including from ContentProvider.onCreate().

public void createDataBase() throws IOException         { boolean dbExist = checkDataBase();           if (!dbExist) {           this.getReadableDatabase();            try {                // ---If not created then copy the database---                copyDataBase();            } catch (IOException e) {                throw new Error("Error copying database");            }          }          else {            /* This line: that has been solve my problem */           this.getWritableDatabase();          }        }

public void openDataBase() throws SQLException {

      // --- Open the database---         String myPath = path + DATABASE_NAME;      myDataBase = SQLiteDatabase.openDatabase(myPath, null,              SQLiteDatabase.OPEN_READWRITE); // you also have to add open_readwrite condition here              /*onUpgrade(myDataBase, 1, 2);*/ // no need to call upgrade     here it will be called automatically  }

You have to give read write condition while open the database.

Furthermore onUpgrade() is called when a new object of the class DataBaseHelper is created but only if the database version numbers do not match. So this means that there is no need to call onUpgrade "on your own". If you publish an update of your db, just increment the version nr by one and apply changes in the onUpgrade()-method.

I got it from the given link:

onUpgrade database - oldVersion - newVersion

Hope this will helps anyone for future developer!


how to test upgrading sqlite database without downloading new version app from play store in android

1) How can I test db upgrade before updating new version on the play store?

i downloaded sqlite browser plugin for eclipse from here

http://sourceforge.net/projects/sqlitebrowser/

and check this tutorial on how to use sqlite plugin

http://www.coderzheaven.com/2011/04/18/sqlitemanager-plugin-for-eclipse/

just copy the jar from 1st link and paste in your eclipse installation folder called plugin and restart eclipse

then start an emulator and navigate to your package from DDMS and you can view your sqlite database & check if the changes you made to tables exists or not