Merge "Treat updates into non-existent body rows as inserts." into jb-ub-mail-ur10

This commit is contained in:
Yu Ping Hu 2013-10-21 23:46:14 +00:00 committed by Android (Google) Code Review
commit b8ef7da634
2 changed files with 12 additions and 0 deletions

View File

@ -314,6 +314,8 @@ public abstract class EmailContent {
public static final class Body extends EmailContent implements BodyColumns {
public static final String TABLE_NAME = "Body";
public static final String SELECTION_BY_MESSAGE_KEY = MESSAGE_KEY + "=?";
public static Uri CONTENT_URI;
public static void initBody() {

View File

@ -1857,6 +1857,16 @@ public class EmailProvider extends ContentProvider {
}
break;
case BODY:
result = db.update(tableName, values, selection, selectionArgs);
if (result == 0 && selection.equals(Body.SELECTION_BY_MESSAGE_KEY)) {
// TODO: This is a hack. Notably, the selection equality test above
// is hokey at best.
LogUtils.i(TAG, "Body Update to non-existent row, morphing to insert");
final ContentValues insertValues = new ContentValues(values);
insertValues.put(EmailContent.Body.MESSAGE_KEY, selectionArgs[0]);
insert(EmailContent.Body.CONTENT_URI, insertValues);
}
break;
case MESSAGE:
case UPDATED_MESSAGE:
case ATTACHMENT: