Search in sources :

Example 1 with SQLiteQuery

use of android.database.sqlite.SQLiteQuery in project android_frameworks_base by DirtyUnicorns.

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 2 with SQLiteQuery

use of android.database.sqlite.SQLiteQuery in project android_frameworks_base by ResurrectionRemix.

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 3 with SQLiteQuery

use of android.database.sqlite.SQLiteQuery in project android_frameworks_base by ParanoidAndroid.

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 4 with SQLiteQuery

use of android.database.sqlite.SQLiteQuery in project platform_frameworks_base by android.

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 5 with SQLiteQuery

use of android.database.sqlite.SQLiteQuery in project android_frameworks_base by AOSPA.

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)

Aggregations

Cursor (android.database.Cursor)6 SQLiteCursor (android.database.sqlite.SQLiteCursor)6 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