1

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?

4
  • Thanks @Pragnani I didn't notice that. Commented Mar 17, 2013 at 12:41
  • It says right in the docs for the parameter 'whereClause' developer.android.com/reference/android/database/sqlite/…, android.content.ContentValues, java.lang.String, java.lang.String[]) Commented Mar 17, 2013 at 12:48
  • You should delete this question now Commented Mar 17, 2013 at 12:48
  • updated answer, check [email protected] Commented Mar 17, 2013 at 13:59

2 Answers 2

1

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.

SqlliteData Update

Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.