dimanche 29 mars 2015

Steps to upgrade existing Android database without losing exisiting data

I have been trying this for two days and have looked at all the different post on it.


I followed this post as well.


Steps to upgrade existing Android database w/o losing data


But when I install a new version on my phone it seems to wipe out my old data.


Can some one please helo.


Here is my database code



private static final int DATABASE_VERSION = 2; //was 1 before
public void create() throws IOException{

boolean dbExist = checkDataBase();

if(dbExist){
//do nothing - database already exist
this.getWritableDatabase();
}else{

//By calling this method and empty database will be created into the default system path
//of your application so we are gonna be able to overwrite that database with our database.


try {
this.getReadableDatabase();
copyDataBase();

} catch (IOException e) {

throw new Error("Error copying database");

}
}

}

public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if(newVersion == 2) {
db.execSQL("ALTER TABLE CHANNELPROFILE ADD COLUMN backcolor TEXT");
}
}


Not really sure what I am doing wrong here. please help


Aucun commentaire:

Enregistrer un commentaire