· 8 years ago · Aug 14, 2018, 02:50 AM
1Android: upgrading DB version and adding new table
2private static final int DATABASE_VERSION = 2;
3
4private static final String DATABASE_CREATE_color = "CREATE TABLE IF NOT EXISTS files(color text, incident_id text)";
5
6@Override
7 public void onCreate(SQLiteDatabase database) {
8 database.execSQL(DATABASE_CREATE_incident);
9 database.execSQL(DATABASE_CREATE_audio);
10 database.execSQL(DATABASE_CREATE_video);
11 database.execSQL(DATABASE_CREATE_image);
12
13 }
14
15 @Override
16 public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
17 //drop table and add new tables when version 2 released.
18 db.execSQL(DATABASE_CREATE_color);
19
20 }
21
22MyOpenHelper(Context context) {
23 super(context, "dbname", null, 2);
24}
25
26database.execSQL(DATABASE_CREATE_color);
27
28onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
29 switch(oldVersion) {
30 case 1:
31 db.execSQL(DATABASE_CREATE_color);
32 // we want both updates, so no break statement here...
33 case 2:
34 db.execSQL(DATABASE_CREATE_someothertable);
35 }
36}
37
38adb uninstall <yourpackagename>