@@ -1488,7 +1488,7 @@ public TdsOperationStatus TryReadByteArray(Span<byte> buff, int len, out int tot
1488
1488
1489
1489
if ( writeDataSizeToSnapshot )
1490
1490
{
1491
- SetSnapshotDataSize ( bytesToRead ) ;
1491
+ AddSnapshotDataSize ( bytesToRead ) ;
1492
1492
}
1493
1493
1494
1494
AssertValidState ( ) ;
@@ -2034,7 +2034,7 @@ internal TdsOperationStatus TryReadPlpLength(bool returnPlpNullIfNull, out ulong
2034
2034
// bool firstchunk = false;
2035
2035
bool isNull = false ;
2036
2036
2037
- Debug . Assert ( _longlenleft == 0 , "Out of synch length read request" ) ;
2037
+ Debug . Assert ( _longlenleft == 0 , "Out of sync length read request" ) ;
2038
2038
if ( _longlen == 0 )
2039
2039
{
2040
2040
// First chunk is being read. Find out what type of chunk it is
@@ -2115,6 +2115,7 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
2115
2115
}
2116
2116
return TryReadPlpBytes ( ref buff , offset , len , out totalBytesRead , canContinue , canContinue , compatibilityMode ) ;
2117
2117
}
2118
+
2118
2119
// Reads the requested number of bytes from a plp data stream, or the entire data if
2119
2120
// requested length is -1 or larger than the actual length of data. First call to this method
2120
2121
// should be preceeded by a call to ReadPlpLength or ReadDataLength.
@@ -2230,14 +2231,14 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
2230
2231
SetSnapshotStorage ( buff ) ;
2231
2232
if ( writeDataSizeToSnapshot )
2232
2233
{
2233
- SetSnapshotDataSize ( bytesRead ) ;
2234
+ AddSnapshotDataSize ( bytesRead ) ;
2234
2235
}
2235
2236
}
2236
2237
return result ;
2237
2238
}
2238
2239
if ( writeDataSizeToSnapshot && canContinue )
2239
2240
{
2240
- SetSnapshotDataSize ( bytesRead ) ;
2241
+ AddSnapshotDataSize ( bytesRead ) ;
2241
2242
}
2242
2243
2243
2244
if ( _longlenleft == 0 )
@@ -2255,10 +2256,7 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
2255
2256
else if ( canContinue && result == TdsOperationStatus . NeedMoreData )
2256
2257
{
2257
2258
SetSnapshotStorage ( buff ) ;
2258
- if ( writeDataSizeToSnapshot )
2259
- {
2260
- SetSnapshotDataSize ( bytesRead ) ;
2261
- }
2259
+ // data bytes read from the current packet must be 0 here so do not save the snapshot data size
2262
2260
}
2263
2261
return result ;
2264
2262
}
@@ -2272,6 +2270,12 @@ internal TdsOperationStatus TryReadPlpBytes(ref byte[] buff, int offset, int len
2272
2270
break ;
2273
2271
}
2274
2272
}
2273
+
2274
+ if ( canContinue )
2275
+ {
2276
+ SetSnapshotStorage ( null ) ;
2277
+ ClearSnapshotDataSize ( ) ;
2278
+ }
2275
2279
return TdsOperationStatus . Done ;
2276
2280
}
2277
2281
@@ -3507,9 +3511,6 @@ internal void ResetSnapshot()
3507
3511
{
3508
3512
StateSnapshot snapshot = _snapshot ;
3509
3513
_snapshot = null ;
3510
- // TODO(GH-3385): Not sure what this is trying to assert, but it
3511
- // currently fails the DataReader tests.
3512
- // Debug.Assert(snapshot._storage == null);
3513
3514
snapshot . Clear ( ) ;
3514
3515
Interlocked . CompareExchange ( ref _cachedSnapshot , snapshot , null ) ;
3515
3516
}
@@ -3567,9 +3568,6 @@ internal object TryTakeSnapshotStorage()
3567
3568
internal void SetSnapshotStorage ( object buffer )
3568
3569
{
3569
3570
Debug . Assert ( _snapshot != null , "should not access snapshot accessor functions without first checking that the snapshot is available" ) ;
3570
- // TODO(GH-3385): Not sure what this is trying to assert, but it
3571
- // currently fails the DataReader tests.
3572
- // Debug.Assert(_snapshot._storage == null, "should not overwrite snapshot stored buffer");
3573
3571
if ( _snapshot != null )
3574
3572
{
3575
3573
_snapshot . _storage = buffer ;
@@ -3581,12 +3579,18 @@ internal void SetSnapshotStorage(object buffer)
3581
3579
/// countOfBytesCopiedFromCurrentPacket to be calculated
3582
3580
/// </summary>
3583
3581
/// <param name="countOfBytesCopiedFromCurrentPacket"></param>
3584
- internal void SetSnapshotDataSize ( int countOfBytesCopiedFromCurrentPacket )
3582
+ internal void AddSnapshotDataSize ( int countOfBytesCopiedFromCurrentPacket )
3585
3583
{
3586
3584
Debug . Assert ( _snapshot != null && _snapshot . ContinueEnabled , "_snapshot must exist to store packet data size" ) ;
3587
3585
_snapshot . SetPacketDataSize ( countOfBytesCopiedFromCurrentPacket ) ;
3588
3586
}
3589
3587
3588
+ internal void ClearSnapshotDataSize ( )
3589
+ {
3590
+ Debug . Assert ( _snapshot != null , "_snapshot must exist to store packet data size" ) ;
3591
+ _snapshot ? . ClearPacketDataSize ( ) ;
3592
+ }
3593
+
3590
3594
internal int GetSnapshotTotalSize ( )
3591
3595
{
3592
3596
Debug . Assert ( _snapshot != null && _snapshot . ContinueEnabled , "_snapshot must exist to read total size" ) ;
@@ -4283,6 +4287,16 @@ internal void SetPacketDataSize(int size)
4283
4287
target . RunningDataSize = total + size ;
4284
4288
}
4285
4289
4290
+ internal void ClearPacketDataSize ( )
4291
+ {
4292
+ PacketData current = _firstPacket ;
4293
+ while ( current != null )
4294
+ {
4295
+ current . RunningDataSize = 0 ;
4296
+ current = current . NextPacket ;
4297
+ }
4298
+ }
4299
+
4286
4300
internal int GetPacketDataOffset ( )
4287
4301
{
4288
4302
int offset = 0 ;
@@ -4332,9 +4346,6 @@ private void ClearPackets()
4332
4346
4333
4347
private void ClearState ( )
4334
4348
{
4335
- // TODO(GH-3385): Not sure what this is trying to assert, but it
4336
- // currently fails the DataReader tests.
4337
- // Debug.Assert(_storage == null);
4338
4349
_storage = null ;
4339
4350
_replayStateData . Clear ( _stateObj ) ;
4340
4351
_continueStateData ? . Clear ( _stateObj , trackStack : false ) ;
0 commit comments