exec

fun exec(stmt: String, args: Iterable<Pair<IColumnType<*>, Any?>> = emptyList(), explicitStatementType: StatementType? = null): Unit?

Executes the provided statement exactly, using the supplied args to set values to question mark placeholders (if applicable).

The explicitStatementType can be manually set to avoid iterating over StatementType values for the best match.

Samples

org.jetbrains.exposed.sql.tests.shared.ParameterizationTests.testInsertWithQuotesAndGetItBack
fun <T : Any> exec(stmt: String, args: Iterable<Pair<IColumnType<*>, Any?>> = emptyList(), explicitStatementType: StatementType? = null, transform: (ResultSet) -> T?): T?

Executes the provided statement exactly, using the supplied args to set values to question mark placeholders (if applicable).

The explicitStatementType can be manually set to avoid iterating over StatementType values for the best match.

Note StatementType.MULTI can be set to enable execution of multiple concatenated statements. However, if more than one ResultSet is generated, only the first will be used in the transform block. Multiple statements in a single execute is not supported by all databases and some may require setting a JDBC driver flag, like MySQL with allowMultiQueries. Please check the specific database documentation.

Return

The result of transform on the ResultSet generated by the statement execution, or null if no ResultSet was returned by the database.

Samples

org.jetbrains.exposed.sql.tests.shared.ParameterizationTests.testInsertWithQuotesAndGetItBackorg.jetbrains.exposed.sql.tests.shared.TransactionExecTests.testExecWithSingleStatementQuery
fun <T> exec(stmt: Statement<T>): T?

Executes the provided Statement object and returns the generated value.

This function also updates its calling Transaction instance's statement count and overall duration, as well as whether the execution time for stmt exceeds the threshold set by DatabaseConfig.warnLongQueriesDuration. If Transaction.debug is set to true, these tracked values are stored for each call in Transaction.statementStats.


fun <T, R> exec(stmt: Statement<T>, body: Statement<T>.(T) -> R): R?

Executes the provided Statement object, retrieves the generated value, then calls the specified function body with this generated value as its argument and returns its result.

This function also updates its calling Transaction instance's statement count and overall duration, as well as whether the execution time for stmt exceeds the threshold set by DatabaseConfig.warnLongQueriesDuration. If Transaction.debug is set to true, these tracked values are stored for each call in Transaction.statementStats.