jeudi 16 avril 2015

Android Content Provider Update not working

I have a code which updates a column called status but the update is not taking place.


Here's how I call the provider:





ContentValues values = new ContentValues(1);
values.put(ChatDataProvider.COL_STATUS, 0);
getContentResolver().update(Uri.withAppendedPath(ChatDataProvider.CONTENT_URI_MESSAGES, "lastcliq/" + userIdOther.toString()), values, null, null);



And here's my update override:





@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
SQLiteDatabase db = dbHelper.getWritableDatabase();
int count = 0;
switch(uriMatcher.match(uri)) {
case MESSAGES_LAST_MSG_BY_ID:
count = db.update(TABLE_MESSAGES, values, COL_USER_ID_TO + " = ?", new String[]{uri.getLastPathSegment()});
break;
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}



The weird thing is "db.update" returns a count of 2 which is correct but the values of COL_STATUS is not set to 0 as when I query again, the same rows still have status=1.


All other methods in my Content Provider perform as expected. Any help/thoughts will be appreciated. Thanks!


Aucun commentaire:

Enregistrer un commentaire