0

I have tried to browse it here, but i couldn't find a solution. The problem is,

I have a database, and i want to update a column in the database, such that the updated value is 1 less than the previous.. Basically, in SQL, it UPDATE TABLE TNAME SET VAL=VAL-1 where

How do i do that in Android? I tried doing this

ContentValues args = new ContentValues();
args.put(KEY_ROWID, "KEY_ROWID-1");
db.update(DATABASE_TABLE, args, KEY_ROWID + ">0", null);

But this doesn't work.

I will be thankful if you can help me with this!

Nithin

nithinreddy
  • 5,996
  • 4
  • 36
  • 43

2 Answers2

2
SQLiteStatement stmt = db.compileStatement("UPDATE TABLE TNAME SET VAL=VAL-1");
stmt.execute();
Shane Wealti
  • 2,162
  • 3
  • 18
  • 32
1

If you already have a working SQL-syntax, there is no need to "build" it in Android. You can for example use a PreparedStatement (which accepts an SQL-String) and use your Query there.

A nice example can be found here.

Community
  • 1
  • 1
Lukas Knuth
  • 24,328
  • 14
  • 80
  • 107