Skip to content

Commit

Permalink
fix: EXPOSED-158 insert space before WHEN
Browse files Browse the repository at this point in the history
to avoid SQL syntax error ENDWHEN using nested CASE
  • Loading branch information
ymotchi committed Aug 28, 2023
1 parent af6bdb1 commit ee1e65c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -393,14 +393,14 @@ class CaseWhenElse<T, R : T>(

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

0 comments on commit ee1e65c

Please sign in to comment.