gpt4 book ai didi

android-room - android Room,如何通过id列表删除表中的多行

转载 作者:行者123 更新时间:2023-12-01 07:33:19 29 4
gpt4 key购买 nike

拥有三张 table 的 Android Room timestamp , index , details ,并且这三个都有

@PrimaryKey @ColumnInfo(name = "id") var id: Int = 0

fun clearDataByID(idList: List<Int>)通过 id 清除所有三个表中的数据在 idList
道为:
@Dao
interface DataDAO {


@Transaction
fun clearDataByID(idList: List<Int>) {
deleteDataInTimestamp(idList)
deleteDataIndex(idList)
deleteDataDetails(idList)
}

@Query("delete from timestamp where id in :idList")
fun deleteDataInTimestamp(idList: List<Int>)

@Query("delete from index where id in :idList")
fun deleteDataIndex(idList: List<Int>)

@Query("delete from details where id in :idList")
fun deleteDataDetails(idList: List<Int>)
}

但它会出现编译器错误(所有三个都类似)
error: no viable alternative at input 'delete from timestamp where id in :idList'
public abstract void deleteDataInTimestamp(@org.jetbrains.annotations.NotNull()

如果通过单个 id 删除它工作。

如何通过 id 列表删除?
@Query("delete from timestamp where id = :id")
fun deleteSingleTimestamp(id: Int)

最佳答案

感谢西蒙指出了类似的问题,应该这样做:

@Query("delete from timestamp where id in (:idList)")
fun deleteDataInTimestamp(idList: List<Int>)

关于android-room - android Room,如何通过id列表删除表中的多行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55478489/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com