TypeConverter not working when updating List in Room Database

后端 未结 2 551
终归单人心
终归单人心 2021-01-20 17:15

My query is showing a syntax error in the DAO_Impl build for some reason. I tried a rebuild but it still errors when conducting the following query:

Query:



        
2条回答
  •  南笙
    南笙 (楼主)
    2021-01-20 17:55

    Not too happy with this fix but I eventually served my purpose by creating a separate class that holds the value of the lists daysOfWeek and daysOfMonth:

    Interval:

    class Interval(_daysOfWeek: MutableList = mutableListOf(false, false, false, false, false, false, false),
                   _daysOfMonth: MutableList = mutableListOf(false, false, false, false, false, false, false, false, false,
                       false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false,
                       false, false, false, false, false, false)
    )
    {
        val daysOfWeek = _daysOfWeek
        val daysOfMonth = _daysOfMonth
    }
    

    and then just added a custom converter for this. Now I can query an update:

    @Query("UPDATE TasksTable SET name = :name, frequency = :frequency, interval = :interval, haveSchedule = :haveSchedule, schedule = :schedule, scheduleString = :scheduleString, description = :description, showProgressLayout = :showProgressLayout, intervals = :intervals WHERE taskID = :taskID")
    fun updateTask(taskID: Int, name: String, frequency: Int, interval: Int, haveSchedule: Boolean, schedule: Int, scheduleString: String, description: String, showProgressLayout: Boolean, intervals: Interval)
    

提交回复
热议问题