@@ -122,6 +122,7 @@ public override long GetBytes(int ordinal, long dataOffset, byte[]? buffer, int
122122 public override char GetChar ( int ordinal )
123123 {
124124 var str = GetString ( ordinal ) ;
125+
125126 return str . Length == 0 ? throw new InvalidCastException ( "Could not read char - string was empty" ) : str [ 0 ] ;
126127 }
127128
@@ -386,7 +387,8 @@ public override int GetOrdinal(string name)
386387 throw new IndexOutOfRangeException ( $ "Field not found in row: { name } ") ;
387388 }
388389
389- public override string GetString ( int ordinal ) => CurrentRow [ ordinal ] . GetText ( ) ;
390+ public override string GetString ( int ordinal ) =>
391+ GetPrimitiveValue ( Type . Types . PrimitiveTypeId . Utf8 , ordinal ) . GetText ( ) ;
390392
391393 public override TextReader GetTextReader ( int ordinal ) => new StringReader ( GetString ( ordinal ) ) ;
392394
@@ -398,14 +400,13 @@ public string GetJsonDocument(int ordinal) =>
398400 public override object GetValue ( int ordinal )
399401 {
400402 var type = GetColumnType ( ordinal ) ;
403+ var ydbValue = CurrentRow [ ordinal ] ;
401404
402405 if ( type . IsNull ( ) )
403406 {
404407 return DBNull . Value ;
405408 }
406409
407- var ydbValue = CurrentRow [ ordinal ] ;
408-
409410 if ( type . IsOptional ( ) )
410411 {
411412 if ( ydbValue . IsNull ( ) )
@@ -468,7 +469,7 @@ public override bool IsDBNull(int ordinal)
468469 {
469470 var type = GetColumnType ( ordinal ) ;
470471
471- return type . IsNull ( ) || ( type . IsOptional ( ) && CurrentRow [ ordinal ] . IsNull ( ) ) ;
472+ return ( type . IsOptional ( ) && CurrentRow [ ordinal ] . IsNull ( ) ) || type . IsNull ( ) ;
472473 }
473474
474475 public override int FieldCount => ReaderMetadata . FieldCount ;
@@ -599,10 +600,9 @@ private Type UnwrapColumnType(int ordinal)
599600 private Ydb . Value GetPrimitiveValue ( Type . Types . PrimitiveTypeId primitiveTypeId , int ordinal )
600601 {
601602 var type = UnwrapColumnType ( ordinal ) ;
603+ var ydbValue = CurrentRow [ ordinal ] ;
602604
603- return type . TypeId == primitiveTypeId
604- ? CurrentRow [ ordinal ]
605- : throw InvalidCastException ( primitiveTypeId , ordinal ) ;
605+ return type . TypeId == primitiveTypeId ? ydbValue : throw InvalidCastException ( primitiveTypeId , ordinal ) ;
606606 }
607607
608608 private async ValueTask < State > NextExecPart ( CancellationToken cancellationToken )
0 commit comments