Search in sources :

Example 21 with SupportSQLiteDatabase

use of androidx.sqlite.db.SupportSQLiteDatabase in project Rocket by mozilla-tw.

the class HistoryProvider method update.

@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
    if (sUriMatcher.match(uri) != BROWSING_HISTORY) {
        throw new UnsupportedOperationException("URI: " + uri);
    }
    final SupportSQLiteDatabase db = mDbHelper.getWritableDatabase();
    final int count = db.update(Tables.BROWSING_HISTORY, OnConflictStrategy.ROLLBACK, values, selection, selectionArgs);
    if (count > 0) {
        notifyBrowsingHistoryChange();
    }
    return count;
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase)

Example 22 with SupportSQLiteDatabase

use of androidx.sqlite.db.SupportSQLiteDatabase in project Rocket by mozilla-tw.

the class HistoryProvider method query.

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    if (sUriMatcher.match(uri) != BROWSING_HISTORY) {
        throw new IllegalArgumentException("URI: " + uri);
    }
    final SupportSQLiteDatabase db = mDbHelper.getReadableDatabase();
    SupportSQLiteQuery query = SupportSQLiteQueryBuilder.builder(Tables.BROWSING_HISTORY).columns(projection).selection(selection, selectionArgs).orderBy(sortOrder).limit(ProviderUtils.getLimitParam(uri.getQueryParameter("offset"), uri.getQueryParameter("limit"))).create();
    return db.query(query);
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) SupportSQLiteQuery(androidx.sqlite.db.SupportSQLiteQuery)

Example 23 with SupportSQLiteDatabase

use of androidx.sqlite.db.SupportSQLiteDatabase in project Rocket by mozilla-tw.

the class HistoryProvider method insert.

@Override
public Uri insert(Uri uri, ContentValues initialValues) {
    final SupportSQLiteDatabase db = mDbHelper.getWritableDatabase();
    long id;
    switch(sUriMatcher.match(uri)) {
        case BROWSING_HISTORY:
            final ContentValues values = new ContentValues(initialValues);
            id = insertWithUrlUnique(db, values);
            break;
        default:
            throw new UnsupportedOperationException("URI: " + uri);
    }
    if (id < 0) {
        return null;
    } else {
        notifyBrowsingHistoryChange();
        return ContentUris.withAppendedId(uri, id);
    }
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) ContentValues(android.content.ContentValues)

Example 24 with SupportSQLiteDatabase

use of androidx.sqlite.db.SupportSQLiteDatabase in project Rocket by mozilla-tw.

the class TabDaoTest method migrationFrom1To2_containsCorrectData.

@Test
public void migrationFrom1To2_containsCorrectData() throws IOException {
    // Create the database in version 1
    SupportSQLiteDatabase db = testHelper.createDatabase(TEST_DB_NAME, 1);
    // Insert some data
    insertTabV1(TAB, db);
    insertTabV1(TAB_2, db);
    db.close();
    // Re-open the database with version 2 and provide MIGRATION_1_2 as the migration process.
    testHelper.runMigrationsAndValidate(TEST_DB_NAME, 2, true, TabsDatabase.MIGRATION_1_2);
    // MigrationTestHelper automatically verifies the schema changes, but not the data validity
    // Validate that the data was migrated properly.
    List<TabEntity> dbTabs = getMigratedRoomDatabase().tabDao().getTabs();
    assertEquals(2, dbTabs.size());
    assertTabEquals(TAB, dbTabs.get(0));
    assertTabEquals(TAB_2, dbTabs.get(1));
}
Also used : SupportSQLiteDatabase(androidx.sqlite.db.SupportSQLiteDatabase) Test(org.junit.Test)

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