@ -1512,7 +1512,7 @@ namespace Microsoft.Data.SqlClient
if ( writeDataSizeToSnapshot )
{
Set SnapshotDataSize( bytesToRead ) ;
Add SnapshotDataSize( bytesToRead ) ;
}
AssertValidState ( ) ;
@ -2058,7 +2058,7 @@ namespace Microsoft.Data.SqlClient
// bool firstchunk = false;
bool isNull = false ;
Debug . Assert ( _longlenleft = = 0 , "Out of synch length read request" ) ;
Debug . Assert ( _longlenleft = = 0 , "Out of sync length read request" ) ;
if ( _longlen = = 0 )
{
// First chunk is being read. Find out what type of chunk it is
@ -2139,6 +2139,7 @@ namespace Microsoft.Data.SqlClient
}
return TryReadPlpBytes ( ref buff , offset , len , out totalBytesRead , canContinue , canContinue , compatibilityMode ) ;
}
// Reads the requested number of bytes from a plp data stream, or the entire data if
// requested length is -1 or larger than the actual length of data. First call to this method
// should be preceeded by a call to ReadPlpLength or ReadDataLength.
@ -2254,14 +2255,14 @@ namespace Microsoft.Data.SqlClient
SetSnapshotStorage ( buff ) ;
if ( writeDataSizeToSnapshot )
{
Set SnapshotDataSize( bytesRead ) ;
Add SnapshotDataSize( bytesRead ) ;
}
}
return result ;
}
if ( writeDataSizeToSnapshot & & canContinue )
{
Set SnapshotDataSize( bytesRead ) ;
Add SnapshotDataSize( bytesRead ) ;
}
if ( _longlenleft = = 0 )
@ -2279,10 +2280,7 @@ namespace Microsoft.Data.SqlClient
else if ( canContinue & & result = = TdsOperationStatus . NeedMoreData )
{
SetSnapshotStorage ( buff ) ;
if ( writeDataSizeToSnapshot )
{
SetSnapshotDataSize ( bytesRead ) ;
}
// data bytes read from the current packet must be 0 here so do not save the snapshot data size
}
return result ;
}
@ -2296,6 +2294,12 @@ namespace Microsoft.Data.SqlClient
break ;
}
}
if ( canContinue )
{
SetSnapshotStorage ( null ) ;
ClearSnapshotDataSize ( ) ;
}
return TdsOperationStatus . Done ;
}
@ -3531,9 +3535,6 @@ namespace Microsoft.Data.SqlClient
{
StateSnapshot snapshot = _snapshot ;
_snapshot = null ;
// TODO(GH-3385): Not sure what this is trying to assert, but it
// currently fails the DataReader tests.
// Debug.Assert(snapshot._storage == null);
snapshot . Clear ( ) ;
Interlocked . CompareExchange ( ref _cachedSnapshot , snapshot , null ) ;
}
@ -3591,9 +3592,6 @@ namespace Microsoft.Data.SqlClient
internal void SetSnapshotStorage ( object buffer )
{
Debug . Assert ( _snapshot ! = null , "should not access snapshot accessor functions without first checking that the snapshot is available" ) ;
// TODO(GH-3385): Not sure what this is trying to assert, but it
// currently fails the DataReader tests.
// Debug.Assert(_snapshot._storage == null, "should not overwrite snapshot stored buffer");
if ( _snapshot ! = null )
{
_snapshot . _storage = buffer ;
@ -3605,12 +3603,18 @@ namespace Microsoft.Data.SqlClient
/// countOfBytesCopiedFromCurrentPacket to be calculated
/// </summary>
/// <param name="countOfBytesCopiedFromCurrentPacket"></param>
internal void Set SnapshotDataSize( int countOfBytesCopiedFromCurrentPacket )
internal void Add SnapshotDataSize( int countOfBytesCopiedFromCurrentPacket )
{
Debug . Assert ( _snapshot ! = null & & _snapshot . ContinueEnabled , "_snapshot must exist to store packet data size" ) ;
_snapshot . SetPacketDataSize ( countOfBytesCopiedFromCurrentPacket ) ;
}
internal void ClearSnapshotDataSize ( )
{
Debug . Assert ( _snapshot ! = null , "_snapshot must exist to store packet data size" ) ;
_snapshot ? . ClearPacketDataSize ( ) ;
}
internal int GetSnapshotTotalSize ( )
{
Debug . Assert ( _snapshot ! = null & & _snapshot . ContinueEnabled , "_snapshot must exist to read total size" ) ;
@ -4307,6 +4311,16 @@ namespace Microsoft.Data.SqlClient
target . RunningDataSize = total + size ;
}
internal void ClearPacketDataSize ( )
{
PacketData current = _firstPacket ;
while ( current ! = null )
{
current . RunningDataSize = 0 ;
current = current . NextPacket ;
}
}
internal int GetPacketDataOffset ( )
{
int offset = 0 ;
@ -4356,9 +4370,6 @@ namespace Microsoft.Data.SqlClient
private void ClearState ( )
{
// TODO(GH-3385): Not sure what this is trying to assert, but it
// currently fails the DataReader tests.
// Debug.Assert(_storage == null);
_storage = null ;
_replayStateData . Clear ( _stateObj ) ;
_continueStateData ? . Clear ( _stateObj , trackStack : false ) ;