Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: EXPOSED-263 Null arg parameter in exec() throws if logger enabled #1973

Merged
merged 1 commit into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,11 @@ open class Transaction(

override fun prepareSQL(transaction: Transaction, prepared: Boolean): String = stmt

override fun arguments(): Iterable<Iterable<Pair<IColumnType, Any?>>> = listOf(args)
override fun arguments(): Iterable<Iterable<Pair<IColumnType, Any?>>> = listOf(
args.map { (columnType, value) ->
columnType.apply { nullable = true } to value
}
)
})
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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])
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Loading