Repository navigation
Validate TDS parser prerequisites and invalidate malformed responses #4941
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...soft.Data.SqlClient/tests/ManualTests/SQL/ConnectivityTests/ParserResultProcessingTest.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Data; | ||
| using System.Threading.Tasks; | ||
| using Xunit; | ||
|
|
||
| namespace Microsoft.Data.SqlClient.ManualTesting.Tests; | ||
|
|
||
| /// <summary> | ||
| /// Verifies that parser prerequisite validation preserves valid login, nullable rows, | ||
| /// result skipping, and subsequent commands against SQL Server. | ||
| /// </summary> | ||
| [Trait("Set", "2")] | ||
| public class ParserResultProcessingTest | ||
| { | ||
| /// <summary> | ||
| /// Consumes null and non-null values, skips unread rows, and reuses the connection with | ||
| /// synchronous/asynchronous APIs and both buffered and sequential access. | ||
| /// </summary> | ||
| [ConditionalTheory(typeof(DataTestUtility), nameof(DataTestUtility.AreConnStringsSetup))] | ||
| [InlineData(false, false)] | ||
| [InlineData(false, true)] | ||
| [InlineData(true, false)] | ||
| [InlineData(true, true)] | ||
| public async Task ValidResults_PreserveConnection(bool useAsync, bool sequential) | ||
| { | ||
| using SqlConnection connection = DataTestUtility.CreateConnection( | ||
| DataTestUtility.TCPConnectionString); | ||
| if (useAsync) | ||
| { | ||
| await connection.OpenAsync(); | ||
| } | ||
| else | ||
| { | ||
| connection.Open(); | ||
| } | ||
|
|
||
| // Sorting puts NULL first and leaves a deterministic unread row before the second result. | ||
| using SqlCommand command = new( | ||
| "SELECT CAST(NULL AS int) AS value UNION ALL SELECT 1 UNION ALL SELECT 2 " + | ||
| "ORDER BY value; " + | ||
| "SELECT 42 AS value;", connection); | ||
| CommandBehavior behavior = sequential | ||
| ? CommandBehavior.SequentialAccess | ||
| : CommandBehavior.Default; | ||
| using (SqlDataReader reader = useAsync | ||
| ? await command.ExecuteReaderAsync(behavior) | ||
| : command.ExecuteReader(behavior)) | ||
| { | ||
| Assert.True(useAsync ? await reader.ReadAsync() : reader.Read()); | ||
| Assert.True(reader.IsDBNull(0)); | ||
| Assert.True(useAsync ? await reader.ReadAsync() : reader.Read()); | ||
| Assert.Equal(1, reader.GetInt32(0)); | ||
| // Skip the unread value 2 and verify that the next result uses its own metadata. | ||
| Assert.True(useAsync ? await reader.NextResultAsync() : reader.NextResult()); | ||
| Assert.True(useAsync ? await reader.ReadAsync() : reader.Read()); | ||
| Assert.Equal(42, reader.GetInt32(0)); | ||
| Assert.False(useAsync ? await reader.ReadAsync() : reader.Read()); | ||
| Assert.False(useAsync ? await reader.NextResultAsync() : reader.NextResult()); | ||
| } | ||
|
|
||
| // A subsequent command proves valid result processing did not invalidate the connection. | ||
| command.CommandText = "SELECT 7"; | ||
| object result = useAsync | ||
| ? await command.ExecuteScalarAsync() | ||
| : command.ExecuteScalar(); | ||
| Assert.Equal(7, result); | ||
| Assert.Equal(ConnectionState.Open, connection.State); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.