Java Code Examples for android.database.DatabaseUtils#concatenateWhere()

The following examples show how to use android.database.DatabaseUtils#concatenateWhere() . 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: LoaderThrottle.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handle deleting data.
 */
@Override
public int delete(Uri uri, String where, String[] whereArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    String finalWhere;

    int count;

    switch (mUriMatcher.match(uri)) {
        case MAIN:
            // If URI is main table, delete uses incoming where clause and args.
            count = db.delete(MainTable.TABLE_NAME, where, whereArgs);
            break;

            // If the incoming URI matches a single note ID, does the delete based on the
            // incoming data, but modifies the where clause to restrict it to the
            // particular note ID.
        case MAIN_ID:
            // If URI is for a particular row ID, delete is based on incoming
            // data but modified to restrict to the given ID.
            finalWhere = DatabaseUtils.concatenateWhere(
                    MainTable._ID + " = " + ContentUris.parseId(uri), where);
            count = db.delete(MainTable.TABLE_NAME, finalWhere, whereArgs);
            break;

        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);

    return count;
}
 
Example 2
Source File: LoaderThrottle.java    From codeexamples-android with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Handle updating data.
 */
@Override
public int update(Uri uri, ContentValues values, String where, String[] whereArgs) {
    SQLiteDatabase db = mOpenHelper.getWritableDatabase();
    int count;
    String finalWhere;

    switch (mUriMatcher.match(uri)) {
        case MAIN:
            // If URI is main table, update uses incoming where clause and args.
            count = db.update(MainTable.TABLE_NAME, values, where, whereArgs);
            break;

        case MAIN_ID:
            // If URI is for a particular row ID, update is based on incoming
            // data but modified to restrict to the given ID.
            finalWhere = DatabaseUtils.concatenateWhere(
                    MainTable._ID + " = " + ContentUris.parseId(uri), where);
            count = db.update(MainTable.TABLE_NAME, values, finalWhere, whereArgs);
            break;

        default:
            throw new IllegalArgumentException("Unknown URI " + uri);
    }

    getContext().getContentResolver().notifyChange(uri, null);

    return count;
}