Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved code of functional logic in Exposed SQL Statement classes #1877

Merged
merged 7 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 All @@ -154,6 +151,7 @@ fun StatementContext.expandArgs(transaction: Transaction): String {
}
}


/** Represents the groups that are used to classify the purpose of an SQL statement. */
enum class StatementGroup {
/** Data definition language group. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,21 @@ 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()
}

}
Loading