I created an app in which I use a SQLiteDatabase custom class, in order to manage SQLite database, obviously.
I created a "ChangeLog" class to check my schema's modifies. For example:
- Version 1.0.0: "table01" has 3 columns with "NOT NULL" constraint
- Version 1.0.1: "table01" has 3 columns, without "NOT NULL" constraint
If an user install last version of my app, I invoke a method applyModifies() from my ChangeLog class in order to apply several modifies and ALTER "table01", for example. (To do this, I rename the old table, I create the new one, I copy all records to new table, I drop my old table and, finally, I rename the new table with original name.)
I would need to call several methods inside applyModifies() (update0001(), update0002(), etc.). If first method fails, next methods don't have to start.
//[... ChangeLog Class - Methods ...]
public void applyModifies() {
int version = checkVersion(); //Take version release of my app
try {
boolean b0001 = update0001();
boolean b0002 = update0002();
boolean b0003 = update0003();
} catch (Exception e) {
//
}
}
public boolean update0001() {
//Verify actual table's schema and apply modifies, if needed
//I use DB transaction to execute queries in block and wait for a result
return result;
}
Normally, I could do something like:
boolean b0001 = update0001();
if (b0001) {
boolean b0002 = update0002();
} else {
//Previous method fails
}
but it's not a good solution, overall because I need to add several changelog modifies to apply and I don't know how to implement it yet.
Aucun commentaire:
Enregistrer un commentaire