Skip to content

Instantly share code, notes, and snippets.

@udacityandroid
Last active November 13, 2019 20:46
Show Gist options
  • Save udacityandroid/266e8875e63b25d219f153ba72613ea9 to your computer and use it in GitHub Desktop.
Save udacityandroid/266e8875e63b25d219f153ba72613ea9 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);
}
}
@moreghz
Copy link

moreghz commented Sep 22, 2016

Code is missing the last curly brace!

Copy link

ghost commented Sep 27, 2016

+1, last brace missing

@udacityandroid
Copy link
Author

Added, thanks guys!

@leenorshn
Copy link

you are right at mine all codes are now design by me

@djnotes
Copy link

djnotes commented Jun 8, 2017

@udacityandroid I really love the way you teach Android. Best course I have ever taken!

@sauravvishal8797
Copy link

Is it necessary to use final with variable match?

@Mayur1496
Copy link

It is a better practice to use final with variables whose values we don't want to change in future.

@RuslanPrimak
Copy link

@Babadzhanov
Copy link

Yep wrong link 👍 Basically the solution is in the quiz!

@Nikoloutsos
Copy link

I have a question:
What is the selection and selectionArgs if we wanted to delete the rows which they have the name "totti" and are male at the same time.

@VaidotasK
Copy link

@Nikoloutsos I think it would be selection = name + "=? AND " + gender + "=?";
selectArgs[] = {"totti", "male"}

@biddlecom
Copy link

Yeah... I was like, "Ok... paste the gist.... ok.... uhm.... looks complete to me. What did I miss???? Did I just cheat?!?! Oh.... they gave us the answer." Well, crap, so much for trying on my own. LOL!

@nedgit
Copy link

nedgit commented Oct 15, 2018

Your Task: Implement delete() method . . . . . . by cut 'n' paste, go on you can do it, I have faith in you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment