Fix function replaceArgsIntoSql
This commit is contained in:
@@ -125,7 +125,7 @@ class Connection(
|
|||||||
.plus("limit" to limit)
|
.plus("limit" to limit)
|
||||||
|
|
||||||
val line = replaceArgs(sql, newValues) {
|
val line = replaceArgs(sql, newValues) {
|
||||||
exec(this.sql, compileArgs(this.parameters))
|
exec(this.sql, this.parameters)
|
||||||
}
|
}
|
||||||
|
|
||||||
return line.run {
|
return line.run {
|
||||||
@@ -228,16 +228,20 @@ class Connection(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun <T> replaceArgsIntoSql(sql: String, values: List<Any?>, block: (String) -> T): T {
|
private fun <T> replaceArgsIntoSql(sql: String, values: List<Any?>, block: (String) -> T): T {
|
||||||
val paramRegex = "(?<!\\?)(\\?)".toRegex(RegexOption.IGNORE_CASE)
|
val paramRegex = "(?<!\\?)(\\?)(?!\\?)".toRegex(RegexOption.IGNORE_CASE)
|
||||||
var i = 0
|
var i = 0
|
||||||
val newSql = paramRegex.replace(sql) { _ ->
|
if (values.isNotEmpty()) {
|
||||||
values[i] ?: error("Parameter $i missing")
|
val newSql = paramRegex.replace(sql) {
|
||||||
val valToReplace = values[i].toString()
|
values[i] ?: error("Parameter $i missing")
|
||||||
++i
|
val valToReplace = values[i].toString()
|
||||||
"'$valToReplace'"
|
++i
|
||||||
|
"'$valToReplace'"
|
||||||
|
}
|
||||||
|
|
||||||
|
return block(newSql)
|
||||||
}
|
}
|
||||||
|
|
||||||
return block(newSql)
|
return block(sql)
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ParametersQuery(val sql: String, val parameters: List<Any?>)
|
data class ParametersQuery(val sql: String, val parameters: List<Any?>)
|
||||||
|
|||||||
Reference in New Issue
Block a user