Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save yesabdelkader/64d0d764ed13528c490cb8f775386ca6 to your computer and use it in GitHub Desktop.
Save yesabdelkader/64d0d764ed13528c490cb8f775386ca6 to your computer and use it in GitHub Desktop.
Pets app - Replace delete() method in PetProvider
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
// Get writeable database
SQLiteDatabase database = mDbHelper.getWritableDatabase();
final int match = sUriMatcher.match(uri);
switch (match) {
case PETS:
// Delete all rows that match the selection and selection args
return database.delete(PetEntry.TABLE_NAME, selection, selectionArgs);
case PET_ID:
// Delete a single row given by the ID in the URI
selection = PetEntry._ID + "=?";
selectionArgs = new String[] { String.valueOf(ContentUris.parseId(uri)) };
return database.delete(PetEntry.TABLE_NAME, selection, selectionArgs);
default:
throw new IllegalArgumentException("Deletion is not supported for " + uri);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment