diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/_autoclose.kt b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/_autoclose.kt index 428b4bc..f51129d 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/_autoclose.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/_autoclose.kt @@ -5,25 +5,99 @@ package ru.landgrafhomyak.db.serdha0.user_commons.executors import kotlin.contracts.InvocationKind import kotlin.contracts.contract import kotlin.jvm.JvmName +import ru.landgrafhomyak.db.serdha0.api.LowLevelApi +import ru.landgrafhomyak.db.serdha0.api.runtime.InputRow +import ru.landgrafhomyak.db.serdha0.api.runtime.OutputRow @Suppress("FunctionName") @PublishedApi -internal inline fun _safeAutoClose(onAbort: () -> Unit = {}, action: () -> R): R { +internal inline fun _safeAutoClose(onAbort: () -> Unit = {}, onSuccess: () -> Unit = {}, action: () -> R): R { contract { callsInPlace(action, InvocationKind.EXACTLY_ONCE) callsInPlace(onAbort, InvocationKind.AT_MOST_ONCE) + callsInPlace(onSuccess, InvocationKind.EXACTLY_ONCE) } val ret: R + var wasError = false try { ret = action() } catch (e1: Throwable) { + wasError = true try { onAbort() } catch (e2: Throwable) { e1.addSuppressed(e2) } throw e1 + } finally { + if (!wasError) + onSuccess() } return ret +} + +@Suppress("ClassName") +public class _ReturnFromInputError : Error("Returning from outer function from input row initializer block is undefined behaviour") + +@Suppress("FunctionName", "REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") +@LowLevelApi +public suspend inline fun , O : OutputRow._Iterator<*, Unit>> _safeAutoClose_IO( + iRow: I, + inputAction: suspend (I) -> Unit, + outputAction: suspend (O) -> Unit, +) { + contract { + callsInPlace(inputAction, InvocationKind.EXACTLY_ONCE) + callsInPlace(outputAction, InvocationKind.EXACTLY_ONCE) + } + var crossReturned = true + _safeAutoClose( + onAbort = { iRow._abort() }, + action = { inputAction(iRow); crossReturned = false }, + onSuccess = { + if (crossReturned) throw _ReturnFromInputError() + val oRow = iRow._finish() + _safeAutoClose( + onAbort = { oRow._abort() }, + action = { outputAction(oRow) }, + onSuccess = { oRow._finish() } + ) + } + ) +} + +@Suppress("FunctionName", "REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") +@LowLevelApi +public suspend inline fun > _safeAutoClose_I( + iRow: I, + inputAction: suspend (I) -> Unit, +) { + contract { + callsInPlace(inputAction, InvocationKind.EXACTLY_ONCE) + } + _safeAutoClose( + onAbort = { iRow._abort() }, + action = { inputAction(iRow) }, + onSuccess = { iRow._finish() } + ) +} + +@Suppress("FunctionName", "REDUNDANT_INLINE_SUSPEND_FUNCTION_TYPE") +@LowLevelApi +public suspend inline fun > _safeAutoClose_O( + oRow: O, + outputAction: suspend (O) -> Unit, +) { + contract { + callsInPlace(outputAction, InvocationKind.EXACTLY_ONCE) + } + _safeAutoClose( + onAbort = { oRow._abort() }, + action = { outputAction(oRow) }, + onSuccess = { oRow._finish() } + ) +} +public fun test() { + } \ No newline at end of file diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2row.kt b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2row.kt index 8563a3e..a4e9ddf 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2row.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2row.kt @@ -17,38 +17,35 @@ public suspend inline fun Transaction.selectExactlyOneOrError( params: RowProducer0, result: RowConsumer0 ): R { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - val ret: R - _safeAutoClose(onAbort = { oRow._abort() }) { - if (!oRow._next()) - throw ExpectedOneRowException() - ret = result.transformRow(oRow) - if (oRow._next()) - throw TooManyRowsException() - } - oRow._finish() - return ret + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + if (!oRow._next()) + throw ExpectedOneRowException() + val ret = result.transformRow(oRow) + if (oRow._next()) + throw TooManyRowsException() + return ret + } + ) } public suspend inline fun Transaction.selectExactlyOneOrError( compiledQuery: _Query.Void2Table, result: RowConsumer0 ): R { - val oRow = this._executeQuery(compiledQuery) - val ret: R - _safeAutoClose(onAbort = { oRow._abort() }) { - if (!oRow._next()) - throw ExpectedOneRowException() - ret = result.transformRow(oRow) - if (oRow._next()) - throw TooManyRowsException() - } - oRow._finish() - return ret + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + if (!oRow._next()) + throw ExpectedOneRowException() + val ret = result.transformRow(oRow) + if (oRow._next()) + throw TooManyRowsException() + return ret + } + ) } public suspend inline fun Transaction.selectExactlyOneOrNull( @@ -56,76 +53,65 @@ public suspend inline fun Transaction.selectExactlyOneOrNull( params: RowProducer0, result: RowConsumer0 ): R? { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - val ret: R? - _safeAutoClose(onAbort = { oRow._abort() }) { - if (!oRow._next()) { - ret = null - return@_safeAutoClose + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + if (!oRow._next()) + return null + val ret = result.transformRow(oRow) + if (oRow._next()) + throw TooManyRowsException() + return ret } - ret = result.transformRow(oRow) - if (oRow._next()) - throw TooManyRowsException() - } - oRow._finish() - return ret + ) } public suspend inline fun Transaction.selectExactlyOneOrNull( compiledQuery: _Query.Void2Table, result: RowConsumer0 ): R? { - val oRow = this._executeQuery(compiledQuery) - val ret: R? - _safeAutoClose(onAbort = { oRow._abort() }) { - if (!oRow._next()) { - ret = null - return@_safeAutoClose + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + if (!oRow._next()) + return null + val ret = result.transformRow(oRow) + if (oRow._next()) + throw TooManyRowsException() + return ret } - ret = result.transformRow(oRow) - if (oRow._next()) - throw TooManyRowsException() - } - oRow._finish() - return ret + ) } + public suspend inline fun Transaction.selectFirstOrError( compiledQuery: _Query.Params2Table, params: RowProducer0, result: RowConsumer0 ): R { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - val ret: R - _safeAutoClose(onAbort = { oRow._abort() }) { - if (!oRow._next()) - throw ExpectedOneRowException() - ret = result.transformRow(oRow) - } - oRow._finish() - return ret + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + if (!oRow._next()) + throw ExpectedOneRowException() + return result.transformRow(oRow) + } + ) } public suspend inline fun Transaction.selectFirstOrError( compiledQuery: _Query.Void2Table, result: RowConsumer0 ): R { - val oRow = this._executeQuery(compiledQuery) - val ret: R - _safeAutoClose(onAbort = { oRow._abort() }) { - if (!oRow._next()) - throw ExpectedOneRowException() - ret = result.transformRow(oRow) - } - oRow._finish() - return ret + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + if (!oRow._next()) + throw ExpectedOneRowException() + return result.transformRow(oRow) + } + ) } public suspend inline fun Transaction.selectFirstOrNull( @@ -133,36 +119,27 @@ public suspend inline fun Transaction.selectFirstOrNull( params: RowProducer0, result: RowConsumer0 ): R? { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - val ret: R? - _safeAutoClose(onAbort = { oRow._abort() }) { - if (!oRow._next()) { - ret = null - return@_safeAutoClose + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + if (!oRow._next()) + return null + return result.transformRow(oRow) } - ret = result.transformRow(oRow) - } - oRow._finish() - return ret + ) } public suspend inline fun Transaction.selectFirstOrNull( compiledQuery: _Query.Void2Table, result: RowConsumer0 ): R? { - val oRow = this._executeQuery(compiledQuery) - val ret: R? - _safeAutoClose(onAbort = { oRow._abort() }) { - if (!oRow._next()) { - ret = null - return@_safeAutoClose + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + if (!oRow._next()) + return null + return result.transformRow(oRow) } - ret = result.transformRow(oRow) - } - oRow._finish() - return ret + ) } \ No newline at end of file diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2table.kt b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2table.kt index e33d572..fc299e6 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2table.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2table.kt @@ -14,28 +14,27 @@ public suspend inline fun Transaction.select( params: RowProducer0, transform: RowConsumer0 ) { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - _safeAutoClose(onAbort = { oRow._abort() }) { - while (oRow._next()) - transform.transformRow(oRow) - } - oRow._finish() + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + while (oRow._next()) + transform.transformRow(oRow) + } + ) } public suspend inline fun Transaction.select( compiledQuery: _Query.Void2Table, transform: RowConsumer0 ) { - val oRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { oRow._abort() }) { - while (oRow._next()) - transform.transformRow(oRow) - } - oRow._finish() + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + while (oRow._next()) + transform.transformRow(oRow) + } + ) } public suspend inline fun Transaction.mapRows( @@ -43,32 +42,31 @@ public suspend inline fun Transaction.mapRows( params: RowProducer0, transform: RowConsumer0 ): List { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - val out = ArrayList() - _safeAutoClose(onAbort = { oRow._abort() }) { - while (oRow._next()) - out.add(transform.transformRow(oRow)) - } - oRow._finish() - return out + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + val dst = ArrayList() + while (oRow._next()) + dst.add(transform.transformRow(oRow)) + return dst + } + ) } public suspend inline fun Transaction.mapRows( compiledQuery: _Query.Void2Table, transform: RowConsumer0 ): List { - val oRow = this._executeQuery(compiledQuery) - val out = ArrayList() - _safeAutoClose(onAbort = { oRow._abort() }) { - while (oRow._next()) - out.add(transform.transformRow(oRow)) - } - oRow._finish() - return out + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + val dst = ArrayList() + while (oRow._next()) + dst.add(transform.transformRow(oRow)) + return dst + } + ) } public suspend inline fun Transaction.mapRowsIndexed( @@ -77,19 +75,17 @@ public suspend inline fun Transaction.mapRowsIndexed( firstIndex: Int = 0, transform: RowConsumer1 ): List { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - val out = ArrayList() - _safeAutoClose(onAbort = { oRow._abort() }) { - var i = firstIndex - while (oRow._next()) - out.add(transform.transformRow(oRow, i++)) - } - oRow._finish() - return out + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + val dst = ArrayList() + var i = firstIndex + while (oRow._next()) + dst.add(transform.transformRow(oRow, i++)) + return dst + } + ) } public suspend inline fun Transaction.mapRowsIndexed( @@ -97,15 +93,16 @@ public suspend inline fun Transaction.mapRowsIndexed( firstIndex: Int = 0, transform: RowConsumer1 ): List { - val oRow = this._executeQuery(compiledQuery) - val out = ArrayList() - _safeAutoClose(onAbort = { oRow._abort() }) { - var i = firstIndex - while (oRow._next()) - out.add(transform.transformRow(oRow, i++)) - } - oRow._finish() - return out + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + val dst = ArrayList() + var i = firstIndex + while (oRow._next()) + dst.add(transform.transformRow(oRow, i++)) + return dst + } + ) } public suspend inline fun > Transaction.mapRowsTo( @@ -114,17 +111,15 @@ public suspend inline fun > Transaction.m dst: C, transform: RowConsumer0 ): C { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - _safeAutoClose(onAbort = { oRow._abort() }) { - while (oRow._next()) - dst.add(transform.transformRow(oRow)) - } - oRow._finish() - return dst + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + while (oRow._next()) + dst.add(transform.transformRow(oRow)) + return dst + } + ) } public suspend inline fun > Transaction.mapRowsTo( @@ -132,13 +127,14 @@ public suspend inline fun > Transaction.m dst: C, transform: RowConsumer0 ): C { - val oRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { oRow._abort() }) { - while (oRow._next()) - dst.add(transform.transformRow(oRow)) - } - oRow._finish() - return dst + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + while (oRow._next()) + dst.add(transform.transformRow(oRow)) + return dst + } + ) } public suspend inline fun > Transaction.mapRowsIndexedTo( @@ -147,18 +143,16 @@ public suspend inline fun > Transaction.m dst: C, firstIndex: Int = 0, transform: RowConsumer1 ): C { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - _safeAutoClose(onAbort = { oRow._abort() }) { - var i = firstIndex - while (oRow._next()) - dst.add(transform.transformRow(oRow, i++)) - } - oRow._finish() - return dst + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + var i = firstIndex + while (oRow._next()) + dst.add(transform.transformRow(oRow, i++)) + return dst + } + ) } public suspend inline fun > Transaction.mapRowsIndexedTo( @@ -166,14 +160,15 @@ public suspend inline fun > Transaction.m dst: C, firstIndex: Int = 0, transform: RowConsumer1 ): C { - val oRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { oRow._abort() }) { - var i = firstIndex - while (oRow._next()) - dst.add(transform.transformRow(oRow, i++)) - } - oRow._finish() - return dst + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + var i = firstIndex + while (oRow._next()) + dst.add(transform.transformRow(oRow, i++)) + return dst + } + ) } public suspend inline fun Transaction.mapRowsTo( @@ -182,18 +177,16 @@ public suspend inline fun Transaction.mapRowsTo( dst: Array, dstOffset: Int = 0, transform: RowConsumer0 ): Array { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - val oRow = iRow._finish() - _safeAutoClose(onAbort = { oRow._abort() }) { - var i = dstOffset - while (oRow._next()) - dst[i++] = transform.transformRow(oRow) - } - oRow._finish() - return dst + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = { oRow -> + var i = dstOffset + while (oRow._next()) + dst[i++] = transform.transformRow(oRow) + return dst + } + ) } public suspend inline fun Transaction.mapRowsTo( @@ -201,12 +194,13 @@ public suspend inline fun Transaction.mapRowsTo( dst: Array, dstOffset: Int = 0, transform: RowConsumer0 ): Array { - val oRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { oRow._abort() }) { - var i = dstOffset - while (oRow._next()) - dst[i++] = transform.transformRow(oRow) - } - oRow._finish() - return dst + _safeAutoClose_O( + oRow = this._executeQuery(compiledQuery), + outputAction = { oRow -> + var i = dstOffset + while (oRow._next()) + dst[i++] = transform.transformRow(oRow) + return dst + } + ) } \ No newline at end of file diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2void.kt b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2void.kt index 574c924..581cef0 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2void.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/row2void.kt @@ -13,20 +13,19 @@ public suspend inline fun Transaction.executeWithParams( compiledQuery: _Query.Params2Void, params: RowProducer0 ) { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - iRow._finish() + _safeAutoClose_I( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow + ) } public suspend inline fun Transaction.executeWithParams( compiledQuery: _Query.Params2Table, params: RowProducer0 ) { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - params.initializeRow(iRow) - } - iRow._finish()._finish() + _safeAutoClose_IO( + iRow = this._executeQuery(compiledQuery), + inputAction = params::initializeRow, + outputAction = {} + ) } \ No newline at end of file diff --git a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/table2void.kt b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/table2void.kt index 8fe0fc5..c71f5af 100644 --- a/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/table2void.kt +++ b/src/commonMain/kotlin/ru/landgrafhomyak/db/serdha0/user_commons/executors/table2void.kt @@ -4,7 +4,6 @@ package ru.landgrafhomyak.db.serdha0.user_commons.executors -import kotlin.contracts.contract import kotlin.jvm.JvmName import ru.landgrafhomyak.db.serdha0.api.LowLevelApi import ru.landgrafhomyak.db.serdha0.api.queries._Query @@ -15,14 +14,15 @@ public suspend inline fun Transaction.mapToRows( collection: Iterable, transform: RowProducer1 ) { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - for (elem in collection) { - iRow._next() - transform.transformToRow(iRow, elem) + _safeAutoClose_I( + iRow = this._executeQuery(compiledQuery), + inputAction = { iRow -> + for (elem in collection) { + iRow._next() + transform.transformToRow(iRow, elem) + } } - } - iRow._finish() + ) } public suspend inline fun Transaction.mapToRowsIndexed( @@ -31,16 +31,16 @@ public suspend inline fun Transaction.mapToRowsIndexed( firstIndex: Int = 0, transform: RowProducer2 ) { - val iRow = this._executeQuery(compiledQuery) - var index = firstIndex - _safeAutoClose(onAbort = { iRow._abort() }) { - for (elem in collection) { - iRow._next() - transform.transformToRow(iRow, index, elem) - index++ + _safeAutoClose_I( + iRow = this._executeQuery(compiledQuery), + inputAction = { iRow -> + var index = firstIndex + for (elem in collection) { + iRow._next() + transform.transformToRow(iRow, index++, elem) + } } - } - iRow._finish() + ) } public suspend inline fun Transaction.mapToRows( @@ -48,14 +48,15 @@ public suspend inline fun Transaction.mapToRows( sequence: Sequence, transform: RowProducer1 ) { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - for (elem in sequence) { - iRow._next() - transform.transformToRow(iRow, elem) + _safeAutoClose_I( + iRow = this._executeQuery(compiledQuery), + inputAction = { iRow -> + for (elem in sequence) { + iRow._next() + transform.transformToRow(iRow, elem) + } } - } - iRow._finish() + ) } public suspend inline fun Transaction.mapToRowsIndexed( @@ -64,47 +65,48 @@ public suspend inline fun Transaction.mapToRowsIndexed( firstIndex: Int = 0, transform: RowProducer2 ) { - val iRow = this._executeQuery(compiledQuery) - var index = firstIndex - _safeAutoClose(onAbort = { iRow._abort() }) { - for (elem in sequence) { - iRow._next() - transform.transformToRow(iRow, index, elem) - index++ + _safeAutoClose_I( + iRow = this._executeQuery(compiledQuery), + inputAction = { iRow -> + var index = firstIndex + for (elem in sequence) { + iRow._next() + transform.transformToRow(iRow, index++, elem) + } } - } - iRow._finish() + ) } public suspend inline fun Transaction.mapToRows( compiledQuery: _Query.Table2Void, - sequence: Array, + array: Array, transform: RowProducer1 ) { - val iRow = this._executeQuery(compiledQuery) - _safeAutoClose(onAbort = { iRow._abort() }) { - for (elem in sequence) { - iRow._next() - transform.transformToRow(iRow, elem) + _safeAutoClose_I( + iRow = this._executeQuery(compiledQuery), + inputAction = { iRow -> + for (elem in array) { + iRow._next() + transform.transformToRow(iRow, elem) + } } - } - iRow._finish() + ) } public suspend inline fun Transaction.mapToRowsIndexed( compiledQuery: _Query.Table2Void, - sequence: Array, + array: Array, firstIndex: Int = 0, transform: RowProducer2 ) { - val iRow = this._executeQuery(compiledQuery) - var index = firstIndex - _safeAutoClose(onAbort = { iRow._abort() }) { - for (elem in sequence) { - iRow._next() - transform.transformToRow(iRow, index, elem) - index++ + _safeAutoClose_I( + iRow = this._executeQuery(compiledQuery), + inputAction = { iRow -> + var index = firstIndex + for (elem in array) { + iRow._next() + transform.transformToRow(iRow, index++, elem) + } } - } - iRow._finish() + ) } \ No newline at end of file