Forked from udacityandroid/Excerpt from PetProvider.java
Created
October 4, 2016 10:43
-
-
Save jchackDragon/632d0c7cb5800f7930a4c4c3503d0dd2 to your computer and use it in GitHub Desktop.
Pets app - Replace delete() method in PetProvider
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @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