-
Notifications
You must be signed in to change notification settings - Fork 330
Cleanup | Consolidate connection capability metadata #3862
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
Open
edwardneal
wants to merge
34
commits into
dotnet:main
Choose a base branch
from
edwardneal:cleanup/unified-connection-capabilities
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
a6646c0
Add ConnectionCapabilities class
edwardneal e37f3a2
Hook LOGINACK handling
edwardneal de5c285
Update reference to _is20XX to reference Capabilities property
edwardneal 65e701f
Errata: use BinaryPrimitives
edwardneal 943c7db
Move handling of SqlLoginAck to ConnectionCapabilities
edwardneal c4ab86d
TdsEnums.cs constants cleanup
edwardneal d68b90c
Hook FEATUREEXT handling
edwardneal 936218e
Move JSON feature detection handling
edwardneal 53f8947
Move float32 vector feature detection handling
edwardneal 8ee0fb4
Move Azure SQL feature detection handling
edwardneal 7713018
Add additional detection logic for Global Transactions
edwardneal 0e1fcc5
Move Global Transactions feature detection handling
edwardneal ade2336
Move data classification feature detection handling
edwardneal ab9ebff
Move initial SQL DNS caching feature detection handling
edwardneal abd69b7
Remove unnecessary _cleanSQLDNSCaching member
edwardneal 50ccf47
Move column encryption feature detection handling
edwardneal 24caa2a
Move logic to throw on unknown FEATUREEXT tokens into TdsParser
edwardneal 984ac2e
Refactor parsing condition into ShouldProcessFeatureExtAck
edwardneal 9380711
Maintain original server version behaviour
edwardneal 95ac4f5
Performance: convert SqlLoginAck to a readonly ref struct
edwardneal 229a04d
Enable Release mode build
edwardneal 25b01d4
Plumb new ConnectionCapabilities to SqlMetaDataFactory
edwardneal 6560f5f
Cross-check FEATUREEXT validation to original OnFeatureExtAck
edwardneal 7c86769
Merge main
edwardneal 2402cd7
Merge branch 'main' into cleanup/unified-connection-capabilities
edwardneal f532f60
Merge main
edwardneal a67a8a8
Move enhanced routing feature detection support
edwardneal 731e99d
Merge main
edwardneal b1fea76
Revert movement of feature/login handling
edwardneal a84b88f
Revert handling of _cleanSQLDNSCaching
edwardneal 5791efe
Move Capabilities to DbConnectionInternal
edwardneal 7ef36b5
Move capability reset to connect methods
edwardneal 0c41cf4
Align Capabilities and ServerVersion exception behaviour across deriv…
edwardneal dd9db7e
Add unit test verifying behaviour of TDS version validation
edwardneal 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
222 changes: 222 additions & 0 deletions
222
...icrosoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/ConnectionCapabilities.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,222 @@ | ||
| // 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 Microsoft.Data.SqlClient.Internal; | ||
| using System; | ||
| using System.Text; | ||
|
|
||
| #nullable enable | ||
|
|
||
| namespace Microsoft.Data.SqlClient; | ||
|
|
||
| /// <summary> | ||
| /// Describes the capabilities and related information (such as the | ||
| /// reported server version and TDS version) of the connection. | ||
| /// </summary> | ||
| internal sealed class ConnectionCapabilities | ||
| { | ||
| /// <summary> | ||
| /// The TDS version reported by the LoginAck response | ||
| /// from the server. | ||
| /// </summary> | ||
| public uint TdsVersion { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The SQL Server major version reported by the LoginAck | ||
| /// response from the server. | ||
| /// </summary> | ||
| public byte ServerMajorVersion { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The SQL Server minor version reported by the LoginAck | ||
| /// response from the server. | ||
| /// </summary> | ||
| public byte ServerMinorVersion { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The SQL Server build number reported by the LoginAck | ||
| /// response from the server. | ||
| /// </summary> | ||
| public ushort ServerBuildNumber { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// The user-friendly SQL Server version reported by the | ||
| /// LoginAck response from the server. | ||
| /// </summary> | ||
| public string ServerVersion => | ||
| $"{ServerMajorVersion:00}.{ServerMinorVersion:00}.{ServerBuildNumber:0000}"; | ||
|
|
||
| /// <summary> | ||
| /// If true (as determined by the value of <see cref="TdsVersion"/>) | ||
| /// then the connection is to SQL Server 2008 R2 or newer. | ||
| /// </summary> | ||
| public bool Is2008R2OrNewer => | ||
| Is2012OrNewer || TdsVersion == TdsEnums.SQL2008_VERSION; | ||
|
|
||
| /// <summary> | ||
| /// If true (as determined by the value of <see cref="TdsVersion"/>) | ||
| /// then the connection is to SQL Server 2012 or newer. | ||
| /// </summary> | ||
| public bool Is2012OrNewer => | ||
| Is2022OrNewer || TdsVersion == TdsEnums.TDS7X_VERSION; | ||
|
|
||
| /// <summary> | ||
| /// If true (as determined by the value of <see cref="TdsVersion"/>) | ||
| /// then the connection is to SQL Server 2022 or newer. | ||
| /// </summary> | ||
| public bool Is2022OrNewer => | ||
| TdsVersion == TdsEnums.TDS80_VERSION; | ||
|
|
||
| /// <summary> | ||
| /// If true, this connection is to an Azure SQL instance. This is determined | ||
| /// by the receipt of a FEATUREEXTACK token of value <c>0x08</c>. | ||
| /// </summary> | ||
| public bool IsAzureSql { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for user-defined CLR types (up to a length of 8000 | ||
| /// bytes.) This was introduced in SQL Server 2005. | ||
| /// </summary> | ||
| public bool UserDefinedTypes => true; | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for the <c>xml</c> data type. This was introduced | ||
| /// in SQL Server 2005. | ||
| /// </summary> | ||
| public bool XmlDataType => true; | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for the <c>date</c>, <c>time</c>, <c>datetime2</c> | ||
| /// and <c>datetimeoffset</c> data types. These were introduced in SQL | ||
| /// Server 2008. | ||
| /// </summary> | ||
| public bool ExpandedDateTimeDataTypes => Is2008R2OrNewer; | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for user-defined CLR types of any length. This | ||
| /// was introduced in SQL Server 2008. | ||
| /// </summary> | ||
| public bool LargeUserDefinedTypes => Is2008R2OrNewer; | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for the client to include a TDS trace header, | ||
| /// which is surfaced in XEvents traces to correlate events between | ||
| /// the client and the server. This was introduced in SQL Server 2012. | ||
| /// </summary> | ||
| public bool TraceHeader => Is2012OrNewer; | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for UTF8 collations. This was introduced in SQL | ||
| /// Server 2019, and is only available if a FEATUREEXTACK token of value | ||
| /// <c>0x0A</c> is received. | ||
| /// </summary> | ||
| public bool Utf8 { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for the client to cache DNS resolution responses for | ||
| /// the server. This is only supported by Azure SQL, and is only available | ||
| /// if a FEATUREEXTACK token of value <c>0x0B</c> is received. | ||
| /// </summary> | ||
| public bool DnsCaching { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for Data Classification and specifies the version of | ||
| /// Data Classification which is supported. This was introduced in SQL | ||
| /// Server 2019, and is only available if a FEATUREEXTACK token of value | ||
| /// <c>0x09</c> is received. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This should only be <c>1</c> or <c>2</c>. | ||
| /// </remarks> | ||
| public byte DataClassificationVersion { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates that Global Transactions are available (even if not currently enabled.) | ||
| /// Global Transactions are only supported by Azure SQL, and are only available if a | ||
| /// FEATUREEXTACK token of value <c>0x05</c> is received. | ||
| /// </summary> | ||
| public bool GlobalTransactionsAvailable { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for Global Transactions. This is only supported by | ||
| /// Azure SQL, and is only available if a FEATUREEXTACK token of value | ||
| /// <c>0x05</c> is received. | ||
| /// </summary> | ||
| public bool GlobalTransactionsSupported { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for Enhanced Routing. This is only supported by | ||
| /// Azure SQL, and is only available if a FEATUREEXTACK token of value | ||
| /// <c>0x0F</c> is received. | ||
| /// </summary> | ||
| public bool EnhancedRouting { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for connecting to the current connection's failover | ||
| /// partner with an Application Intent of ReadOnly. This is only supported | ||
| /// by Azure SQL, and is only available if a FEATUREEXTACK token of value | ||
| /// <c>0x08</c> is received, and if bit zero of this token's data is set. | ||
| /// </summary> | ||
| public bool ReadOnlyFailoverPartnerConnection { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for the <c>vector</c> data type, with a backing type | ||
| /// of <c>float32</c>. This was introduced in SQL Server 2022, and is only | ||
| /// available if a FEATUREEXTACK token of value <c>0x0E</c> is received, and | ||
| /// if the version in this token's data is greater than or equal to <c>1</c>. | ||
| /// </summary> | ||
| public bool Float32VectorType { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for the <c>json</c> data type. This was introduced in | ||
| /// SQL Server 2022, and is only available if a FEATUREEXTACK token of value | ||
| /// <c>0x0D</c> is received, and if the version in this token's data is | ||
| /// greater than or equal to <c>1</c>. | ||
| /// </summary> | ||
| public bool JsonType { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates support for column encryption and specifies the version of column | ||
| /// encryption which is supported. This was introduced in SQL Server 2016, and is | ||
| /// only available if a FEATUREEXTACK token of value <c>0x04</c> is received. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This should only be <c>1</c>, <c>2</c> or <c>3</c>. v1 is supported from SQL | ||
| /// Server 2016 upwards, v2 is supported from SQL Server 2019 upwards, v3 is supported | ||
| /// from SQL Server 2022 upwards. | ||
| /// </remarks> | ||
| public byte ColumnEncryptionVersion { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// If column encryption is enabled, the type of enclave reported by the server. This | ||
| /// was introduced in SQL Server 2019, and is only available if a FEATUREEXTACK token | ||
| /// of value <c>0x04</c> is received, and the resultant <see cref="ColumnEncryptionVersion"/> | ||
| /// is <c>2</c> or <c>3</c>. | ||
| /// </summary> | ||
| public string? ColumnEncryptionEnclaveType { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Returns the capability records to unset values. | ||
| /// </summary> | ||
| public void Reset() | ||
| { | ||
| TdsVersion = 0; | ||
| ServerMajorVersion = 0; | ||
| ServerMinorVersion = 0; | ||
| ServerBuildNumber = 0; | ||
|
|
||
| IsAzureSql = false; | ||
| Utf8 = false; | ||
| DnsCaching = false; | ||
| DataClassificationVersion = TdsEnums.DATA_CLASSIFICATION_NOT_ENABLED; | ||
| GlobalTransactionsAvailable = false; | ||
| GlobalTransactionsSupported = false; | ||
| EnhancedRouting = false; | ||
| ReadOnlyFailoverPartnerConnection = false; | ||
| Float32VectorType = false; | ||
| JsonType = false; | ||
| ColumnEncryptionVersion = TdsEnums.TCE_NOT_ENABLED; | ||
| ColumnEncryptionEnclaveType = null; | ||
| } | ||
| } | ||
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.