diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt index 596ba31270..730593125b 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt @@ -206,7 +206,11 @@ open class Transaction( override fun prepareSQL(transaction: Transaction, prepared: Boolean): String = stmt - override fun arguments(): Iterable>> = listOf(args) + override fun arguments(): Iterable>> = listOf( + args.map { (columnType, value) -> + columnType.apply { nullable = true } to value + } + ) }) } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ParameterizationTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ParameterizationTests.kt index 7f6e76512d..b4bedd4880 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ParameterizationTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ParameterizationTests.kt @@ -10,10 +10,11 @@ import org.jetbrains.exposed.sql.transactions.transaction import org.junit.Assume import org.junit.Test import kotlin.test.assertNotNull +import kotlin.test.assertNull class ParameterizationTests : DatabaseTestsBase() { object TempTable : Table("tmp") { - val name = varchar("foo", 50) + val name = varchar("foo", 50).nullable() } private val supportMultipleStatements by lazy { @@ -146,4 +147,19 @@ class ParameterizationTests : DatabaseTestsBase() { TransactionManager.closeAndUnregister(db) } + + @Test + fun testNullParameterWithLogger() { + withTables(TempTable) { + // the logger is left in to test that it does not throw IllegalStateException with null parameter arg + addLogger(StdOutSqlLogger) + + exec( + stmt = "INSERT INTO ${TempTable.tableName} (${TempTable.name.name}) VALUES (?)", + args = listOf(VarCharColumnType() to null) + ) + + assertNull(TempTable.selectAll().single()[TempTable.name]) + } + } } diff --git a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/SequencesTests.kt b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/SequencesTests.kt index 9263a04ffb..322a4d5e50 100644 --- a/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/SequencesTests.kt +++ b/exposed-tests/src/test/kotlin/org/jetbrains/exposed/sql/tests/shared/ddl/SequencesTests.kt @@ -86,7 +86,6 @@ class SequencesTests : DatabaseTestsBase() { fun `test insert LongIdTable with auth-increment with sequence`() { withDb { if (currentDialectTest.supportsSequenceAsGeneratedKeys) { - addLogger(StdOutSqlLogger) try { SchemaUtils.create(DeveloperWithAutoIncrementBySequence) val developerId = DeveloperWithAutoIncrementBySequence.insertAndGetId {