Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@moreghz moreghz commented Sep 22, 2016

Code is missing the last curly brace!

@ghost

This comment has been minimized.

Copy link

@ghost ghost commented Sep 27, 2016

+1, last brace missing

@udacityandroid

This comment has been minimized.

Copy link
Owner Author

@udacityandroid udacityandroid commented Oct 21, 2016

Added, thanks guys!

@leenorshn

This comment has been minimized.

Copy link

@leenorshn leenorshn commented Nov 3, 2016

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

@djnotes

This comment has been minimized.

Copy link

@djnotes djnotes commented Jun 8, 2017

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

@sauravvishal8797

This comment has been minimized.

Copy link

@sauravvishal8797 sauravvishal8797 commented Jun 16, 2017

Is it necessary to use final with variable match?

@Mayur1496

This comment has been minimized.

Copy link

@Mayur1496 Mayur1496 commented Aug 22, 2017

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

@RuslanPrimak

This comment has been minimized.

Copy link

@RuslanPrimak RuslanPrimak commented Mar 8, 2018

@Babadzhanov

This comment has been minimized.

Copy link

@Babadzhanov Babadzhanov commented Jun 4, 2018

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

@Nikoloutsos

This comment has been minimized.

Copy link

@Nikoloutsos Nikoloutsos commented Jun 15, 2018

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

This comment has been minimized.

Copy link

@VaidotasK VaidotasK commented Aug 13, 2018

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

@biddlecom

This comment has been minimized.

Copy link

@biddlecom biddlecom commented Sep 4, 2018

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

This comment has been minimized.

Copy link

@nedgit 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