I have a USER table in my android app which is released in App Store
but then I had to add a POSTCODE field and release a new version of the app with the Database version set to 2 now.
So in the app when I create my DatabaseManager object, upon its creation I first call
public DatabaseManager(Context context) {
super(context, Preferences.LOCAL_SQLITE_DATABASE_NAME, null, 2);
}
public void onCreate(SQLiteDatabase database) {
database.execSQL(SQLQueries.tableUserCreate);
// Remainder omitted for clarity
}
and then in the onUpgdade I do the following:
public void onUpgrade(SQLiteDatabase database, int version_old, int current_version) {
switch (version_old) {
case 1:
database.execSQL(SQLQueries.addPostcodeFieldToUserTable);
break;
}
Now I have two queries:
SQLQueries.tableUserCreate;
SQLQueries.addPostcodeFieldToUserTable;
My question is: Should I add the POSTCODE field in the "CREATE TABLE "tableUserCreate" query and then put it in the ALTER TABLE statement "addPostcodeFieldToUserTable" or should I ONLY put it in the ALTER TABLE statement "addPostcodeFieldToUserTable"?
The problem is I already put it in both the CREATE TABLE and ALTER TABLE statements and now I have already released a version 3 of the app - has the POSTCODE field been added twice to the table? What if in version 4 I remove the POSTCODE field declaration from the CREATE TABLE query and only leave it in the ALTER TABLE query?
Aucun commentaire:
Enregistrer un commentaire