0

I want to update a row in a table, updating all the columns to new values except one that should keep the greatest value between the old and newValue.

Is there some way of doing this without creating the raw query (for example using the update(String table, ContentValues values, String whereClause, String\[\] whereArgs) function or other similar using ContentValues) in order to seize the character scaping and other advantages of that providers?

The query I want to achieve is something like:

UPDATE users SET name='newName', address='newAddress',
                 lastLogin=GREATEST(lastLogin,1348757941);
3
  • not that i know of. I don't think you can put functions in ContentValues (you can still try to put the string "max(something)" as you would in a rawQuery) or you can try to figure out something with the where clause. Can you post the rawQuery ? Commented Sep 27, 2012 at 14:55
  • I'd need a function in the ContentValues. Posted the raw query Commented Sep 27, 2012 at 15:00
  • 1
    I doubt you could put the max function is the contentValue, as the escaping is probably made to prevent things like that. I don't see a way of doing this without rawQuery (but i'm no expert in sqlite) Commented Sep 28, 2012 at 7:47

1 Answer 1

1

The GREATEST function is actually called MAX:

UPDATE users
SET name = 'newName',
    address = 'newAddress',
    lastLogin = MAX(lastLogin, 1348757941)
Sign up to request clarification or add additional context in comments.

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.