我知道我不能在查询中使用 DELETE
(顺便说一句,这很遗憾),我会收到以下错误:
<i>Error:error: Observable query return type (LiveData, Flowable etc) can only be used with SELECT queries that directly or indirectly (via @Relation, for example) access at least one table.</i>
但我不能使用 @Delete(WHERE... xxx)
那么如何通过参数删除特定行呢?
最佳答案
其实你可以使用@Query
来进行删除。
@Query("DELETE FROM users WHERE user_id = :userId")
abstract void deleteByUserId(long userId);
摘自 Query javadoc :
UPDATE or DELETE queries can return void or int. If it is an int, the value is the number of rows affected by this query.
关于java - Android Room @Delete 带参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47538857/