是否有办法更新实体的列仅当列为空时?这是我的DAO界面中的更新功能:
@Query("UPDATE media SET media_name = :mediaName, media_data = :mediaData WHERE id = :id")
fun update(id: Int, mediaName: String?, mediaData: String?)
...因为截至目前,值为" null"已针对这些列进行更新。
答案 0 :(得分:1)
您可以尝试:
@Query("UPDATE media SET media_name = (CASE WHEN media_name IS NULL THEN :mediaName ELSE media_name END), media_data = (CASE WHEN media_data IS NULL THEN :mediaData ELSE media_data END) WHERE id = :id")
fun update(id: Int, mediaName: String?, mediaData: String?)