Reputation: 493
Maybe this question has been answered but I cannot find it, so:
In SQLiteDatabase update method,
int android.database.sqlite.SQLiteDatabase.update(String table, ContentValues values, String whereClause, String[] whereArgs)
What will happen if the WHERE clause does not exists?. I mean does not return any row, it will perform a normal insert, or do nothing?
EDIT
I think I did not explain it correctly.
Suppose this SQL:
CREATE TABLE weight (weight REAL, date TEXT);
INSERT INTO weight VALUES (78.5,"10/03/2013");
INSERT INTO weight VALUES (68.5,"09/03/2013");
INSERT INTO weight VALUES (79.5,"08/03/2013");
And now suppose this code:
ContentValues values = new ContentValues();
values.put("weight", 90.2);
db.update("weight",values, "date = '15/03/2013'",null);
NOTICE that there is no row with date = '15/03/2013' so, what happen in that case (that was what I wanted to mean) it will insert or do nothing?
Upvotes: 1
Views: 9524
Reputation: 20155
Edit:
It will check is there a row with date = '15/03/2013 if there is no row, then no rows will effect, and the update method will return 0
If I understand your question, Where claus is optional, it may be null, if you don't provide where clause it will update all the rows in a table.
It is just a sql thing, like if you don't supply where condition it will update all rows. documentation clearly says that,
Parameters
whereClause the optional WHERE clause to apply when updating. Passing null will update all rows.
Upvotes: 1
Reputation: 6711
if you don't use the WHERE
clause all the records on the table will be affected
whereClause the optional WHERE clause to apply when updating. Passing null will update all rows.
Upvotes: 0