From ee1e65c5991e80ef8d7382d242036fcf471d3bee Mon Sep 17 00:00:00 2001 From: ymotchi Date: Tue, 29 Aug 2023 00:00:55 +0900 Subject: [PATCH] fix: EXPOSED-158 insert space before WHEN to avoid SQL syntax error ENDWHEN using nested CASE --- .../src/main/kotlin/org/jetbrains/exposed/sql/Function.kt | 6 +++--- .../src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Function.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Function.kt index d013a7942f..f86e96c371 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Function.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Function.kt @@ -393,14 +393,14 @@ class CaseWhenElse( override fun toQueryBuilder(queryBuilder: QueryBuilder) { queryBuilder { - append("CASE ") + append("CASE") if (caseWhen.value != null) { - +caseWhen.value +" " + +caseWhen.value } for ((first, second) in caseWhen.cases) { - append("WHEN ", first, " THEN ", second) + append(" WHEN ", first, " THEN ", second) } append(" ELSE ", elseResult, " END") diff --git a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt index 0c9f1906d9..b4379951b7 100644 --- a/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt +++ b/exposed-java-time/src/test/kotlin/org/jetbrains/exposed/DefaultsTest.kt @@ -26,6 +26,7 @@ import org.jetbrains.exposed.sql.vendors.SQLServerDialect import org.jetbrains.exposed.sql.vendors.h2Mode import org.junit.Test import java.time.* +import java.time.temporal.ChronoUnit import kotlin.test.assertEquals import kotlin.test.assertNotNull import kotlin.test.assertTrue @@ -400,7 +401,7 @@ class DefaultsTest : DatabaseTestsBase() { java.util.TimeZone.setDefault(java.util.TimeZone.getTimeZone(ZoneOffset.UTC)) assertEquals("UTC", ZoneId.systemDefault().id) - val nowWithTimeZone = OffsetDateTime.now() + val nowWithTimeZone = OffsetDateTime.now().truncatedTo(ChronoUnit.MICROS) val timestampWithTimeZoneLiteral = timestampWithTimeZoneLiteral(nowWithTimeZone) val testTable = object : IntIdTable("t") {