Skip to content

Commit

Permalink
Improved code of functional logic in Exposed SQL Statement classes (J…
Browse files Browse the repository at this point in the history
…etBrains#1877)

* Update Statement.kt

* Update StatementInterceptor.kt

* Update UpdateStatement.kt

* Update Statement.kt

* fix :: i increment, duplex override method

* delete blank line(s)
  • Loading branch information
esperar authored Jan 8, 2024
1 parent f58465b commit 7325e04
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,34 +115,31 @@ class StatementContext(val statement: Statement<*>, val args: Iterable<Pair<ICol
fun StatementContext.expandArgs(transaction: Transaction): String {
val sql = sql(transaction)
val iterator = args.iterator()

if (!iterator.hasNext()) return sql

return buildString {
val quoteStack = Stack<Char>()
var lastPos = 0
var i = -1
while (++i < sql.length) {

for (i in sql.indices) {
val char = sql[i]
if (char == '?') {
if (quoteStack.isEmpty()) {
when {
char == '?' && quoteStack.isEmpty() -> {
if (sql.getOrNull(i + 1) == '?') {
++i
i.inc()
continue
}
append(sql.substring(lastPos, i))
lastPos = i + 1
val (col, value) = iterator.next()
append(col.valueToString(value))
}
} else if (char == '\'' || char == '\"') {
if (quoteStack.isEmpty()) {
quoteStack.push(char)
} else {
val currentQuote = quoteStack.peek()
if (currentQuote == char) {
quoteStack.pop()
} else {
quoteStack.push(char)
char == '\'' || char == '\"' -> {
when {
quoteStack.isEmpty() -> quoteStack.push(char)
quoteStack.peek() == char -> quoteStack.pop()
else -> quoteStack.push(char)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,19 @@ open class UpdateStatement(val targetsSet: ColumnSet, val limit: Int?, val where
}

override fun arguments(): Iterable<Iterable<Pair<IColumnType, Any?>>> = QueryBuilder(true).run {
if (targetsSet is Join && currentDialect is OracleDialect) {
where?.toQueryBuilder(this)
values.forEach {
registerArgument(it.key, it.value)
when {
targetsSet is Join && currentDialect is OracleDialect -> {
where?.toQueryBuilder(this)
values.forEach {
registerArgument(it.key, it.value)
}
}
} else {
values.forEach {
registerArgument(it.key, it.value)
else -> {
values.forEach {
registerArgument(it.key, it.value)
}
where?.toQueryBuilder(this)
}
where?.toQueryBuilder(this)
}
if (args.isNotEmpty()) listOf(args) else emptyList()
}
Expand Down

0 comments on commit 7325e04

Please sign in to comment.