Search in sources :

Example 6 with SQLiteCursor

use of android.database.sqlite.SQLiteCursor in project android_frameworks_base by crdroidandroid.

the class DatabaseCursorTest method testRequeryWithAlteredSelectionArgs.

@MediumTest
public void testRequeryWithAlteredSelectionArgs() throws Exception {
    /**
         * Test the ability of a subclass of SQLiteCursor to change its query arguments.
         */
    populateDefaultTable();
    SQLiteDatabase.CursorFactory factory = new SQLiteDatabase.CursorFactory() {

        public Cursor newCursor(SQLiteDatabase db, SQLiteCursorDriver masterQuery, String editTable, SQLiteQuery query) {
            return new SQLiteCursor(db, masterQuery, editTable, query) {

                @Override
                public boolean requery() {
                    setSelectionArguments(new String[] { "2" });
                    return super.requery();
                }
            };
        }
    };
    Cursor c = mDatabase.rawQueryWithFactory(factory, "SELECT data FROM test WHERE _id <= ?", new String[] { "1" }, null);
    assertNotNull(c);
    assertEquals(1, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));
    // Our hacked requery() changes the query arguments in the cursor.
    c.requery();
    assertEquals(2, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));
    assertTrue(c.moveToNext());
    assertEquals(sString2, c.getString(0));
    // Test that setting query args on a deactivated cursor also works.
    c.deactivate();
    c.requery();
}
Also used : SQLiteCursorDriver(android.database.sqlite.SQLiteCursorDriver) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) SQLiteQuery(android.database.sqlite.SQLiteQuery) SQLiteCursor(android.database.sqlite.SQLiteCursor) Cursor(android.database.Cursor) SQLiteCursor(android.database.sqlite.SQLiteCursor) MediumTest(android.test.suitebuilder.annotation.MediumTest)

Example 7 with SQLiteCursor

use of android.database.sqlite.SQLiteCursor in project robolectric by robolectric.

the class ShadowMergeCursorTest method setupTable.

private SQLiteCursor setupTable(final String createSql, final String[] insertions, final String selectSql) {
    database.execSQL(createSql);
    for (String insert : insertions) {
        database.execSQL(insert);
    }
    Cursor cursor = database.rawQuery(selectSql, null);
    assertThat(cursor).isInstanceOf(SQLiteCursor.class);
    return (SQLiteCursor) cursor;
}
Also used : MergeCursor(android.database.MergeCursor) Cursor(android.database.Cursor) SQLiteCursor(android.database.sqlite.SQLiteCursor) SQLiteCursor(android.database.sqlite.SQLiteCursor)

Aggregations

Cursor (android.database.Cursor)7 SQLiteCursor (android.database.sqlite.SQLiteCursor)7 SQLiteCursorDriver (android.database.sqlite.SQLiteCursorDriver)6 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)6 SQLiteQuery (android.database.sqlite.SQLiteQuery)6 MediumTest (android.test.suitebuilder.annotation.MediumTest)6 MergeCursor (android.database.MergeCursor)1