Search in sources :

Example 16 with SupportSQLiteDatabase

use of androidx.sqlite.db.SupportSQLiteDatabase in project AmazeFileManager by TeamAmaze.

the class ExplorerDatabaseMigrationTest method migrateAll.

@Test
public void migrateAll() throws IOException {
    SupportSQLiteDatabase db = helper.createDatabase(TEST_DB, 1);
    db.close();
    ExplorerDatabase explorerDatabase = Room.databaseBuilder(InstrumentationRegistry.getInstrumentation().getTargetContext(), ExplorerDatabase.class, TEST_DB).addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4, MIGRATION_4_5, MIGRATION_5_6, MIGRATION_6_7).build();
    explorerDatabase.getOpenHelper().getWritableDatabase();
    explorerDatabase.close();
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) Test(org.junit.Test)

Example 17 with SupportSQLiteDatabase

use of androidx.sqlite.db.SupportSQLiteDatabase in project AmazeFileManager by TeamAmaze.

the class ExplorerDatabaseMigrationTest method migrateFromV7.

@Test
public void migrateFromV7() throws IOException {
    SupportSQLiteDatabase db = helper.createDatabase(TEST_DB, 7);
    db.execSQL("INSERT INTO " + TABLE_CLOUD_PERSIST + "(" + COLUMN_CLOUD_ID + "," + COLUMN_CLOUD_SERVICE + "," + COLUMN_CLOUD_PERSIST + ") VALUES (1," + (OpenMode.GDRIVE.ordinal() - 1) + ",'abcd')");
    db.execSQL("INSERT INTO " + TABLE_CLOUD_PERSIST + "(" + COLUMN_CLOUD_ID + "," + COLUMN_CLOUD_SERVICE + "," + COLUMN_CLOUD_PERSIST + ") VALUES (2," + (OpenMode.DROPBOX.ordinal() - 1) + ",'efgh')");
    db.execSQL("INSERT INTO " + TABLE_CLOUD_PERSIST + "(" + COLUMN_CLOUD_ID + "," + COLUMN_CLOUD_SERVICE + "," + COLUMN_CLOUD_PERSIST + ") VALUES (3," + (OpenMode.BOX.ordinal() - 1) + ",'ijkl')");
    db.execSQL("INSERT INTO " + TABLE_CLOUD_PERSIST + "(" + COLUMN_CLOUD_ID + "," + COLUMN_CLOUD_SERVICE + "," + COLUMN_CLOUD_PERSIST + ") VALUES (4," + (OpenMode.ONEDRIVE.ordinal() - 1) + ",'mnop')");
    db.close();
    ExplorerDatabase explorerDatabase = Room.databaseBuilder(InstrumentationRegistry.getInstrumentation().getTargetContext(), ExplorerDatabase.class, TEST_DB).addMigrations(MIGRATION_7_8).allowMainThreadQueries().build();
    explorerDatabase.getOpenHelper().getWritableDatabase();
    CloudEntry verify = explorerDatabase.cloudEntryDao().findByServiceType(OpenMode.GDRIVE.ordinal()).subscribeOn(Schedulers.trampoline()).blockingGet();
    assertEquals(1, verify.getId());
    assertEquals("abcd", verify.getPersistData().toString());
    verify = explorerDatabase.cloudEntryDao().findByServiceType(OpenMode.BOX.ordinal()).subscribeOn(Schedulers.trampoline()).blockingGet();
    assertEquals(3, verify.getId());
    assertEquals("ijkl", verify.getPersistData().toString());
    verify = explorerDatabase.cloudEntryDao().findByServiceType(OpenMode.DROPBOX.ordinal()).subscribeOn(Schedulers.trampoline()).blockingGet();
    assertEquals(2, verify.getId());
    assertEquals("efgh", verify.getPersistData().toString());
    verify = explorerDatabase.cloudEntryDao().findByServiceType(OpenMode.ONEDRIVE.ordinal()).subscribeOn(Schedulers.trampoline()).blockingGet();
    assertEquals(4, verify.getId());
    assertEquals("mnop", verify.getPersistData().toString());
    explorerDatabase.close();
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) CloudEntry(com.amaze.filemanager.database.models.explorer.CloudEntry) Test(org.junit.Test)

Example 18 with SupportSQLiteDatabase

use of androidx.sqlite.db.SupportSQLiteDatabase in project AmazeFileManager by TeamAmaze.

the class ExplorerDatabaseMigrationTest method migrateFromV5.

@Test
public void migrateFromV5() throws IOException {
    SupportSQLiteDatabase db = helper.createDatabase(TEST_DB, 5);
    db.close();
    ExplorerDatabase explorerDatabase = Room.databaseBuilder(InstrumentationRegistry.getInstrumentation().getTargetContext(), ExplorerDatabase.class, TEST_DB).addMigrations(MIGRATION_5_6, MIGRATION_6_7).build();
    explorerDatabase.getOpenHelper().getWritableDatabase();
    explorerDatabase.close();
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) Test(org.junit.Test)

Example 19 with SupportSQLiteDatabase

use of androidx.sqlite.db.SupportSQLiteDatabase in project AmazeFileManager by TeamAmaze.

the class ExplorerDatabaseMigrationTest method migrateFromV6.

@Test
public void migrateFromV6() throws IOException {
    SupportSQLiteDatabase db = helper.createDatabase(TEST_DB, 6);
    db.close();
    ExplorerDatabase explorerDatabase = Room.databaseBuilder(InstrumentationRegistry.getInstrumentation().getTargetContext(), ExplorerDatabase.class, TEST_DB).addMigrations(MIGRATION_6_7).build();
    explorerDatabase.getOpenHelper().getWritableDatabase();
    explorerDatabase.close();
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) Test(org.junit.Test)

Example 20 with SupportSQLiteDatabase

use of androidx.sqlite.db.SupportSQLiteDatabase in project AmazeFileManager by TeamAmaze.

the class MigrationTestHelper method openDatabase.

private SupportSQLiteDatabase openDatabase(String name, RoomOpenHelper roomOpenHelper) {
    SupportSQLiteOpenHelper.Configuration config = SupportSQLiteOpenHelper.Configuration.builder(mInstrumentation.getTargetContext()).callback(roomOpenHelper).name(name).build();
    SupportSQLiteDatabase db = mOpenFactory.create(config).getWritableDatabase();
    mManagedDatabases.add(new WeakReference<>(db));
    return db;
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) SupportSQLiteOpenHelper(androidx.sqlite.db.SupportSQLiteOpenHelper)

Aggregations

SupportSQLiteDatabase (androidx.sqlite.db.SupportSQLiteDatabase)24 Test (org.junit.Test)16 Cursor (android.database.Cursor)5 ContentValues (android.content.ContentValues)4 SupportSQLiteOpenHelper (androidx.sqlite.db.SupportSQLiteOpenHelper)3 SQLiteConstraintException (android.database.sqlite.SQLiteConstraintException)1 SQLiteException (android.database.sqlite.SQLiteException)1 Uri (android.net.Uri)1 SupportSQLiteQuery (androidx.sqlite.db.SupportSQLiteQuery)1 FrameworkSQLiteOpenHelperFactory (androidx.sqlite.db.framework.FrameworkSQLiteOpenHelperFactory)1 SqlDriver (app.cash.sqldelight.db.SqlDriver)1 AndroidSqliteDriver (app.cash.sqldelight.driver.android.AndroidSqliteDriver)1 CloudEntry (com.amaze.filemanager.database.models.explorer.CloudEntry)1 TestEpisode (com.battlelancer.seriesguide.provider.RoomDatabaseTestHelper.TestEpisode)1 MovieDetails (com.battlelancer.seriesguide.ui.movies.MovieDetails)1 SelectionBuilder (com.battlelancer.seriesguide.util.SelectionBuilder)1