Skip to content

Commit

Permalink
Fix bug with LegacyRowVersionNullBehavior (#1182)
Browse files Browse the repository at this point in the history
  • Loading branch information
cheenamalhotra authored Aug 19, 2021
1 parent ffce6d3 commit ce5a1f7
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 206 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ protected override void Dispose(bool disposing)
}
base.Dispose(disposing);
}
catch(SqlException ex)
catch (SqlException ex)
{
SqlClientEventSource.Log.TryTraceEvent("SqlDataReader.Dispose | ERR | Error Message: {0}, Stack Trace: {1}", ex.Message, ex.StackTrace);
}
Expand Down Expand Up @@ -3771,26 +3771,18 @@ private bool TryReadColumnInternal(int i, bool readHeaderOnly = false)
_sharedState._nextColumnDataToRead = _sharedState._nextColumnHeaderToRead;
_sharedState._nextColumnHeaderToRead++; // We read this one

if (isNull)
// Trigger new behavior for RowVersion to send DBNull.Value by allowing entry for Timestamp or discard entry for Timestamp for legacy support.
// if LegacyRowVersionNullBehavior is enabled, Timestamp type must enter "else" block.
if (isNull && (!LocalAppContextSwitches.LegacyRowVersionNullBehavior || columnMetaData.type != SqlDbType.Timestamp))
{
if (columnMetaData.type == SqlDbType.Timestamp)
{
if (!LocalAppContextSwitches.LegacyRowVersionNullBehavior)
{
_data[i].SetToNullOfType(SqlBuffer.StorageType.SqlBinary);
}
}
else
{
TdsParser.GetNullSqlValue(_data[_sharedState._nextColumnDataToRead],
TdsParser.GetNullSqlValue(_data[_sharedState._nextColumnDataToRead],
columnMetaData,
_command != null ? _command.ColumnEncryptionSetting : SqlCommandColumnEncryptionSetting.UseConnectionSetting,
_parser.Connection);

if (!readHeaderOnly)
{
_sharedState._nextColumnDataToRead++;
}
if (!readHeaderOnly)
{
_sharedState._nextColumnDataToRead++;
}
}
else
Expand Down Expand Up @@ -4102,8 +4094,8 @@ internal bool TrySetMetaData(_SqlMetaDataSet metaData, bool moreInfo)

if (_parser != null)
{ // There is a valid case where parser is null
// Peek, and if row token present, set _hasRows true since there is a
// row in the result
// Peek, and if row token present, set _hasRows true since there is a
// row in the result
byte b;
if (!_stateObj.TryPeekByte(out b))
{
Expand Down Expand Up @@ -5015,7 +5007,7 @@ override public Task<T> GetFieldValueAsync<T>(int i, CancellationToken cancellat
{
_stateObj._shouldHaveEnoughData = true;
#endif
return Task.FromResult(GetFieldValueInternal<T>(i));
return Task.FromResult(GetFieldValueInternal<T>(i));
#if DEBUG
}
finally
Expand Down Expand Up @@ -5109,7 +5101,7 @@ internal void CompletePendingReadWithFailure(int errorCode, bool resetForcePendi

#endif

internal abstract class SqlDataReaderAsyncCallContext<T> : AAsyncCallContext<SqlDataReader,T>
internal abstract class SqlDataReaderAsyncCallContext<T> : AAsyncCallContext<SqlDataReader, T>
{
internal static readonly Action<Task<T>, object> s_completeCallback = CompleteAsyncCallCallback;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5424,6 +5424,10 @@ internal static object GetNullSqlValue(SqlBuffer nullVal, SqlMetaDataPriv md, Sq
break;

case SqlDbType.Timestamp:
if (!LocalAppContextSwitches.LegacyRowVersionNullBehavior)
{
nullVal.SetToNullOfType(SqlBuffer.StorageType.SqlBinary);
}
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4281,26 +4281,18 @@ private bool TryReadColumnInternal(int i, bool readHeaderOnly = false)
_sharedState._nextColumnDataToRead = _sharedState._nextColumnHeaderToRead;
_sharedState._nextColumnHeaderToRead++; // We read this one

if (isNull)
// Trigger new behavior for RowVersion to send DBNull.Value by allowing entry for Timestamp or discard entry for Timestamp for legacy support.
// if LegacyRowVersionNullBehavior is enabled, Timestamp type must enter "else" block.
if (isNull && (!LocalAppContextSwitches.LegacyRowVersionNullBehavior || columnMetaData.type != SqlDbType.Timestamp))
{
if (columnMetaData.type == SqlDbType.Timestamp)
{
if (!LocalAppContextSwitches.LegacyRowVersionNullBehavior)
{
_data[i].SetToNullOfType(SqlBuffer.StorageType.SqlBinary);
}
}
else
{
TdsParser.GetNullSqlValue(_data[_sharedState._nextColumnDataToRead],
TdsParser.GetNullSqlValue(_data[_sharedState._nextColumnDataToRead],
columnMetaData,
_command != null ? _command.ColumnEncryptionSetting : SqlCommandColumnEncryptionSetting.UseConnectionSetting,
_parser.Connection);

if (!readHeaderOnly)
{
_sharedState._nextColumnDataToRead++;
}
if (!readHeaderOnly)
{
_sharedState._nextColumnDataToRead++;
}
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6208,8 +6208,10 @@ internal static object GetNullSqlValue(
break;

case SqlDbType.Timestamp:
// Dev10 Bug #479607 - this should have been the same as SqlDbType.Binary, but it's a rejected breaking change
// Dev10 Bug #752790 - don't assert when it does happen
if (!LocalAppContextSwitches.LegacyRowVersionNullBehavior)
{
nullVal.SetToNullOfType(SqlBuffer.StorageType.SqlBinary);
}
break;

default:
Expand Down
Loading

0 comments on commit ce5a1f7

Please sign in to comment.