简体   繁体   中英

How can I use SQL “NOT IN” Operator with Room

@Query("UPDATE items SET saved=:saved WHERE id IN :itemsIds") // works
abstract void method1(List<Long> itemsIds, boolean saved);

@Query("UPDATE items SET saved=:saved WHERE id NOT IN :itemsIds") // ERROR!!
abstract void method2(List<Long> itemsIds, boolean saved);

@Transaction
void updatePreferredItems(@NonNull List<Long> prefItems) {
    method1(prefItems, true);
    method2(prefItems, false);
}

My objective is from an ids list I would like to to update the field saved of all the items to true if item id belong to ids list, false otherwise.

Why the second query is generating a compile error ?

Is this the right approach ?

What happens when you do this:

@Query("UPDATE items SET saved=:saved WHERE NOT(id IN :itemsIds)") // ERROR??
abstract void method2(List<Long> itemsIds, boolean saved);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM