Updates and Deletes

So far we have talked about queries and inserts; updates and deletes are fairly straightforward. Performing an update is similar to performing an insert, in which changed column values are passed through a ContentValues object. Here is the signature of an update method on the ContentResolver object:

int numberOfRowsUpdated = activity.getContentResolver().update( Uri uri,

ContentValues values, String whereClause, String[] selectionArgs )

The whereClause argument will constrain the update to the pertinent rows. Similarly, the signature for the delete method is int numberOfRowsDeleted = activity.getContentResolver().update( Uri uri,

String whereClause, String[] selectionArgs )

Clearly a delete method will not require the ContentValues argument because you will not need to specify the columns you want when you are deleting a record.

Almost all the calls from managedOuery and ContentResolver are directed eventually to the provider class. Knowing how a provider implements each of these methods gives us enough clues as to how those methods are used by a client. In the next section, we'll cover the implementation from scratch of an example content provider called BookProvider.

0 0

Post a comment