Refresh an item in a database without all columns specified in ContentValues

For example, I have four columns: first_name, last_name, phone_numberand picture. Somewhere in my code is:

ContentValues values = new ContentValues();
values.put(MyPerson.FIRST_NAME, "Ted");
values.put(MyPerson.LAST_NAME, "Johnson");
values.put(MyPerson.PHONE_NUMBER, "111-111-1111");
values.put(MyPerson.PICTURE, "file://tedpicture.jpeg");

getContentResolver().update(tedUri, values, null, null);

Can I run something like:

ContentValues values = new ContentValues();
values.put(MyPerson.PHONE_NUMBER, "222-222-2222");

getContentResolver().update(tedUri, values, null, null);

And expect the columns first_name, last_nameand picturewill have the same values ​​as when they were first set. Or do I need to fill in the columns as well first_name, last_nameand picture?

+3
source share
3 answers

To answer your question, yes, you can only pass one data field to the update, and it will update this column without affecting the others.

, , , .

:

public int update (String table, ContentValues values, String whereClause, String[] whereArgs)

null .

- , .

ContentValues values = new ContentValues();
values.put(MyPerson.PHONE_NUMBER, "222-222-2222");
getContentResolver().update(tedUri, values, "first_name = ?", new String[] { "tom" });

- tom, 222-222-2222

+9

, , .

0

where 3-

getContentResolver().update(tedUri, values, "first_name=?", new String
         [ ]{"name"});
0

Source: https://habr.com/ru/post/1785760/


All Articles