use of android.database.sqlite.SQLiteQuery 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();
}
Aggregations