Skip to content

Commit

Permalink
Explicit statementType for exec functions
Browse files Browse the repository at this point in the history
How to call a MSSQL stored procedure and iterate over returned result set? JetBrains#390
Execute stored procedures with resultSet, MS SQL JetBrains#1249
  • Loading branch information
Tapac authored and SchweinchenFuntik committed Oct 23, 2021
1 parent a7b1f21 commit bc9e5dd
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Pair<IColumnType, Any?>> = emptyList()) = exec(stmt, args) { }

fun <T : Any> exec(stmt: String, args: Iterable<Pair<IColumnType, Any?>> = emptyList(), transform: (ResultSet) -> T): T? {
fun exec(stmt: String, args: Iterable<Pair<IColumnType, Any?>> = emptyList(), explicitStatementType: StatementType? = null) =
exec(stmt, args, explicitStatementType) { }

fun <T : Any> exec(
stmt: String,
args: Iterable<Pair<IColumnType, Any?>> = 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<T>(type, emptyList()) {
override fun PreparedStatementApi.executeInternal(transaction: Transaction): T? {
Expand Down

0 comments on commit bc9e5dd

Please sign in to comment.