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?
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?
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)
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