@Test public void testUpdateTo32() { for (String table : TABLES) { mDb.execSQL(String.format(BASE_TABLE_CREATE, table)); } mDbHelper.onUpgrade(mDb, 31, 32); }
@Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { TbaLogger.w("Upgrading database from version " + oldVersion + " to " + newVersion); int upgradeTo = oldVersion + 1; while (upgradeTo <= newVersion) { switch (upgradeTo) { case 14: db.execSQL(CREATE_DISTRICTS); db.execSQL(CREATE_DISTRICTTEAMS); if (!columnExists(db, TABLE_EVENTS, EventsTable.DISTRICT_POINTS)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.DISTRICT_POINTS + " TEXT DEFAULT '' "); } break; case 15: db.execSQL(CREATE_FAVORITES); db.execSQL(CREATE_SUBSCRIPTIONS); break; case 16: if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.NOTIFICATION_SETTINGS)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.NOTIFICATION_SETTINGS + " TEXT DEFAULT '[]' "); } if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } if (!columnExists(db, TABLE_FAVORITES, FavoritesTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_FAVORITES + " ADD COLUMN " + FavoritesTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } break; case 17: if (!columnExists(db, TABLE_DISTRICTS, DistrictsTable.NAME)) { db.execSQL("ALTER TABLE " + TABLE_DISTRICTS + " ADD COLUMN " + DistrictsTable.NAME + " TEXT DEFAULT '' "); } break; case 18: if (!columnExists(db, TABLE_EVENTS, EventsTable.SHORTNAME)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.SHORTNAME + " TEXT DEFAULT '' "); } break; case 20: db.execSQL(CREATE_NOTIFICATIONS); break; case 23: case 24: db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_TEAMS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_EVENTS); onCreate(db); break; case 25: db.execSQL("DROP TABLE IF EXISTS " + TABLE_API); break; case 28: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NOTIFICATIONS); db.execSQL(CREATE_NOTIFICATIONS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 29: db.beginTransaction(); try { if (!columnExists(db, TABLE_TEAMS, TeamsTable.MOTTO)) { db.execSQL("ALTER TABLE " + TABLE_TEAMS + " ADD COLUMN " + TeamsTable.MOTTO + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 30: db.beginTransaction(); try { if (!columnExists(db, TABLE_MATCHES, MatchesTable.BREAKDOWN)) { db.execSQL("ALTER TABLE " + TABLE_MATCHES + " ADD COLUMN " + MatchesTable.BREAKDOWN + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 31: String[] tables = {TABLE_AWARDS, TABLE_DISTRICTS, TABLE_DISTRICTTEAMS, TABLE_EVENTS, TABLE_EVENTTEAMS, TABLE_MATCHES, TABLE_MEDIAS, TABLE_TEAMS}; db.beginTransaction(); try { for (int i = 0; i < tables.length; i++) { if (!columnExists(db, tables[i], "last_modified")) { db.execSQL(String.format("ALTER TABLE %1$s ADD COLUMN last_modified TIMESTAMP", tables[i])); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 32: db.beginTransaction(); String[] tables32 = {TABLE_EVENTS, TABLE_TEAMS, TABLE_DISTRICTTEAMS, TABLE_EVENTTEAMS, TABLE_MATCHES}; try { for (int i = 0; i < tables32.length; i++) { db.execSQL("DROP TABLE IF EXISTS " + tables32[i]); } onCreate(db); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 33: db.beginTransaction(); try { if (!columnExists(db, TABLE_EVENTS, EventsTable.CITY)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_EVENTS, EventsTable.CITY)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 34: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_MEDIAS); db.execSQL(CREATE_MEDIAS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 35: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_DISTRICTS); db.execSQL(CREATE_DISTRICTS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 36: db.beginTransaction(); try { if (!columnExists(db, TABLE_MEDIAS, MediasTable.B64_IMAGE)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_MEDIAS, MediasTable.B64_IMAGE)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; } upgradeTo++; } }
Database extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { TbaLogger.w("Upgrading database from version " + oldVersion + " to " + newVersion); int upgradeTo = oldVersion + 1; while (upgradeTo <= newVersion) { switch (upgradeTo) { case 14: db.execSQL(CREATE_DISTRICTS); db.execSQL(CREATE_DISTRICTTEAMS); if (!columnExists(db, TABLE_EVENTS, EventsTable.DISTRICT_POINTS)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.DISTRICT_POINTS + " TEXT DEFAULT '' "); } break; case 15: db.execSQL(CREATE_FAVORITES); db.execSQL(CREATE_SUBSCRIPTIONS); break; case 16: if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.NOTIFICATION_SETTINGS)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.NOTIFICATION_SETTINGS + " TEXT DEFAULT '[]' "); } if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } if (!columnExists(db, TABLE_FAVORITES, FavoritesTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_FAVORITES + " ADD COLUMN " + FavoritesTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } break; case 17: if (!columnExists(db, TABLE_DISTRICTS, DistrictsTable.NAME)) { db.execSQL("ALTER TABLE " + TABLE_DISTRICTS + " ADD COLUMN " + DistrictsTable.NAME + " TEXT DEFAULT '' "); } break; case 18: if (!columnExists(db, TABLE_EVENTS, EventsTable.SHORTNAME)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.SHORTNAME + " TEXT DEFAULT '' "); } break; case 20: db.execSQL(CREATE_NOTIFICATIONS); break; case 23: case 24: db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_TEAMS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_EVENTS); onCreate(db); break; case 25: db.execSQL("DROP TABLE IF EXISTS " + TABLE_API); break; case 28: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NOTIFICATIONS); db.execSQL(CREATE_NOTIFICATIONS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 29: db.beginTransaction(); try { if (!columnExists(db, TABLE_TEAMS, TeamsTable.MOTTO)) { db.execSQL("ALTER TABLE " + TABLE_TEAMS + " ADD COLUMN " + TeamsTable.MOTTO + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 30: db.beginTransaction(); try { if (!columnExists(db, TABLE_MATCHES, MatchesTable.BREAKDOWN)) { db.execSQL("ALTER TABLE " + TABLE_MATCHES + " ADD COLUMN " + MatchesTable.BREAKDOWN + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 31: String[] tables = {TABLE_AWARDS, TABLE_DISTRICTS, TABLE_DISTRICTTEAMS, TABLE_EVENTS, TABLE_EVENTTEAMS, TABLE_MATCHES, TABLE_MEDIAS, TABLE_TEAMS}; db.beginTransaction(); try { for (int i = 0; i < tables.length; i++) { if (!columnExists(db, tables[i], "last_modified")) { db.execSQL(String.format("ALTER TABLE %1$s ADD COLUMN last_modified TIMESTAMP", tables[i])); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 32: db.beginTransaction(); String[] tables32 = {TABLE_EVENTS, TABLE_TEAMS, TABLE_DISTRICTTEAMS, TABLE_EVENTTEAMS, TABLE_MATCHES}; try { for (int i = 0; i < tables32.length; i++) { db.execSQL("DROP TABLE IF EXISTS " + tables32[i]); } onCreate(db); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 33: db.beginTransaction(); try { if (!columnExists(db, TABLE_EVENTS, EventsTable.CITY)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_EVENTS, EventsTable.CITY)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 34: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_MEDIAS); db.execSQL(CREATE_MEDIAS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 35: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_DISTRICTS); db.execSQL(CREATE_DISTRICTS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 36: db.beginTransaction(); try { if (!columnExists(db, TABLE_MEDIAS, MediasTable.B64_IMAGE)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_MEDIAS, MediasTable.B64_IMAGE)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; } upgradeTo++; } } }
Database extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { TbaLogger.w("Upgrading database from version " + oldVersion + " to " + newVersion); int upgradeTo = oldVersion + 1; while (upgradeTo <= newVersion) { switch (upgradeTo) { case 14: db.execSQL(CREATE_DISTRICTS); db.execSQL(CREATE_DISTRICTTEAMS); if (!columnExists(db, TABLE_EVENTS, EventsTable.DISTRICT_POINTS)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.DISTRICT_POINTS + " TEXT DEFAULT '' "); } break; case 15: db.execSQL(CREATE_FAVORITES); db.execSQL(CREATE_SUBSCRIPTIONS); break; case 16: if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.NOTIFICATION_SETTINGS)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.NOTIFICATION_SETTINGS + " TEXT DEFAULT '[]' "); } if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } if (!columnExists(db, TABLE_FAVORITES, FavoritesTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_FAVORITES + " ADD COLUMN " + FavoritesTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } break; case 17: if (!columnExists(db, TABLE_DISTRICTS, DistrictsTable.NAME)) { db.execSQL("ALTER TABLE " + TABLE_DISTRICTS + " ADD COLUMN " + DistrictsTable.NAME + " TEXT DEFAULT '' "); } break; case 18: if (!columnExists(db, TABLE_EVENTS, EventsTable.SHORTNAME)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.SHORTNAME + " TEXT DEFAULT '' "); } break; case 20: db.execSQL(CREATE_NOTIFICATIONS); break; case 23: case 24: db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_TEAMS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_EVENTS); onCreate(db); break; case 25: db.execSQL("DROP TABLE IF EXISTS " + TABLE_API); break; case 28: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NOTIFICATIONS); db.execSQL(CREATE_NOTIFICATIONS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 29: db.beginTransaction(); try { if (!columnExists(db, TABLE_TEAMS, TeamsTable.MOTTO)) { db.execSQL("ALTER TABLE " + TABLE_TEAMS + " ADD COLUMN " + TeamsTable.MOTTO + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 30: db.beginTransaction(); try { if (!columnExists(db, TABLE_MATCHES, MatchesTable.BREAKDOWN)) { db.execSQL("ALTER TABLE " + TABLE_MATCHES + " ADD COLUMN " + MatchesTable.BREAKDOWN + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 31: String[] tables = {TABLE_AWARDS, TABLE_DISTRICTS, TABLE_DISTRICTTEAMS, TABLE_EVENTS, TABLE_EVENTTEAMS, TABLE_MATCHES, TABLE_MEDIAS, TABLE_TEAMS}; db.beginTransaction(); try { for (int i = 0; i < tables.length; i++) { if (!columnExists(db, tables[i], "last_modified")) { db.execSQL(String.format("ALTER TABLE %1$s ADD COLUMN last_modified TIMESTAMP", tables[i])); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 32: db.beginTransaction(); String[] tables32 = {TABLE_EVENTS, TABLE_TEAMS, TABLE_DISTRICTTEAMS, TABLE_EVENTTEAMS, TABLE_MATCHES}; try { for (int i = 0; i < tables32.length; i++) { db.execSQL("DROP TABLE IF EXISTS " + tables32[i]); } onCreate(db); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 33: db.beginTransaction(); try { if (!columnExists(db, TABLE_EVENTS, EventsTable.CITY)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_EVENTS, EventsTable.CITY)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 34: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_MEDIAS); db.execSQL(CREATE_MEDIAS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 35: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_DISTRICTS); db.execSQL(CREATE_DISTRICTS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 36: db.beginTransaction(); try { if (!columnExists(db, TABLE_MEDIAS, MediasTable.B64_IMAGE)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_MEDIAS, MediasTable.B64_IMAGE)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; } upgradeTo++; } } protected  Database(Context context); }
Database extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { TbaLogger.w("Upgrading database from version " + oldVersion + " to " + newVersion); int upgradeTo = oldVersion + 1; while (upgradeTo <= newVersion) { switch (upgradeTo) { case 14: db.execSQL(CREATE_DISTRICTS); db.execSQL(CREATE_DISTRICTTEAMS); if (!columnExists(db, TABLE_EVENTS, EventsTable.DISTRICT_POINTS)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.DISTRICT_POINTS + " TEXT DEFAULT '' "); } break; case 15: db.execSQL(CREATE_FAVORITES); db.execSQL(CREATE_SUBSCRIPTIONS); break; case 16: if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.NOTIFICATION_SETTINGS)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.NOTIFICATION_SETTINGS + " TEXT DEFAULT '[]' "); } if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } if (!columnExists(db, TABLE_FAVORITES, FavoritesTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_FAVORITES + " ADD COLUMN " + FavoritesTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } break; case 17: if (!columnExists(db, TABLE_DISTRICTS, DistrictsTable.NAME)) { db.execSQL("ALTER TABLE " + TABLE_DISTRICTS + " ADD COLUMN " + DistrictsTable.NAME + " TEXT DEFAULT '' "); } break; case 18: if (!columnExists(db, TABLE_EVENTS, EventsTable.SHORTNAME)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.SHORTNAME + " TEXT DEFAULT '' "); } break; case 20: db.execSQL(CREATE_NOTIFICATIONS); break; case 23: case 24: db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_TEAMS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_EVENTS); onCreate(db); break; case 25: db.execSQL("DROP TABLE IF EXISTS " + TABLE_API); break; case 28: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NOTIFICATIONS); db.execSQL(CREATE_NOTIFICATIONS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 29: db.beginTransaction(); try { if (!columnExists(db, TABLE_TEAMS, TeamsTable.MOTTO)) { db.execSQL("ALTER TABLE " + TABLE_TEAMS + " ADD COLUMN " + TeamsTable.MOTTO + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 30: db.beginTransaction(); try { if (!columnExists(db, TABLE_MATCHES, MatchesTable.BREAKDOWN)) { db.execSQL("ALTER TABLE " + TABLE_MATCHES + " ADD COLUMN " + MatchesTable.BREAKDOWN + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 31: String[] tables = {TABLE_AWARDS, TABLE_DISTRICTS, TABLE_DISTRICTTEAMS, TABLE_EVENTS, TABLE_EVENTTEAMS, TABLE_MATCHES, TABLE_MEDIAS, TABLE_TEAMS}; db.beginTransaction(); try { for (int i = 0; i < tables.length; i++) { if (!columnExists(db, tables[i], "last_modified")) { db.execSQL(String.format("ALTER TABLE %1$s ADD COLUMN last_modified TIMESTAMP", tables[i])); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 32: db.beginTransaction(); String[] tables32 = {TABLE_EVENTS, TABLE_TEAMS, TABLE_DISTRICTTEAMS, TABLE_EVENTTEAMS, TABLE_MATCHES}; try { for (int i = 0; i < tables32.length; i++) { db.execSQL("DROP TABLE IF EXISTS " + tables32[i]); } onCreate(db); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 33: db.beginTransaction(); try { if (!columnExists(db, TABLE_EVENTS, EventsTable.CITY)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_EVENTS, EventsTable.CITY)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 34: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_MEDIAS); db.execSQL(CREATE_MEDIAS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 35: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_DISTRICTS); db.execSQL(CREATE_DISTRICTS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 36: db.beginTransaction(); try { if (!columnExists(db, TABLE_MEDIAS, MediasTable.B64_IMAGE)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_MEDIAS, MediasTable.B64_IMAGE)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; } upgradeTo++; } } protected  Database(Context context); static synchronized Database getInstance(Context context); TeamsTable getTeamsTable(); EventsTable getEventsTable(); EventDetailsTable getEventDetailsTable(); AwardsTable getAwardsTable(); MatchesTable getMatchesTable(); MediasTable getMediasTable(); EventTeamsTable getEventTeamsTable(); DistrictsTable getDistrictsTable(); DistrictTeamsTable getDistrictTeamsTable(); FavoritesTable getFavoritesTable(); SubscriptionsTable getSubscriptionsTable(); NotificationsTable getNotificationsTable(); @WorkerThread void beginTransaction(); @WorkerThread static void beginTransaction(SQLiteDatabase db); void setTransactionSuccessful(); void endTransaction(); SQLiteDatabase getDb(); @Override void onCreate(SQLiteDatabase db); @Override void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); Cursor getMatchesForTeamQuery(String query); Cursor getMatchesForEventQuery(String query); }
Database extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { TbaLogger.w("Upgrading database from version " + oldVersion + " to " + newVersion); int upgradeTo = oldVersion + 1; while (upgradeTo <= newVersion) { switch (upgradeTo) { case 14: db.execSQL(CREATE_DISTRICTS); db.execSQL(CREATE_DISTRICTTEAMS); if (!columnExists(db, TABLE_EVENTS, EventsTable.DISTRICT_POINTS)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.DISTRICT_POINTS + " TEXT DEFAULT '' "); } break; case 15: db.execSQL(CREATE_FAVORITES); db.execSQL(CREATE_SUBSCRIPTIONS); break; case 16: if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.NOTIFICATION_SETTINGS)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.NOTIFICATION_SETTINGS + " TEXT DEFAULT '[]' "); } if (!columnExists(db, TABLE_SUBSCRIPTIONS, SubscriptionsTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_SUBSCRIPTIONS + " ADD COLUMN " + SubscriptionsTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } if (!columnExists(db, TABLE_FAVORITES, FavoritesTable.MODEL_ENUM)) { db.execSQL("ALTER TABLE " + TABLE_FAVORITES + " ADD COLUMN " + FavoritesTable.MODEL_ENUM + " INTEGER NOT NULL DEFAULT -1"); } break; case 17: if (!columnExists(db, TABLE_DISTRICTS, DistrictsTable.NAME)) { db.execSQL("ALTER TABLE " + TABLE_DISTRICTS + " ADD COLUMN " + DistrictsTable.NAME + " TEXT DEFAULT '' "); } break; case 18: if (!columnExists(db, TABLE_EVENTS, EventsTable.SHORTNAME)) { db.execSQL("ALTER TABLE " + TABLE_EVENTS + " ADD COLUMN " + EventsTable.SHORTNAME + " TEXT DEFAULT '' "); } break; case 20: db.execSQL(CREATE_NOTIFICATIONS); break; case 23: case 24: db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_TEAMS); db.execSQL("DROP TABLE IF EXISTS " + TABLE_SEARCH_EVENTS); onCreate(db); break; case 25: db.execSQL("DROP TABLE IF EXISTS " + TABLE_API); break; case 28: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_NOTIFICATIONS); db.execSQL(CREATE_NOTIFICATIONS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 29: db.beginTransaction(); try { if (!columnExists(db, TABLE_TEAMS, TeamsTable.MOTTO)) { db.execSQL("ALTER TABLE " + TABLE_TEAMS + " ADD COLUMN " + TeamsTable.MOTTO + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 30: db.beginTransaction(); try { if (!columnExists(db, TABLE_MATCHES, MatchesTable.BREAKDOWN)) { db.execSQL("ALTER TABLE " + TABLE_MATCHES + " ADD COLUMN " + MatchesTable.BREAKDOWN + " TEXT DEFAULT '' "); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 31: String[] tables = {TABLE_AWARDS, TABLE_DISTRICTS, TABLE_DISTRICTTEAMS, TABLE_EVENTS, TABLE_EVENTTEAMS, TABLE_MATCHES, TABLE_MEDIAS, TABLE_TEAMS}; db.beginTransaction(); try { for (int i = 0; i < tables.length; i++) { if (!columnExists(db, tables[i], "last_modified")) { db.execSQL(String.format("ALTER TABLE %1$s ADD COLUMN last_modified TIMESTAMP", tables[i])); } } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 32: db.beginTransaction(); String[] tables32 = {TABLE_EVENTS, TABLE_TEAMS, TABLE_DISTRICTTEAMS, TABLE_EVENTTEAMS, TABLE_MATCHES}; try { for (int i = 0; i < tables32.length; i++) { db.execSQL("DROP TABLE IF EXISTS " + tables32[i]); } onCreate(db); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 33: db.beginTransaction(); try { if (!columnExists(db, TABLE_EVENTS, EventsTable.CITY)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_EVENTS, EventsTable.CITY)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 34: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_MEDIAS); db.execSQL(CREATE_MEDIAS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 35: db.beginTransaction(); try { db.execSQL("DROP TABLE IF EXISTS " + TABLE_DISTRICTS); db.execSQL(CREATE_DISTRICTS); db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; case 36: db.beginTransaction(); try { if (!columnExists(db, TABLE_MEDIAS, MediasTable.B64_IMAGE)) { db.execSQL(String.format( "ALTER TABLE %1$s ADD COLUMN %2$s TEXT DEFAULT ''", TABLE_MEDIAS, MediasTable.B64_IMAGE)); } db.setTransactionSuccessful(); } finally { db.endTransaction(); } break; } upgradeTo++; } } protected  Database(Context context); static synchronized Database getInstance(Context context); TeamsTable getTeamsTable(); EventsTable getEventsTable(); EventDetailsTable getEventDetailsTable(); AwardsTable getAwardsTable(); MatchesTable getMatchesTable(); MediasTable getMediasTable(); EventTeamsTable getEventTeamsTable(); DistrictsTable getDistrictsTable(); DistrictTeamsTable getDistrictTeamsTable(); FavoritesTable getFavoritesTable(); SubscriptionsTable getSubscriptionsTable(); NotificationsTable getNotificationsTable(); @WorkerThread void beginTransaction(); @WorkerThread static void beginTransaction(SQLiteDatabase db); void setTransactionSuccessful(); void endTransaction(); SQLiteDatabase getDb(); @Override void onCreate(SQLiteDatabase db); @Override void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion); Cursor getMatchesForTeamQuery(String query); Cursor getMatchesForEventQuery(String query); static final String ALL_TEAMS_LOADED_TO_DATABASE_FOR_PAGE; static final String ALL_EVENTS_LOADED_TO_DATABASE_FOR_YEAR; static final String ALL_DISTRICTS_LOADED_TO_DATABASE_FOR_YEAR; static final String TABLE_TEAMS; static final String CREATE_TEAMS; static final String CREATE_EVENTS; static final String CREATE_AWARDS; static final String CREATE_MATCHES; static final String CREATE_MEDIAS; static final String CREATE_EVENTTEAMS; static final String CREATE_DISTRICTS; static final String CREATE_DISTRICTTEAMS; static final String CREATE_EVENTDETAILS; static final String CREATE_FAVORITES; static final String CREATE_SUBSCRIPTIONS; static final String CREATE_SEARCH_TEAMS; static final String CREATE_SEARCH_EVENTS; static final String CREATE_NOTIFICATIONS; }