October 25, 2024
Chicago 12, Melborne City, USA
SQL

Room DB Init if not exists by 2 combined colums


I have a Room Table with some colums.
enter image description here

Now I want to add another column. But it should only be added if the combination of Year and Week does not exists. Otherwise it should be Ignored.

@Insert(onConflict = OnConflictStrategy.IGNORE)
suspend fun initInsertWeek(week: Week)

How to archive that by an query?

This is "Week"

@Entity(tableName = "Weeks")

data class Week(

@PrimaryKey(autoGenerate = true)
val id: Long? = null,

val year: Int,
val week: Int,
val workingTime: Int,

@ColumnInfo(name = "timeStamp", defaultValue = "0")
val timeStamp: Long = 0,

@ColumnInfo(name = "weeklyWorkingDayCount", defaultValue = "5")
val weeklyWorkingDayCount: Int = 5,

@ColumnInfo(name = "weekDailyDurations", defaultValue = "462:462:462:462:462:0:0")
val weekDailyDurations: String = "462:462:462:462:462:0:0"

)

I hope you can help me.



You need to sign in to view this answers

Leave feedback about this

  • Quality
  • Price
  • Service

PROS

+
Add Field

CONS

+
Add Field
Choose Image
Choose Video