Skip to content

Commit c615e7a

Browse files
committed
Revert "Fix SqlCached buffer async read with continue edge case. (#3329)"
This reverts commit c3857b1.
1 parent a2863dd commit c615e7a

File tree

2 files changed

+9
-207
lines changed

2 files changed

+9
-207
lines changed

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCachedBuffer.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
3939
{
4040
buffer = null;
4141

42-
(bool isAvailable, bool isStarting, _) = stateObj.GetSnapshotStatuses();
42+
(bool isAvailable, bool isStarting, bool isContinuing) = stateObj.GetSnapshotStatuses();
4343

4444
List<byte[]> cachedBytes = null;
4545
if (isAvailable)
4646
{
4747
cachedBytes = stateObj.TryTakeSnapshotStorage() as List<byte[]>;
48-
if (isStarting)
48+
if (cachedBytes != null && !isStarting && !isContinuing)
4949
{
50-
cachedBytes = null;
50+
stateObj.SetSnapshotStorage(null);
5151
}
5252
}
5353

@@ -56,13 +56,15 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
5656
cachedBytes = new List<byte[]>();
5757
}
5858

59+
5960
// the very first length is already read.
6061
TdsOperationStatus result = parser.TryPlpBytesLeft(stateObj, out ulong plplength);
6162
if (result != TdsOperationStatus.Done)
6263
{
6364
return result;
6465
}
6566

67+
6668
// For now we only handle Plp data from the parser directly.
6769
Debug.Assert(metadata.metaType.IsPlp, "SqlCachedBuffer call on a non-plp data");
6870
do
@@ -103,7 +105,10 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
103105

104106
if (returnAfterAdd)
105107
{
106-
stateObj.SetSnapshotStorage(cachedBytes);
108+
if (isStarting || isContinuing)
109+
{
110+
stateObj.SetSnapshotStorage(cachedBytes);
111+
}
107112
return result;
108113
}
109114

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

Lines changed: 0 additions & 203 deletions
Original file line numberDiff line numberDiff line change
@@ -388,209 +388,6 @@ public static async Task<int> CanReadEmployeesTableCompletelyWithNullImageAsync(
388388
return counter;
389389
}
390390

391-
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))]
392-
public static async Task<int> CanReadXmlData()
393-
{
394-
const string xml = @"<catalog id1=""00000000-0000-0000-0000-000000000000"" id2=""00000000-0000-0000-0000-000000000000"" id3=""00000000-0000-0000-0000-000000000000"" id4=""00000000-0000-0000-0000-000000000000"" id5=""00000000-0000-0000-0000-000000000000"">
395-
<book id=""bk101"">
396-
<author>Gambardella, Matthew</author>
397-
<title>XML Developer's Guide</title>
398-
<genre>Computer</genre>
399-
<price>44.95</price>
400-
<publish_date>2000-10-01</publish_date>
401-
<description>An in-depth look at creating applications
402-
with XML.</description>
403-
</book>
404-
<book id=""bk102"">
405-
<author>Ralls, Kim</author>
406-
<title>Midnight Rain</title>
407-
<genre>Fantasy</genre>
408-
<price>5.95</price>
409-
<publish_date>2000-12-16</publish_date>
410-
<description>A former architect battles corporate zombies,
411-
an evil sorceress, and her own childhood to become queen
412-
of the world.</description>
413-
</book>
414-
<book id=""bk103"">
415-
<author>Corets, Eva</author>
416-
<title>Maeve Ascendant</title>
417-
<genre>Fantasy</genre>
418-
<price>5.95</price>
419-
<publish_date>2000-11-17</publish_date>
420-
<description>After the collapse of a nanotechnology
421-
society in England, the young survivors lay the
422-
foundation for a new society.</description>
423-
</book>
424-
<book id=""bk104"">
425-
<author>Corets, Eva</author>
426-
<title>Oberon's Legacy</title>
427-
<genre>Fantasy</genre>
428-
<price>5.95</price>
429-
<publish_date>2001-03-10</publish_date>
430-
<description>In post-apocalypse England, the mysterious
431-
agent known only as Oberon helps to create a new life
432-
for the inhabitants of London. Sequel to Maeve
433-
Ascendant.</description>
434-
</book>
435-
<book id=""bk105"">
436-
<author>Corets, Eva</author>
437-
<title>The Sundered Grail</title>
438-
<genre>Fantasy</genre>
439-
<price>5.95</price>
440-
<publish_date>2001-09-10</publish_date>
441-
<description>The two daughters of Maeve, half-sisters,
442-
battle one another for control of England. Sequel to
443-
Oberon's Legacy.</description>
444-
</book>
445-
<book id=""bk106"">
446-
<author>Randall, Cynthia</author>
447-
<title>Lover Birds</title>
448-
<genre>Romance</genre>
449-
<price>4.95</price>
450-
<publish_date>2000-09-02</publish_date>
451-
<description>When Carla meets Paul at an ornithology
452-
conference, tempers fly as feathers get ruffled.</description>
453-
</book>
454-
<book id=""bk107"">
455-
<author>Thurman, Paula</author>
456-
<title>Splish Splash</title>
457-
<genre>Romance</genre>
458-
<price>4.95</price>
459-
<publish_date>2000-11-02</publish_date>
460-
<description>A deep sea diver finds true love twenty
461-
thousand leagues beneath the sea.</description>
462-
</book>
463-
<book id=""bk108"">
464-
<author>Knorr, Stefan</author>
465-
<title>Creepy Crawlies</title>
466-
<genre>Horror</genre>
467-
<price>4.95</price>
468-
<publish_date>2000-12-06</publish_date>
469-
<description>An anthology of horror stories about roaches,
470-
centipedes, scorpions and other insects.</description>
471-
</book>
472-
<book id=""bk109"">
473-
<author>Kress, Peter</author>
474-
<title>Paradox Lost</title>
475-
<genre>Science Fiction</genre>
476-
<price>6.95</price>
477-
<publish_date>2000-11-02</publish_date>
478-
<description>After an inadvertant trip through a Heisenberg
479-
Uncertainty Device, James Salway discovers the problems
480-
of being quantum.</description>
481-
</book>
482-
<book id=""bk110"">
483-
<author>O'Brien, Tim</author>
484-
<title>Microsoft .NET: The Programming Bible</title>
485-
<genre>Computer</genre>
486-
<price>36.95</price>
487-
<publish_date>2000-12-09</publish_date>
488-
<description>Microsoft's .NET initiative is explored in
489-
detail in this deep programmer's reference.</description>
490-
</book>
491-
<book id=""bk111"">
492-
<author>O'Brien, Tim</author>
493-
<title>MSXML3: A Comprehensive Guide</title>
494-
<genre>Computer</genre>
495-
<price>36.95</price>
496-
<publish_date>2000-12-01</publish_date>
497-
<description>The Microsoft MSXML3 parser is covered in
498-
detail, with attention to XML DOM interfaces, XSLT processing,
499-
SAX and more.</description>
500-
</book>
501-
<book id=""bk112"">
502-
<author>Galos, Mike</author>
503-
<title>Visual Studio 7: A Comprehensive Guide</title>
504-
<genre>Computer</genre>
505-
<price>49.95</price>
506-
<publish_date>2001-04-16</publish_date>
507-
<description>Microsoft Visual Studio 7 is explored in depth,
508-
looking at how Visual Basic, Visual C++, C#, and ASP+ are
509-
integrated into a comprehensive development
510-
environment.</description>
511-
</book>
512-
</catalog>";
513-
514-
string tableName = DataTestUtility.GenerateObjectName();
515-
516-
SqlConnectionStringBuilder builder = new SqlConnectionStringBuilder(DataTestUtility.TCPConnectionString);
517-
builder.PersistSecurityInfo = true;
518-
builder.PacketSize = 3096; // should reproduce failure that this tests for in <100 reads
519-
520-
using (var connection = new SqlConnection(builder.ToString()))
521-
{
522-
await connection.OpenAsync();
523-
524-
try
525-
{
526-
// setup
527-
using (var dropCommand = connection.CreateCommand())
528-
{
529-
dropCommand.CommandText = $"DROP TABLE IF EXISTS [{tableName}]";
530-
dropCommand.ExecuteNonQuery();
531-
}
532-
533-
using (var createCommand = connection.CreateCommand())
534-
{
535-
createCommand.CommandText = $"CREATE TABLE [{tableName}] (Id int PRIMARY KEY, Data xml NOT NULL)";
536-
createCommand.ExecuteNonQuery();
537-
}
538-
539-
for (var i = 0; i < 100; i++)
540-
{
541-
using (var insertCommand = connection.CreateCommand())
542-
{
543-
insertCommand.CommandText = $"INSERT INTO [{tableName}] (Id, Data) VALUES (@id, @data)";
544-
insertCommand.Parameters.AddWithValue("@id", i);
545-
insertCommand.Parameters.AddWithValue("@data", xml);
546-
insertCommand.ExecuteNonQuery();
547-
}
548-
}
549-
550-
// execute
551-
int id = 0;
552-
553-
using (var command = connection.CreateCommand())
554-
{
555-
command.CommandText = $"SELECT Data FROM [{tableName}] ORDER BY Id";
556-
using (var reader = await command.ExecuteReaderAsync())
557-
{
558-
string expectedResult = null;
559-
while (await reader.ReadAsync())
560-
{
561-
var result = reader.GetString(0);
562-
if (expectedResult == null)
563-
{
564-
expectedResult = result;
565-
}
566-
else
567-
{
568-
Assert.Equal(expectedResult, result);
569-
}
570-
id++;
571-
}
572-
}
573-
}
574-
return id;
575-
576-
}
577-
finally
578-
{
579-
try
580-
{
581-
using (var dropCommand = connection.CreateCommand())
582-
{
583-
dropCommand.CommandText = $"DROP TABLE IF EXISTS [{tableName}]";
584-
dropCommand.ExecuteNonQuery();
585-
}
586-
}
587-
catch
588-
{
589-
}
590-
}
591-
}
592-
}
593-
594391
// Synapse: Cannot find data type 'rowversion'.
595392
[ConditionalFact(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup), nameof(DataTestUtility.IsNotAzureSynapse))]
596393
public static void CheckLegacyNullRowVersionIsEmptyArray()

0 commit comments

Comments
 (0)