@@ -29,18 +29,20 @@ public override bool NextResult()
29
29
30
30
public override bool Read ( )
31
31
{
32
- Command ? . CancellableCommand . ResetCommandTimeout ( ) ;
33
- return GetResultSet ( ) . Read ( ) ;
32
+ VerifyNotDisposed ( ) ;
33
+ Command ! . CancellableCommand . ResetCommandTimeout ( ) ;
34
+ return m_resultSet ! . Read ( ) ;
34
35
}
35
36
36
37
public override Task < bool > ReadAsync ( CancellationToken cancellationToken )
37
38
{
38
- Command ? . CancellableCommand . ResetCommandTimeout ( ) ;
39
- return GetResultSet ( ) . ReadAsync ( cancellationToken ) ;
39
+ VerifyNotDisposed ( ) ;
40
+ Command ! . CancellableCommand . ResetCommandTimeout ( ) ;
41
+ return m_resultSet ! . ReadAsync ( cancellationToken ) ;
40
42
}
41
43
42
44
internal Task < bool > ReadAsync ( IOBehavior ioBehavior , CancellationToken cancellationToken ) =>
43
- GetResultSet ( ) . ReadAsync ( ioBehavior , cancellationToken ) ;
45
+ m_resultSet ! . ReadAsync ( ioBehavior , cancellationToken ) ;
44
46
45
47
public override Task < bool > NextResultAsync ( CancellationToken cancellationToken )
46
48
{
@@ -58,7 +60,7 @@ internal async Task<bool> NextResultAsync(IOBehavior ioBehavior, CancellationTok
58
60
await m_resultSet ! . ReadEntireAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
59
61
await ScanResultSetAsync ( ioBehavior , m_resultSet , cancellationToken ) . ConfigureAwait ( false ) ;
60
62
if ( m_hasMoreResults && m_resultSet . ContainsCommandParameters )
61
- await ReadOutParametersAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
63
+ await ReadOutParametersAsync ( Command ! , m_resultSet , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
62
64
else
63
65
break ;
64
66
}
@@ -366,7 +368,7 @@ internal static async Task<MySqlDataReader> CreateAsync(CommandListPosition comm
366
368
dataReader . m_hasMoreResults = true ;
367
369
368
370
if ( dataReader . m_resultSet . ContainsCommandParameters )
369
- await dataReader . ReadOutParametersAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
371
+ await ReadOutParametersAsync ( dataReader . Command ! , dataReader . m_resultSet , ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
370
372
371
373
// if the command list has multiple commands, keep reading until a result set is found
372
374
while ( dataReader . m_resultSet . State == ResultSetState . NoMoreData && commandListPosition . CommandIndex < commandListPosition . Commands . Count )
@@ -529,30 +531,31 @@ internal async ValueTask DisposeAsync(IOBehavior ioBehavior, CancellationToken c
529
531
// If ResultSet.ContainsCommandParameters is true, then this method should be called to read the (single)
530
532
// row in that result set, which contains the values of "out" parameters from the previous stored procedure
531
533
// execution. These values will be stored in the parameters of the associated command.
532
- private async Task ReadOutParametersAsync ( IOBehavior ioBehavior , CancellationToken cancellationToken )
534
+ private static async Task ReadOutParametersAsync ( IMySqlCommand command , ResultSet resultSet , IOBehavior ioBehavior , CancellationToken cancellationToken )
533
535
{
534
- await ReadAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
536
+ await resultSet . ReadAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) ;
535
537
536
- if ( GetString ( 0 ) != SingleCommandPayloadCreator . OutParameterSentinelColumnName )
538
+ var row = resultSet . GetCurrentRow ( ) ;
539
+ if ( row . GetString ( 0 ) != SingleCommandPayloadCreator . OutParameterSentinelColumnName )
537
540
throw new InvalidOperationException ( "Expected out parameter values." ) ;
538
541
539
- for ( var i = 0 ; i < Command ! . OutParameters ! . Count ; i ++ )
542
+ for ( var i = 0 ; i < command . OutParameters ! . Count ; i ++ )
540
543
{
541
- var param = Command . OutParameters [ i ] ;
544
+ var param = command . OutParameters [ i ] ;
542
545
var columnIndex = i + 1 ;
543
- if ( param . HasSetDbType && ! IsDBNull ( columnIndex ) )
546
+ if ( param . HasSetDbType && ! row . IsDBNull ( columnIndex ) )
544
547
{
545
548
var dbTypeMapping = TypeMapper . Instance . GetDbTypeMapping ( param . DbType ) ;
546
549
if ( dbTypeMapping is object )
547
550
{
548
- param . Value = dbTypeMapping . DoConversion ( GetValue ( columnIndex ) ) ;
551
+ param . Value = dbTypeMapping . DoConversion ( row . GetValue ( columnIndex ) ) ;
549
552
continue ;
550
553
}
551
554
}
552
- param . Value = GetValue ( columnIndex ) ;
555
+ param . Value = row . GetValue ( columnIndex ) ;
553
556
}
554
557
555
- if ( await ReadAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) )
558
+ if ( await resultSet . ReadAsync ( ioBehavior , cancellationToken ) . ConfigureAwait ( false ) )
556
559
throw new InvalidOperationException ( "Expected only one row." ) ;
557
560
}
558
561
@@ -565,7 +568,9 @@ private void VerifyNotDisposed()
565
568
private ResultSet GetResultSet ( )
566
569
{
567
570
VerifyNotDisposed ( ) ;
568
- return m_resultSet ?? throw new InvalidOperationException ( "There is no current result set." ) ;
571
+ if ( m_resultSet is null || m_resultSet . ContainsCommandParameters )
572
+ throw new InvalidOperationException ( "There is no current result set." ) ;
573
+ return m_resultSet ;
569
574
}
570
575
571
576
readonly CommandBehavior m_behavior ;
0 commit comments