如果不为空,则列的On On冲突替换策略

时间:2019-10-02 06:58:41

标签: kotlin android-sqlite android-room

我有实体MySurvey,而MySurvey的列名为answers,如下所示:

我的调查

@Entity(tableName = "my_survey")
data class MySurvey(@PrimaryKey var _id: String = "",
                    var created_at: String = "",
                    var conducted_at: String? = "",
                    var cancellation_reason: String?,
                    var enumeratorId: String = AppPreferences.getString(Enumerator_Id, "default"),
                    @Embedded(prefix = "basic_") var survey: SurveyBasic,
                    @Embedded(prefix = "location_") var location: SurveyLocationBasic?,
                    var ended_at: String? = "",
                    var status: MySurveyStatus = MySurveyStatus.OFFLINE,
                    @Embedded var stats: Stats?,
                    var uploaded: Boolean,
                    var answers: List<AnswersResponse>? = listOf()
)

MySurveyDAO

@Dao
interface MySurveyDAO {

    @Insert(onConflict = REPLACE)
    fun insert(mySurvey: MySurvey): Long

    @Insert(onConflict = REPLACE)
    fun insert(savedSurvey: List<MySurvey>)
}

有一个列表屏幕,该屏幕从没有MySurvey的API中提取answers个数组。当基于MySurvey获取特定ID并且具有answers对象的详细信息屏幕时。我使用onConflict = REPLACE策略在数据库中进行了更新。效果很好,但是当我恢复列表屏幕时,数据库的所有记录都有answers列为NULL,这是由于REPLACE策略所致。

  

是否有一种方法可以添加仅REPLACE列为IF IT IS NOT NULL的条件?

0 个答案:

没有答案