Skip to content

Bug for SqlType.transform when transforming database null values of JVM primitive types.  #400

Closed
@vincentlauvlwj

Description

@vincentlauvlwj

Code to reproduce this issue:

enum class Status(val code: Int) {
    ONE(1), TWO(2), THREE(3);

    companion object {
        fun forCode(code: Int): Status {
            return values().first { it.code == code }
        }
    }
}

@Test
fun testTransformingNullValues() {
    val t = object : Table<Nothing>("T_TEST_TRANSFORMING_NULL_VALUES") {
        val status = int("STATUS").transform({ Status.forCode(it) }, { it.code })
    }

    database.useConnection { conn ->
        conn.createStatement().use { statement ->
            val sql = """CREATE TABLE T_TEST_TRANSFORMING_NULL_VALUES(STATUS INT)"""
            statement.executeUpdate(sql)
        }
    }

    database.insert(t) {
        set(it.status, null)
    }

    val query = database.from(t).select(t.status)
    assert(query.map { row -> row[t.status] }.first() == null)
}

Throwing the exception:

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions