I have released an app (World Time) with initial database. Now i want to update the app with a database upgrade.
I have put in the upgrade code in OnUpgrade() and checking for the newVersion. But it was not being called in my local testing...
So i put in the debug statement to get the database version and it is zero .
Any idea why it is not being versioned ?
Following is the code to copy the database from my Assets folder ...
InputStream myInput = myContext.getAssets().open(DB_NAME);
// Path to the just created empty db
String outFileName = DB_PATH + DB_NAME;
//Open the empty db as the output stream
OutputStream myOutput = new FileOutputStream(outFileName);
//transfer bytes from the inputfile to the outputfile
byte[] buffer = new byte[1024];
int length;
while ((length = myInput.read(buffer))>0){
myOutput.write(buffer, 0, length);
}
//Close the streams
myOutput.flush();
myOutput.close();
myInput.close();
Following is my constructor, OnCreate() & OnUpgrade()
public DatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
this.myContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
if(oldVersion == 1 && newVersion == 2){
String sql = "update statement...."; // i have a correct update statement here
db.execSQL(sql);
}
}
--
Mahesh
http://android.maheshdixit.com