Java Code Examples for android.database.Cursor#requery()

The following examples show how to use android.database.Cursor#requery() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ContentQueryMap.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/** Requeries the cursor and reads the contents into the cache */
public void requery() {
    final Cursor cursor = mCursor;
    if (cursor == null) {
        // If mCursor is null then it means there was a requery() in flight
        // while another thread called close(), which nulls out mCursor.
        // If this happens ignore the requery() since we are closed anyways.
        return;
    }
    mDirty = false;
    if (!cursor.requery()) {
        // again, don't do anything if the cursor is already closed
        return;
    }
    readCursorIntoCache(cursor);
    setChanged();
    notifyObservers();
}
 
Example 2
Source File: MergeCursor.java    From libcommon with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
@Override
public boolean requery() {
	synchronized (mCursors) {
		for (final Cursor cursor: mCursors) {
			if (cursor == null) {
				continue;
			}
			if (!cursor.requery()) {
				return false;
			}

		}
	}
	return true;
}
 
Example 3
Source File: DatabaseCursorTest.java    From sqlite-android with Apache License 2.0 6 votes vote down vote up
@MediumTest
@Test
public void testRequeryWithSelection() {
    populateDefaultTable();

    Cursor c = mDatabase.rawQuery("SELECT data FROM test WHERE data = '" + sString1 + "'",
            null);
    assertNotNull(c);
    assertEquals(1, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));
    c.deactivate();
    c.requery();
    assertEquals(1, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));
    c.close();
}
 
Example 4
Source File: DatabaseCursorTest.java    From sqlite-android with Apache License 2.0 6 votes vote down vote up
@MediumTest
@Test
public void testRequeryWithSelectionArgs() {
    populateDefaultTable();

    Cursor c = mDatabase.rawQuery("SELECT data FROM test WHERE data = ?",
            new String[]{sString1});
    assertNotNull(c);
    assertEquals(1, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));
    c.deactivate();
    c.requery();
    assertEquals(1, c.getCount());
    assertTrue(c.moveToFirst());
    assertEquals(sString1, c.getString(0));
    c.close();
}
 
Example 5
Source File: SqliteWrapper.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
public static boolean requery(Context context, Cursor cursor) {
    try {
        return cursor.requery();
    } catch (SQLiteException e) {
        Log.e(TAG, "Catch a SQLiteException when requery: ", e);
        checkSQLiteException(context, e);
        return false;
    }
}
 
Example 6
Source File: DatabaseCursorTest.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
@MediumTest
@Test
public void testRequery() {
    populateDefaultTable();

    Cursor c = mDatabase.rawQuery("SELECT * FROM test", null);
    assertNotNull(c);
    assertEquals(3, c.getCount());
    c.deactivate();
    c.requery();
    assertEquals(3, c.getCount());
    c.close();
}
 
Example 7
Source File: DatabaseCursorTest.java    From sqlite-android with Apache License 2.0 5 votes vote down vote up
@MediumTest
@Test
public void testRequeryWithAlteredSelectionArgs() {
    // 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(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();
}
 
Example 8
Source File: SqliteWrapper.java    From squidb with Apache License 2.0 5 votes vote down vote up
public static boolean requery(Context context, Cursor cursor) {
    try {
        return cursor.requery();
    } catch (SQLiteException e) {
        Log.e(TAG, "Catch a SQLiteException when requery: ", e);
        checkSQLiteException(context, e);
        return false;
    }
}
 
Example 9
Source File: FanfouServiceManager.java    From fanfouapp-opensource with Apache License 2.0 5 votes vote down vote up
public static void doFavorite(final Activity activity, final Status s,
        final Cursor c) {
    final ActionResultHandler li = new ActionResultHandler() {
        @Override
        public void onActionSuccess(final int type, final String message) {
            c.requery();
        }
    };
    FanfouServiceManager.doFavorite(activity, s, li);
}
 
Example 10
Source File: UIManager.java    From fanfouapp-opensource with Apache License 2.0 5 votes vote down vote up
public static void doDelete(final Activity activity, final Status s,
        final Cursor c) {
    final ActionResultHandler li = new ActionResultHandler() {
        @Override
        public void onActionSuccess(final int type, final String message) {
            c.requery();
        }
    };
    FanfouServiceManager.doStatusDelete(activity, s.id, li);
}