Skip to content

Commit a2ad9d2

Browse files
committed
fix ef core test and add coverage
1 parent 7db3c50 commit a2ad9d2

File tree

3 files changed

+112
-0
lines changed

3 files changed

+112
-0
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5556,6 +5556,12 @@ private TdsOperationStatus TryProcessColumnHeaderNoNBC(SqlMetaDataPriv col, TdsP
55565556
{
55575557
if (col.metaType.IsLong && !col.metaType.IsPlp)
55585558
{
5559+
if (stateObj.IsSnapshotContinuing())
5560+
{
5561+
length = (ulong)stateObj.GetSnapshotStorageLength<byte>();
5562+
isNull = length == 0;
5563+
return TdsOperationStatus.Done;
5564+
}
55595565
//
55605566
// we don't care about TextPtrs, simply go after the data after it
55615567
//

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6019,6 +6019,12 @@ private TdsOperationStatus TryProcessColumnHeaderNoNBC(SqlMetaDataPriv col, TdsP
60196019
{
60206020
if (col.metaType.IsLong && !col.metaType.IsPlp)
60216021
{
6022+
if (stateObj.IsSnapshotContinuing())
6023+
{
6024+
length = (ulong)stateObj.GetSnapshotStorageLength<byte>();
6025+
isNull = length == 0;
6026+
return TdsOperationStatus.Done;
6027+
}
60226028
//
60236029
// we don't care about TextPtrs, simply go after the data after it
60246030
//

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

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
using System.Reflection;
1010
using System.Text;
1111
using System.Threading;
12+
using System.Threading.Tasks;
1213
using Xunit;
1314

1415
namespace Microsoft.Data.SqlClient.ManualTesting.Tests
@@ -300,6 +301,105 @@ public static void CheckNullRowVersionIsBDNull()
300301
}
301302
}
302303

304+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
305+
public static int CanReadEmployeesTableCompletely()
306+
{
307+
int counter = 0;
308+
309+
using (var conn = new SqlConnection(DataTestUtility.TCPConnectionString))
310+
{
311+
using (var cmd = new SqlCommand("SELECT EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath FROM Employees WHERE ReportsTo = @p0 OR (ReportsTo IS NULL AND @p0 IS NULL)", conn))
312+
{
313+
cmd.Parameters.AddWithValue("@p0", 5);
314+
315+
conn.Open();
316+
317+
using (var reader = cmd.ExecuteReader())
318+
{
319+
if (reader.Read())
320+
{
321+
for (int index = 0; index < reader.FieldCount; index++)
322+
{
323+
if (!reader.IsDBNull(index))
324+
{
325+
object value = reader[index];
326+
counter += 1;
327+
}
328+
}
329+
}
330+
}
331+
}
332+
}
333+
334+
return counter;
335+
}
336+
337+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
338+
public static async Task<int> CanReadEmployeesTableCompletelyAsync()
339+
{
340+
int counter = 0;
341+
342+
using (var conn = new SqlConnection(DataTestUtility.TCPConnectionString))
343+
{
344+
using (var cmd = new SqlCommand("SELECT EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,Address,City,Region,PostalCode,Country,HomePhone,Extension,Photo,Notes,ReportsTo,PhotoPath FROM Employees WHERE ReportsTo = @p0 OR (ReportsTo IS NULL AND @p0 IS NULL)", conn))
345+
{
346+
cmd.Parameters.AddWithValue("@p0", 5);
347+
348+
await conn.OpenAsync();
349+
350+
using (var reader = await cmd.ExecuteReaderAsync())
351+
{
352+
if (await reader.ReadAsync())
353+
{
354+
for (int index = 0; index < reader.FieldCount; index++)
355+
{
356+
if (!await reader.IsDBNullAsync(index))
357+
{
358+
object value = reader[index];
359+
counter += 1;
360+
}
361+
}
362+
}
363+
}
364+
}
365+
}
366+
367+
return counter;
368+
}
369+
370+
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
371+
public static async Task<int> CanReadEmployeesTableCompletelyWithNullImageAsync()
372+
{
373+
int counter = 0;
374+
375+
using (var conn = new SqlConnection(DataTestUtility.TCPConnectionString))
376+
{
377+
using (var cmd = new SqlCommand("SELECT EmployeeID,LastName,FirstName,Title,TitleOfCourtesy,BirthDate,HireDate,Address,City,Region,PostalCode,Country,HomePhone,Extension,convert(image,NULL) as Photo,Notes,ReportsTo,PhotoPath FROM Employees WHERE ReportsTo = @p0 OR (ReportsTo IS NULL AND @p0 IS NULL)", conn))
378+
{
379+
cmd.Parameters.AddWithValue("@p0", 5);
380+
381+
await conn.OpenAsync();
382+
383+
using (var reader = await cmd.ExecuteReaderAsync())
384+
{
385+
if (await reader.ReadAsync())
386+
{
387+
for (int index = 0; index < reader.FieldCount; index++)
388+
{
389+
if (!await reader.IsDBNullAsync(index))
390+
{
391+
object value = reader[index];
392+
counter += 1;
393+
}
394+
}
395+
}
396+
}
397+
}
398+
}
399+
400+
return counter;
401+
}
402+
303403
// Synapse: Cannot find data type 'rowversion'.
304404
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
305405
public static void CheckLegacyNullRowVersionIsEmptyArray()

0 commit comments

Comments
 (0)