improve-tests #28
@@ -182,6 +182,9 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
override fun sendQuery(sql: String, values: List<Any?>): Int {
|
override fun sendQuery(sql: String, values: List<Any?>): Int {
|
||||||
val compiledValues = compileArgs(values)
|
val compiledValues = compileArgs(values)
|
||||||
return stopwatchQuery(sql, compiledValues) {
|
return stopwatchQuery(sql, compiledValues) {
|
||||||
@@ -191,6 +194,9 @@ class Connection(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
override fun sendQuery(sql: String, values: Map<String, Any?>): Int {
|
override fun sendQuery(sql: String, values: Map<String, Any?>): Int {
|
||||||
return replaceArgs(sql, values) {
|
return replaceArgs(sql, values) {
|
||||||
sendQuery(this.sql, this.parameters)
|
sendQuery(this.sql, this.parameters)
|
||||||
@@ -224,9 +230,11 @@ 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)
|
/* The regular expression matches a question mark "?" alone, not preceded or followed by another question mark */
|
||||||
|
val paramRegex = """(?<!\?)(\?)(?!\?)""".toRegex(RegexOption.IGNORE_CASE)
|
||||||
var i = 0
|
var i = 0
|
||||||
if (values.isNotEmpty()) {
|
if (values.isNotEmpty()) {
|
||||||
|
/* for each question mark, replace by the value */
|
||||||
val newSql = paramRegex.replace(sql) {
|
val newSql = paramRegex.replace(sql) {
|
||||||
values[i] ?: queryError("Parameter $i missing", sql, values)
|
values[i] ?: queryError("Parameter $i missing", sql, values)
|
||||||
val valToReplace = values[i].toString()
|
val valToReplace = values[i].toString()
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ sealed interface EmbedExecutable {
|
|||||||
): Paginated<R> =
|
): Paginated<R> =
|
||||||
select(page, limit, typeReference, values.toMap(), block)
|
select(page, limit, typeReference, values.toMap(), block)
|
||||||
|
|
||||||
fun exec(values: List<Any?> = emptyList()): QueryResult
|
fun exec(values: List<Any?>): QueryResult
|
||||||
fun exec(values: Map<String, Any?>): QueryResult
|
fun exec(values: Map<String, Any?>): QueryResult
|
||||||
fun exec(vararg values: Pair<String, Any?>): QueryResult = exec(values.toMap())
|
fun exec(vararg values: Pair<String, Any?>): QueryResult = exec(values.toMap())
|
||||||
|
|
||||||
@@ -112,7 +112,16 @@ sealed interface EmbedExecutable {
|
|||||||
fun perform(values: Map<String, Any?>) { exec(values) }
|
fun perform(values: Map<String, Any?>) { exec(values) }
|
||||||
fun perform(vararg values: Pair<String, Any?>) = perform(values.toMap())
|
fun perform(vararg values: Pair<String, Any?>) = perform(values.toMap())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
fun sendQuery(values: List<Any?>): Int
|
fun sendQuery(values: List<Any?>): Int
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
fun sendQuery(values: Map<String, Any?>): Int
|
fun sendQuery(values: Map<String, Any?>): Int
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
fun sendQuery(vararg values: Pair<String, Any?>): Int = sendQuery(values.toMap())
|
fun sendQuery(vararg values: Pair<String, Any?>): Int = sendQuery(values.toMap())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,8 +122,20 @@ interface Executable {
|
|||||||
fun perform(sql: String, values: Map<String, Any?>) { exec(sql, values) }
|
fun perform(sql: String, values: Map<String, Any?>) { exec(sql, values) }
|
||||||
fun perform(sql: String, vararg values: Pair<String, Any?>) = perform(sql, values.toMap())
|
fun perform(sql: String, vararg values: Pair<String, Any?>) = perform(sql, values.toMap())
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
fun <R : EntityI> sendQuery(sql: String, value: R): Int = sendQuery(sql, listOf(value))
|
fun <R : EntityI> sendQuery(sql: String, value: R): Int = sendQuery(sql, listOf(value))
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
fun sendQuery(sql: String, values: List<Any?> = emptyList()): Int
|
fun sendQuery(sql: String, values: List<Any?> = emptyList()): Int
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
fun sendQuery(sql: String, values: Map<String, Any?>): Int
|
fun sendQuery(sql: String, values: Map<String, Any?>): Int
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
fun sendQuery(sql: String, vararg values: Pair<String, Any?>): Int = sendQuery(sql, values.toMap())
|
fun sendQuery(sql: String, vararg values: Pair<String, Any?>): Int = sendQuery(sql, values.toMap())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,11 +82,17 @@ class Function(val definition: Function, override val connection: Connection) :
|
|||||||
|
|
||||||
override fun exec(values: Map<String, Any?>): QueryResult = connection.exec(compileSql(values), values)
|
override fun exec(values: Map<String, Any?>): QueryResult = connection.exec(compileSql(values), values)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
override fun sendQuery(values: List<Any?>): Int {
|
override fun sendQuery(values: List<Any?>): Int {
|
||||||
exec(values)
|
exec(values)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
override fun sendQuery(values: Map<String, Any?>): Int {
|
override fun sendQuery(values: Map<String, Any?>): Int {
|
||||||
exec(values)
|
exec(values)
|
||||||
return 0
|
return 0
|
||||||
|
|||||||
@@ -73,7 +73,13 @@ class Query(override val name: String, private val sql: String, override val con
|
|||||||
|
|
||||||
override fun exec(values: Map<String, Any?>): QueryResult = connection.exec(sql, values)
|
override fun exec(values: Map<String, Any?>): QueryResult = connection.exec(sql, values)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
override fun sendQuery(values: List<Any?>): Int = connection.sendQuery(sql, values)
|
override fun sendQuery(values: List<Any?>): Int = connection.sendQuery(sql, values)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Warning: this method not use prepared statement
|
||||||
|
*/
|
||||||
override fun sendQuery(values: Map<String, Any?>): Int = connection.sendQuery(sql, values)
|
override fun sendQuery(values: Map<String, Any?>): Int = connection.sendQuery(sql, values)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user