Skip to content

Commit 7190535

Browse files
committed
fix(SQLite): UNION clause can only use visitQuery
1 parent 6d14238 commit 7190535

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

ktorm-support-sqlite/src/main/kotlin/org/ktorm/support/sqlite/SQLiteDialect.kt

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,34 @@ public open class SQLiteFormatter(
7979
_parameters += ArgumentExpression(expr.limit ?: Int.MAX_VALUE, IntSqlType)
8080
}
8181

82+
override fun visitUnion(expr: UnionExpression): UnionExpression {
83+
when (expr.left) {
84+
is SelectExpression -> visitQuery(expr.left)
85+
is UnionExpression -> visitUnion(expr.left as UnionExpression)
86+
}
87+
88+
if (expr.isUnionAll) {
89+
writeKeyword("union all ")
90+
} else {
91+
writeKeyword("union ")
92+
}
93+
94+
when (expr.right) {
95+
is SelectExpression -> visitQuery(expr.right)
96+
is UnionExpression -> visitUnion(expr.right as UnionExpression)
97+
}
98+
99+
if (expr.orderBy.isNotEmpty()) {
100+
newLine(Indentation.SAME)
101+
writeKeyword("order by ")
102+
visitOrderByList(expr.orderBy)
103+
}
104+
if (expr.offset != null || expr.limit != null) {
105+
writePagination(expr)
106+
}
107+
return expr
108+
}
109+
82110
protected open fun visitInsertOrUpdate(expr: InsertOrUpdateExpression): InsertOrUpdateExpression {
83111
writeKeyword("insert into ")
84112
visitTable(expr.table)

0 commit comments

Comments
 (0)