Q:

Manage DB before uploading to playstore in android

I have uploaded an application to play store couple of weeks back. This application involves sqlite database that stores information on username, password, other details that given are by user while using the application locally. 
Now I have couple of more tables and fields added to database and wanna upload the application to playstore as an update? 
My worry is if the user updates the application from playstore - After update - all the data stored in database will be saved or will the user has to recreate everything from scratch? 
Let me know!
Thanks! 

A:

You have to override the onUpgade method of SQLiteOpenHelper. In the OnUpgrade method you can either erase the data(drop sqlite command) or maintain the data with the additional columns(alter sqlite command) or create new table (create sqlite command).
Refer the following snippet.
I assume your version would be 1.(Plz check the constructor of your SqliteOpenHelper class)
Increment the version by 1.
class DatabaseHelper extends SqliteOplenHelper{

        private static final int DATABASE_VERSION = 2;   //new version of the database
        private static final int Database_name = "MyDatabase";
        private static final String alterUserName = "alter table users add name text";
        private static final String table_users = "create table if not exists "
            + users + "(" + "_id integer primary key autoincrement,"
            + "email text" + ")";

        public DatabaseHelper(Context context) {
        super(context, Database_name, null, DATABASE_VERSION);
        cntxt = context;
    }

        @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

        db.execSQL(table_users);
        db.execSQL(alterUserName);

    }
}

Now everytime when you roll the next update with database changes be sure to increment the database version by 1 else let it remain the same.

