Skip to content

Commit b1b5f4f

Browse files
[Hotfix 4.0.2] | Fix null binary rowversion and add test coverage (#1688) (#1724)
1 parent 621dcd6 commit b1b5f4f

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBuffer.cs

+4
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,10 @@ internal SqlBinary SqlBinary
625625
{
626626
if (StorageType.SqlBinary == _type)
627627
{
628+
if (IsNull)
629+
{
630+
return SqlBinary.Null;
631+
}
628632
return (SqlBinary)_object;
629633
}
630634
return (SqlBinary)SqlValue; // anything else we haven't thought of goes through boxing.

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBuffer.cs

+4
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,10 @@ internal SqlBinary SqlBinary
607607
{
608608
if (StorageType.SqlBinary == _type)
609609
{
610+
if (IsNull)
611+
{
612+
return SqlBinary.Null;
613+
}
610614
return (SqlBinary)_object;
611615
}
612616
return (SqlBinary)SqlValue; // anything else we haven't thought of goes through boxing.

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/DataReaderTest/DataReaderTest.cs

+8
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,14 @@ public static void CheckNullRowVersionIsBDNull()
282282
Assert.IsType<DBNull>(result);
283283
Assert.Equal(result, reader.GetFieldValue<DBNull>(0));
284284
Assert.Throws<SqlNullValueException>(() => reader.GetFieldValue<byte[]>(0));
285+
286+
SqlBinary binary = reader.GetSqlBinary(0);
287+
Assert.True(binary.IsNull);
288+
289+
SqlBytes bytes = reader.GetSqlBytes(0);
290+
Assert.True(bytes.IsNull);
291+
Assert.Null(bytes.Buffer);
292+
285293
}
286294
finally
287295
{

0 commit comments

Comments
 (0)