I want to update a specific column against a list of items/rows in a table. 1 way is to apply a loop on the update method, but is there any way to pass list of items and update that column for all, instead of doing it in loop?
Dao method:
@Query("UPDATE items SET is_processing=1 WHERE item_id=:id")
public abstract void updateProcessingStatus(String id);
Current update code:
public void updateStatusOfList(List<Item> items)
{
for(Item item:items)
myDao.updateProcessingStatus(item);
}
Just pass your list as a variable into the query:
@Query("UPDATE items SET is_processing=1 WHERE item_id in (:items) ")
public abstract void updateProcessingStatus(List<String> items);
You will probably need to create a String List from your Items list first.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With