Skip to content

Commit

Permalink
fix: EXPOSED-54 CaseWhen.Else returns narrow Expression<R>
Browse files Browse the repository at this point in the history
Remove Unit return type and replace assignment operator with block body.
  • Loading branch information
bog-walk committed Jul 27, 2023
1 parent 829696e commit 540c4ad
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Function.kt
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@ class Random(
class CharLength<T : String?>(
val expr: Expression<T>
) : Function<Int?>(IntegerColumnType()) {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit =
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
currentDialect.functionProvider.charLength(expr, queryBuilder)
}
}

/**
Expand Down Expand Up @@ -106,8 +107,9 @@ class Concat(
/** Returns the expressions being concatenated. */
vararg val expr: Expression<*>
) : Function<String>(TextColumnType()) {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit =
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
currentDialect.functionProvider.concat(separator, queryBuilder, expr = expr)
}
}

/**
Expand All @@ -123,8 +125,9 @@ class GroupConcat<T : String?>(
/** Returns the order in which the elements of each group are sorted. */
vararg val orderBy: Pair<Expression<*>, SortOrder>
) : Function<T>(TextColumnType()) {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit =
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
currentDialect.functionProvider.groupConcat(this, queryBuilder)
}
}

/**
Expand All @@ -136,8 +139,9 @@ class Substring<T : String?>(
/** Returns the length of the substring. */
val length: Expression<Int>
) : Function<T>(TextColumnType()) {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit =
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
currentDialect.functionProvider.substring(expr, start, length, queryBuilder)
}
}

/**
Expand Down Expand Up @@ -350,8 +354,9 @@ sealed class NextVal<T>(
columnType: IColumnType
) : Function<T>(columnType) {

override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit =
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
currentDialect.functionProvider.nextVal(seq, queryBuilder)
}

class IntNextVal(seq: Sequence) : NextVal<Int>(seq, IntegerColumnType())
class LongNextVal(seq: Sequence) : NextVal<Long>(seq, LongColumnType())
Expand Down Expand Up @@ -386,18 +391,20 @@ class CaseWhenElse<T, R : T>(
?: caseWhen.cases.map { it.second }.filterIsInstance<ExpressionWithColumnType<*>>().firstOrNull()?.columnType
?: BooleanColumnType.INSTANCE

override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit = queryBuilder {
append("CASE ")
if (caseWhen.value != null) {
+caseWhen.value
+" "
}
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
queryBuilder {
append("CASE ")
if (caseWhen.value != null) {
+caseWhen.value
+" "
}

for ((first, second) in caseWhen.cases) {
append("WHEN ", first, " THEN ", second)
}
for ((first, second) in caseWhen.cases) {
append("WHEN ", first, " THEN ", second)
}

append(" ELSE ", elseResult, " END")
append(" ELSE ", elseResult, " END")
}
}
}

Expand Down Expand Up @@ -428,6 +435,7 @@ class Cast<T>(
val expr: Expression<*>,
columnType: IColumnType
) : Function<T>(columnType) {
override fun toQueryBuilder(queryBuilder: QueryBuilder): Unit =
override fun toQueryBuilder(queryBuilder: QueryBuilder) {
currentDialect.functionProvider.cast(expr, columnType, queryBuilder)
}
}

0 comments on commit 540c4ad

Please sign in to comment.