Fix function replaceArgsIntoSql

This commit is contained in:
2019-08-04 22:24:24 +02:00
parent 13f0f12c1b
commit f56c84c675

View File

@@ -125,7 +125,7 @@ class Connection(
.plus("limit" to limit)
val line = replaceArgs(sql, newValues) {
exec(this.sql, compileArgs(this.parameters))
exec(this.sql, this.parameters)
}
return line.run {
@@ -228,9 +228,10 @@ class Connection(
}
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
val newSql = paramRegex.replace(sql) { _ ->
if (values.isNotEmpty()) {
val newSql = paramRegex.replace(sql) {
values[i] ?: error("Parameter $i missing")
val valToReplace = values[i].toString()
++i
@@ -240,6 +241,9 @@ class Connection(
return block(newSql)
}
return block(sql)
}
data class ParametersQuery(val sql: String, val parameters: List<Any?>)
private fun <T> stopwatchQuery(sql: String, values: List<Any?> = emptyList(), callback: () -> T): T {