diff --git a/app/src/main/java/com/example/android/pets/data/PetProvider.java b/app/src/main/java/com/example/android/pets/data/PetProvider.java index 78f23282..dd3c8935 100644 --- a/app/src/main/java/com/example/android/pets/data/PetProvider.java +++ b/app/src/main/java/com/example/android/pets/data/PetProvider.java @@ -175,11 +175,6 @@ private Uri insertPet(Uri uri, ContentValues values) { return ContentUris.withAppendedId(uri, id); } - @Override - public int delete(Uri uri, String s, String[] strings) { - return 0; - } - @Override public int update(Uri uri, ContentValues contentValues, String selection, String[] selectionArgs) { @@ -246,4 +241,24 @@ private int updatePet(Uri uri, ContentValues values, String selection, String[] // Returns the number of database rows affected by the update statement return database.update(PetEntry.TABLE_NAME, values, selection, selectionArgs); } + + @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); + } + } }