Your code should update every row that matches your WHERE
clause. If you know there are extra rows that should be matching but aren't, then something is wrong there.
One possible way to test: You might first want to query for things that match ContactsContract.CommonDataKinds.Phone.NUMBER
for the given ContactsContract.Data.RAW_CONTACT_ID
and see how many things are returned.
If necessary (though I'm not sure how precisely this is different than what you're already doing), iterate over your results while(cursor.moveToNext())
and if the phone number matches the one you're trying to update, update
it.
Note that this is untested, off-the-cuff code, so there are probably small bugs, and that if you were doing this for real you would want to use a List<ContentProviderOperation>
and then do a batch operation, instead of doing this one by one.
ContentResolver resolver = getContentResolver();
String[] columnsToReturn = {Data._ID, ContactsContract.CommonDataKinds.Phone.NUMBER}
// This should return all of the phone numbers that match your criteria
Cursor cursor = resolver.query(ContactsContract.Data.CONTENT_URI, columnsToReturn, phoneWhere, phoneWhereParams, null);
while(cursor != null && cursor.moveToNext()){
// This code doesn't do this, but you might want to see how many items
// are returned in your cursor here to verify that you're getting what
// you should for some known case..
// I'm using the row ID here (Data._ID) to update, instead of your initial WHERE
resolver.update(ContactsContract.Data.CONTENT_URI, values, Data._ID + "=?", cursor.getString(cursor.getColumnId(Data._ID));
}
It should not even be necessary to perform the query first, if you get everything set up correctly in your UPDATE
statement.
You may also find the chunk of code attached to this question useful.