1
- #nullable disable
2
1
using System ;
3
2
using System . Collections . Generic ;
4
3
using System . Globalization ;
@@ -35,7 +34,6 @@ public void Reset()
35
34
m_columnDefinitionPayloadUsedBytes = 0 ;
36
35
m_readBuffer ? . Clear ( ) ;
37
36
m_row = null ;
38
- m_rowBuffered = null ;
39
37
m_hasRows = false ;
40
38
ReadResultSetHeaderException = null ;
41
39
}
@@ -176,7 +174,7 @@ public bool Read()
176
174
}
177
175
178
176
public Task < bool > ReadAsync ( CancellationToken cancellationToken ) =>
179
- ReadAsync ( Command . Connection . AsyncIOBehavior , cancellationToken ) ;
177
+ ReadAsync ( Connection . AsyncIOBehavior , cancellationToken ) ;
180
178
181
179
public async Task < bool > ReadAsync ( IOBehavior ioBehavior , CancellationToken cancellationToken )
182
180
{
@@ -198,33 +196,32 @@ public async Task<bool> ReadAsync(IOBehavior ioBehavior, CancellationToken cance
198
196
return true ;
199
197
}
200
198
201
- public async Task < Row > BufferReadAsync ( IOBehavior ioBehavior , CancellationToken cancellationToken )
199
+ public async Task < Row ? > BufferReadAsync ( IOBehavior ioBehavior , CancellationToken cancellationToken )
202
200
{
203
- m_rowBuffered = m_rowBuffered ? . Clone ( ) ;
204
- // ScanRowAsync sets m_rowBuffered to the next row if there is one
205
- if ( await ScanRowAsync ( ioBehavior , null , cancellationToken ) . ConfigureAwait ( false ) is null )
201
+ var row = await ScanRowAsync ( ioBehavior , null , cancellationToken ) . ConfigureAwait ( false ) ;
202
+ if ( row is null )
206
203
return null ;
207
204
if ( m_readBuffer is null )
208
205
m_readBuffer = new Queue < Row > ( ) ;
209
- m_readBuffer . Enqueue ( m_rowBuffered ) ;
210
- return m_rowBuffered ;
206
+ m_readBuffer . Enqueue ( row ) ;
207
+ return row ;
211
208
}
212
209
213
- private ValueTask < Row > ScanRowAsync ( IOBehavior ioBehavior , Row row , CancellationToken cancellationToken )
210
+ private ValueTask < Row ? > ScanRowAsync ( IOBehavior ioBehavior , Row ? row , CancellationToken cancellationToken )
214
211
{
215
212
// if we've already read past the end of this resultset, Read returns false
216
213
if ( BufferState == ResultSetState . HasMoreData || BufferState == ResultSetState . NoMoreData || BufferState == ResultSetState . None )
217
- return new ValueTask < Row > ( ( Row ) null ) ;
214
+ return new ValueTask < Row ? > ( default ( Row ? ) ) ;
218
215
219
216
using ( Command . CancellableCommand . RegisterCancel ( cancellationToken ) )
220
217
{
221
218
var payloadValueTask = Session . ReceiveReplyAsync ( ioBehavior , CancellationToken . None ) ;
222
219
return payloadValueTask . IsCompletedSuccessfully
223
- ? new ValueTask < Row > ( ScanRowAsyncRemainder ( this , payloadValueTask . Result , row ) )
224
- : new ValueTask < Row > ( ScanRowAsyncAwaited ( this , payloadValueTask . AsTask ( ) , row , cancellationToken ) ) ;
220
+ ? new ValueTask < Row ? > ( ScanRowAsyncRemainder ( this , payloadValueTask . Result , row ) )
221
+ : new ValueTask < Row ? > ( ScanRowAsyncAwaited ( this , payloadValueTask . AsTask ( ) , row , cancellationToken ) ) ;
225
222
}
226
223
227
- static async Task < Row > ScanRowAsyncAwaited ( ResultSet this_ , Task < PayloadData > payloadTask , Row row_ , CancellationToken token )
224
+ static async Task < Row ? > ScanRowAsyncAwaited ( ResultSet this_ , Task < PayloadData > payloadTask , Row ? row_ , CancellationToken token )
228
225
{
229
226
PayloadData payloadData ;
230
227
try
@@ -241,7 +238,7 @@ static async Task<Row> ScanRowAsyncAwaited(ResultSet this_, Task<PayloadData> pa
241
238
return ScanRowAsyncRemainder ( this_ , payloadData , row_ ) ;
242
239
}
243
240
244
- static Row ScanRowAsyncRemainder ( ResultSet this_ , PayloadData payload , Row row_ )
241
+ static Row ? ScanRowAsyncRemainder ( ResultSet this_ , PayloadData payload , Row ? row_ )
245
242
{
246
243
if ( payload . HeaderByte == EofPayload . Signature )
247
244
{
@@ -250,14 +247,12 @@ static Row ScanRowAsyncRemainder(ResultSet this_, PayloadData payload, Row row_)
250
247
{
251
248
var ok = OkPayload . Create ( span , this_ . Session . SupportsDeprecateEof , this_ . Session . SupportsSessionTrack ) ;
252
249
this_ . BufferState = ( ok . ServerStatus & ServerStatus . MoreResultsExist ) == 0 ? ResultSetState . NoMoreData : ResultSetState . HasMoreData ;
253
- this_ . m_rowBuffered = null ;
254
250
return null ;
255
251
}
256
252
if ( ! this_ . Session . SupportsDeprecateEof && EofPayload . IsEof ( payload ) )
257
253
{
258
254
var eof = EofPayload . Create ( span ) ;
259
255
this_ . BufferState = ( eof . ServerStatus & ServerStatus . MoreResultsExist ) == 0 ? ResultSetState . NoMoreData : ResultSetState . HasMoreData ;
260
- this_ . m_rowBuffered = null ;
261
256
return null ;
262
257
}
263
258
}
@@ -318,7 +313,7 @@ static Row ScanRowAsyncRemainder(ResultSet this_, PayloadData payload, Row row_)
318
313
reader . Offset += length ;
319
314
columnCount ++ ;
320
315
321
- if ( columnCount == this_ . ColumnDefinitions . Length )
316
+ if ( columnCount == this_ . ColumnDefinitions ! . Length )
322
317
{
323
318
// if we used up all the bytes reading exactly 'ColumnDefinitions' length-encoded columns, then assume this is a text row
324
319
if ( reader . BytesRemaining == 0 )
@@ -332,7 +327,6 @@ static Row ScanRowAsyncRemainder(ResultSet this_, PayloadData payload, Row row_)
332
327
row_ = isBinaryRow ? ( Row ) new BinaryRow ( this_ ) : new TextRow ( this_ ) ;
333
328
}
334
329
row_ . SetData ( payload . Memory ) ;
335
- this_ . m_rowBuffered = row_ ;
336
330
this_ . m_hasRows = true ;
337
331
this_ . BufferState = ResultSetState . ReadingRows ;
338
332
return row_ ;
@@ -357,7 +351,7 @@ public string GetDataTypeName(int ordinal)
357
351
if ( ordinal < 0 || ordinal >= ColumnDefinitions . Length )
358
352
throw new IndexOutOfRangeException ( "value must be between 0 and {0}." . FormatInvariant ( ColumnDefinitions . Length ) ) ;
359
353
360
- var mySqlDbType = ColumnTypes [ ordinal ] ;
354
+ var mySqlDbType = ColumnTypes ! [ ordinal ] ;
361
355
if ( mySqlDbType == MySqlDbType . String )
362
356
return string . Format ( CultureInfo . InvariantCulture , "CHAR({0})" , ColumnDefinitions [ ordinal ] . ColumnLength / ProtocolUtility . GetBytesPerCharacter ( ColumnDefinitions [ ordinal ] . CharacterSet ) ) ;
363
357
return TypeMapper . Instance . GetColumnTypeMetadata ( mySqlDbType ) . SimpleDataTypeName ;
@@ -370,7 +364,7 @@ public Type GetFieldType(int ordinal)
370
364
if ( ordinal < 0 || ordinal >= ColumnDefinitions . Length )
371
365
throw new IndexOutOfRangeException ( "value must be between 0 and {0}." . FormatInvariant ( ColumnDefinitions . Length ) ) ;
372
366
373
- var type = TypeMapper . Instance . GetColumnTypeMetadata ( ColumnTypes [ ordinal ] ) . DbTypeMapping . ClrType ;
367
+ var type = TypeMapper . Instance . GetColumnTypeMetadata ( ColumnTypes ! [ ordinal ] ) . DbTypeMapping . ClrType ;
374
368
if ( Connection . AllowZeroDateTime && type == typeof ( DateTime ) )
375
369
type = typeof ( MySqlDateTime ) ;
376
370
return type ;
@@ -412,25 +406,24 @@ public Row GetCurrentRow()
412
406
}
413
407
414
408
public readonly MySqlDataReader DataReader ;
415
- public Exception ReadResultSetHeaderException { get ; private set ; }
409
+ public Exception ? ReadResultSetHeaderException { get ; private set ; }
416
410
public IMySqlCommand Command => DataReader . Command ;
417
411
public MySqlConnection Connection => DataReader . Connection ;
418
412
public ServerSession Session => DataReader . Session ;
419
413
420
414
public ResultSetState BufferState { get ; private set ; }
421
- public ColumnDefinitionPayload [ ] ColumnDefinitions { get ; private set ; }
422
- public MySqlDbType [ ] ColumnTypes { get ; private set ; }
415
+ public ColumnDefinitionPayload [ ] ? ColumnDefinitions { get ; private set ; }
416
+ public MySqlDbType [ ] ? ColumnTypes { get ; private set ; }
423
417
public long LastInsertId { get ; private set ; }
424
418
public int ? RecordsAffected { get ; private set ; }
425
419
public int WarningCount { get ; private set ; }
426
420
public ResultSetState State { get ; private set ; }
427
421
public bool ContainsCommandParameters { get ; private set ; }
428
422
429
- ResizableArray < byte > m_columnDefinitionPayloads ;
423
+ ResizableArray < byte > ? m_columnDefinitionPayloads ;
430
424
int m_columnDefinitionPayloadUsedBytes ;
431
- Queue < Row > m_readBuffer ;
432
- Row m_row ;
433
- Row m_rowBuffered ;
425
+ Queue < Row > ? m_readBuffer ;
426
+ Row ? m_row ;
434
427
bool m_hasRows ;
435
428
}
436
429
}
0 commit comments