diff --git a/src/main/kotlin/fr/postgresjson/connexion/Connection.kt b/src/main/kotlin/fr/postgresjson/connexion/Connection.kt index 45e7ed5..d9a045b 100644 --- a/src/main/kotlin/fr/postgresjson/connexion/Connection.kt +++ b/src/main/kotlin/fr/postgresjson/connexion/Connection.kt @@ -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,16 +228,20 @@ class Connection( } private fun replaceArgsIntoSql(sql: String, values: List, block: (String) -> T): T { - val paramRegex = "(? - values[i] ?: error("Parameter $i missing") - val valToReplace = values[i].toString() - ++i - "'$valToReplace'" + if (values.isNotEmpty()) { + val newSql = paramRegex.replace(sql) { + values[i] ?: error("Parameter $i missing") + val valToReplace = values[i].toString() + ++i + "'$valToReplace'" + } + + return block(newSql) } - return block(newSql) + return block(sql) } data class ParametersQuery(val sql: String, val parameters: List)