@Test public void onUpgradeWithMultipleContentWritesSQLCorrectly() { final DatabaseHelper databaseHelper = new DatabaseHelper(mContext, "TEST_DB", 1) { @Override public List<Content> getContent(Context context) { final Content mockContent = new MockContent("EMIR"); final Content mockContent1 = new MockContent("EMIR1"); return Lists.newArrayList(mockContent, mockContent1); } }; databaseHelper.onUpgrade(mSqLiteDatabase, 0, 1); verify(mSqLiteDatabase).execSQL("DROP TABLE EMIR;"); verify(mSqLiteDatabase).execSQL("CREATE TABLE EMIR;"); verify(mSqLiteDatabase).execSQL("DROP TABLE EMIR1;"); verify(mSqLiteDatabase).execSQL("CREATE TABLE EMIR1;"); }
@Override public void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion) { if (oldVersion != newVersion) { final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String drop = content.getDrop(mContext); final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(drop); sqLiteDatabase.execSQL(create); } } else if (oldVersion == newVersion) { } }
DatabaseHelper extends SQLiteOpenHelper { @Override public void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion) { if (oldVersion != newVersion) { final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String drop = content.getDrop(mContext); final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(drop); sqLiteDatabase.execSQL(create); } } else if (oldVersion == newVersion) { } } }
DatabaseHelper extends SQLiteOpenHelper { @Override public void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion) { if (oldVersion != newVersion) { final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String drop = content.getDrop(mContext); final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(drop); sqLiteDatabase.execSQL(create); } } else if (oldVersion == newVersion) { } } DatabaseHelper(final Context context, final String name, final int version); }
DatabaseHelper extends SQLiteOpenHelper { @Override public void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion) { if (oldVersion != newVersion) { final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String drop = content.getDrop(mContext); final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(drop); sqLiteDatabase.execSQL(create); } } else if (oldVersion == newVersion) { } } DatabaseHelper(final Context context, final String name, final int version); @Override SQLiteDatabase getWritableDatabase(); abstract List<Content> getContent(final Context context); @Override void onOpen(final SQLiteDatabase sqLiteDatabase); @Override void onCreate(final SQLiteDatabase sqLiteDatabase); @Override void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion); }
DatabaseHelper extends SQLiteOpenHelper { @Override public void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion) { if (oldVersion != newVersion) { final List<Content> contentList = getContent(mContext); for (final Content content : contentList) { final String drop = content.getDrop(mContext); final String create = content.getCreate(mContext); sqLiteDatabase.execSQL(drop); sqLiteDatabase.execSQL(create); } } else if (oldVersion == newVersion) { } } DatabaseHelper(final Context context, final String name, final int version); @Override SQLiteDatabase getWritableDatabase(); abstract List<Content> getContent(final Context context); @Override void onOpen(final SQLiteDatabase sqLiteDatabase); @Override void onCreate(final SQLiteDatabase sqLiteDatabase); @Override void onUpgrade(final SQLiteDatabase sqLiteDatabase, final int oldVersion, final int newVersion);  }