From bc9e5dd72e2541335a36bd713737b8b17e1469ba Mon Sep 17 00:00:00 2001 From: "Andrey.Tarashevskiy" Date: Fri, 4 Jun 2021 20:10:10 +0300 Subject: [PATCH] Explicit statementType for exec functions How to call a MSSQL stored procedure and iterate over returned result set? #390 Execute stored procedures with resultSet, MS SQL #1249 --- .../org/jetbrains/exposed/sql/Transaction.kt | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt index 8c89158fa5..83080f8514 100644 --- a/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt +++ b/exposed-core/src/main/kotlin/org/jetbrains/exposed/sql/Transaction.kt @@ -79,14 +79,20 @@ open class Transaction(private val transactionImpl: TransactionInterface) : User private fun describeStatement(delta: Long, stmt: String): String = "[${delta}ms] ${stmt.take(1024)}\n\n" - fun exec(stmt: String, args: Iterable> = emptyList()) = exec(stmt, args) { } - - fun exec(stmt: String, args: Iterable> = emptyList(), transform: (ResultSet) -> T): T? { + fun exec(stmt: String, args: Iterable> = emptyList(), explicitStatementType: StatementType? = null) = + exec(stmt, args, explicitStatementType) { } + + fun exec( + stmt: String, + args: Iterable> = emptyList(), + explicitStatementType: StatementType? = null, + transform: (ResultSet) -> T + ): T? { if (stmt.isEmpty()) return null - val type = StatementType.values().find { - stmt.trim().startsWith(it.name, true) - } ?: StatementType.OTHER + val type = explicitStatementType + ?: StatementType.values().find { stmt.trim().startsWith(it.name, true) } + ?: StatementType.OTHER return exec(object : Statement(type, emptyList()) { override fun PreparedStatementApi.executeInternal(transaction: Transaction): T? {