1

I want to update my database by android room. But I can not find a way to do some thing like this:

UPDATE persondata SET age=age+1 where id=123;

So does room have this ability, and how can I do it? custom my Dao class?

2 Answers2

1

You can refer to this example of mine and modify yours accordingly.

@Query("UPDATE order_item SET Quantity = Quantity + 1 WHERE id = (:cart_id)") fun increaseCartQuantity(cart_id: Int)

shahooo
  • 563
  • 4
  • 14
0

You can update the object directly using the update annotation.

/**
 * Update an object from the database.
 *
 * @param obj the object to be updated
 */
@Update
fun update(obj: T): Int
Muthukrishnan Rajendran
  • 11,122
  • 3
  • 31
  • 41