@@ -1004,6 +1004,16 @@ public final class OracleCoreConnection: @unchecked Sendable {
10041004 _ query : String ,
10051005 batching : OracleRowBatcher ,
10061006 continuation : AsyncThrowingStream < OracleStreamElement , Error > . Continuation
1007+ ) async throws {
1008+ try await streamQuery ( query , batching : batching , onElement : { continuation . yield ( $0 ) } )
1009+ continuation . finish ( )
1010+ }
1011+
1012+ // The next row is read only once `onElement` returns, so a caller that waits in it holds the statement open.
1013+ public func streamQuery (
1014+ _ query : String ,
1015+ batching : OracleRowBatcher ,
1016+ onElement : @escaping @Sendable ( OracleStreamElement ) async -> Void
10071017 ) async throws {
10081018 let role = OracleTransactionRole ( of : query )
10091019 await queryGate . acquire ( )
@@ -1022,13 +1032,12 @@ public final class OracleCoreConnection: @unchecked Sendable {
10221032 regions : regions ,
10231033 batching : batching ,
10241034 on : connection ,
1025- continuation : continuation
1035+ onElement : onElement
10261036 )
10271037 }
10281038 await recordSuccess ( of : role , on : admitted . session )
10291039 forgetSessionZonesIfChanged ( by : query )
10301040 await queryGate . release ( )
1031- continuation . finish ( )
10321041 } catch {
10331042 let mapped = mapExecutionError ( error )
10341043 forgetSessionZonesIfChanged ( by : query )
@@ -1045,33 +1054,33 @@ public final class OracleCoreConnection: @unchecked Sendable {
10451054 regions : OracleTimeZoneRegions ,
10461055 batching : OracleRowBatcher ,
10471056 on connection : OracleNIO . OracleConnection ,
1048- continuation : AsyncThrowingStream < OracleStreamElement , Error > . Continuation
1057+ onElement : @escaping @ Sendable ( OracleStreamElement ) async -> Void
10491058 ) async throws {
10501059 let statement = OracleStatement ( unsafeSQL : query )
10511060 let stream = try await connection . execute ( statement , options : options , logger : nioLogger )
10521061
10531062 let columns = stream . columns . map ( OracleResultColumn . init )
10541063 var decoder = CellDecoder ( columns : columns , zones : zones , regions : regions )
1055- continuation . yield ( . header ( columns : columns . map ( \. descriptor ) ) )
1064+ await onElement ( . header ( columns : columns . map ( \. descriptor ) ) )
10561065
10571066 var batcher = batching
10581067 do {
10591068 for try await row in stream {
10601069 try Task . checkCancellation ( )
10611070 if let batch = batcher . append ( decoder . decode ( row ) ) {
1062- continuation . yield ( . rows ( batch ) )
1071+ await onElement ( . rows ( batch ) )
10631072 }
10641073 }
10651074 } catch {
10661075 // The rows read before a failure still reach the reader ahead of the error, as they did one by one.
1067- if let batch = batcher . remainder ( ) { continuation . yield ( . rows ( batch ) ) }
1076+ if let batch = batcher . remainder ( ) { await onElement ( . rows ( batch ) ) }
10681077 throw error
10691078 }
1070- if let batch = batcher . remainder ( ) { continuation . yield ( . rows ( batch ) ) }
1079+ if let batch = batcher . remainder ( ) { await onElement ( . rows ( batch ) ) }
10711080 await warnOnce ( about : decoder . unsupportedTypeNames )
10721081
10731082 guard columns . isEmpty else { return }
1074- continuation . yield ( . affectedRows ( try await stream . affectedRows ) )
1083+ await onElement ( . affectedRows ( try await stream . affectedRows ) )
10751084 }
10761085
10771086 // MARK: - Session Time Zones
0 commit comments