You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Configure a table with a duration column type that is nullable
Write a row with null into that duration column
Read that row back
In code:
Table definition
object SampleDurationTable : UUIDTable("duration_example_table") {
val elapsedDuration = duration("elapsed_duration").nullable()
val elapsedDouble = double("elapsed_double").nullable()
fun insert(duration: Duration?) = insertAndGetId {
it[elapsedDuration] = duration?.toJavaDuration()
it[elapsedDouble] = duration?.inSeconds
}
}
Test case
@Test
fun `null duration`() {
// Sets up in-memory SQLite database
@Suppress("UNUSED_VARIABLE") val db = Db(type = Db.Type.Memory)
transaction {
SampleDurationTable.insert(null)
assertEquals(1, SampleDurationTable.selectAll().count())
val row = SampleDurationTable.selectAll().first()
val doubleItem = row.getOrNull(SampleDurationTable.elapsedDouble)
val durationItem = row.getOrNull(SampleDurationTable.elapsedDuration)?.toKotlinDuration()
assertNull(doubleItem, "Got $doubleItem instead of null double") // pass
assertNull(durationItem, "Got $durationItem instead of null duration") // fail
}
}
RESULTS
Actual:
Duration is converted to 0
Expected:
Duration should continue to be null
NOTES
I tested this with an on-disk database, and found that null is being written when I inspect the database directly. So it appears the bug might be occurring when the data is being read back
WORKAROUND
Manually convert Duration type into another representation, such as Double.
The text was updated successfully, but these errors were encountered:
STEPS TO REPRODUCE
duration
column type that is nullablenull
into that duration columnIn code:
Table definition
Test case
RESULTS
Actual:
Duration is converted to 0
Expected:
Duration should continue to be null
NOTES
I tested this with an on-disk database, and found that
null
is being written when I inspect the database directly. So it appears the bug might be occurring when the data is being read backWORKAROUND
Manually convert Duration type into another representation, such as Double.
The text was updated successfully, but these errors were encountered: