8000 Merge | Cleanup Pre 2005 Support in TdsParser (#3206) · dotnet/SqlClient@bbbb467 · GitHub
[go: up one dir, main page]

Skip to content

Commit bbbb467

Browse files
benrr101MichelZcheenamalhotra
authored
Merge | Cleanup Pre 2005 Support in TdsParser (#3206)
* Cleanup Pre 2005 Support in TdsParser * Fix some code indentation issues * Fix some code indentation issues * Add back isVersion8 * PR Comments - Removing _is2005 - Removing ENV_CHANGE types that are not supported in TDS >7 --------- Co-authored-by: Michel Zehnder <MichelZ@users.noreply.github.com> Co-authored-by: Cheena Malhotra <13396919+cheenamalhotra@users.noreply.github.com>
1 parent 09d4d38 commit bbbb467

File tree

4 files changed

+214
-576
lines changed

4 files changed

+214
-576
lines changed

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

Lines changed: 16 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,6 @@ internal sealed partial class TdsParser
105105

106106
// Version variables
107107

108-
private bool _is2005 = false; // set to true if speaking to 2005 or later
109-
110108
private bool _is2008 = false;
111109

112110
private bool _is2012 = false;
@@ -931,7 +929,6 @@ private PreLoginHandshakeStatus ConsumePreLoginHandshake(
931929
// Assign default values
932930
marsCapable = _fMARS;
933931
fedAuthRequired = false;
934-
bool is2005OrLater = false;
935932
Debug.Assert(_physicalStateObj._syncOverAsync, "Should not attempt pends in a synchronous call");
936933
TdsOperationStatus result = _physicalStateObj.TryReadNetworkPacket();
937934
if (result != TdsOperationStatus.Done)
@@ -990,13 +987,6 @@ private PreLoginHandshakeStatus ConsumePreLoginHandshake(
990987
byte minorVersion = payload[payloadOffset + 1];
991988
int level = (payload[payloadOffset + 2] << 8) |
992989
payload[payloadOffset + 3];
993-
994-
is2005OrLater = majorVersion >= 9;
995-
if (!is2005OrLater)
996-
{
997-
marsCapable = false; // If pre-2005, MARS not supported.
998-
}
999-
1000990
break;
1001991

1002992
case (int)PreLoginOptions.ENCRYPT:
@@ -1154,7 +1144,7 @@ private PreLoginHandshakeStatus ConsumePreLoginHandshake(
11541144
bool shouldValidateServerCert = (_encryptionOption == EncryptionOptions.ON && !trustServerCert) ||
11551145
(_connHandler._accessTokenInBytes != null && !trustServerCert);
11561146
uint info = (shouldValidateServerCert ? TdsEnums.SNI_SSL_VALIDATE_CERTIFICATE : 0)
1157-
| (is2005OrLater ? TdsEnums.SNI_SSL_USE_SCHANNEL_CACHE : 0);
1147+
| TdsEnums.SNI_SSL_USE_SCHANNEL_CACHE;
11581148

11591149
EnableSsl(info, encrypt, integratedSecurity, serverCert);
11601150
}
@@ -2747,30 +2737,7 @@ private TdsOperationStatus TryProcessEnvChange(int tokenLength, TdsParserStateOb
27472737
}
27482738
break;
27492739

2750-
case TdsEnums.ENV_CHARSET:
2751-
// we copied this behavior directly from luxor - see charset envchange
2752-
// section from sqlctokn.c
2753-
result = TryReadTwoStringFields(env, stateObj);
2754-
if (result != TdsOperationStatus.Done)
2755-
{
2756-
return result;
2757-
}
2758-
if (env._newValue == TdsEnums.DEFAULT_ENGLISH_CODE_PAGE_STRING)
2759-
{
2760-
_defaultCodePage = TdsEnums.DEFAULT_ENGLISH_CODE_PAGE_VALUE;
2761-
_defaultEncoding = System.Text.Encoding.GetEncoding(_defaultCodePage);
2762-
}
2763-
else
2764-
{
2765-
Debug.Assert(env._newValue.Length > TdsEnums.CHARSET_CODE_PAGE_OFFSET, "TdsParser.ProcessEnvChange(): charset value received with length <=10");
2766-
2767-
string stringCodePage = env._newValue.Substring(TdsEnums.CHARSET_CODE_PAGE_OFFSET);
2768-
2769-
_defaultCodePage = int.Parse(stringCodePage, NumberStyles.Integer, CultureInfo.InvariantCulture);
2770-
_defaultEncoding = System.Text.Encoding.GetEncoding(_defaultCodePage);
2771-
}
2772-
2773-
break;
2740+
// TdsEnums.ENV_CHARSET (3) is only supported in TDS <= 7 which is no longer supported
27742741

27752742
case TdsEnums.ENV_PACKETSIZE:
27762743
// take care of packet size right here
@@ -2802,24 +2769,9 @@ private TdsOperationStatus TryProcessEnvChange(int tokenLength, TdsParserStateOb
28022769

28032770
break;
28042771

2805-
case TdsEnums.ENV_LOCALEID:
2806-
// UNDONE: this LCID may be incorrect for OEM code pages on 7.0
2807-
// need a way to get lcid from code page
2808-
result = TryReadTwoStringFields(env, stateObj);
2809-
if (result != TdsOperationStatus.Done)
2810-
{
2811-
return result;
2812-
}
2813-
_defaultLCID = int.Parse(env._newValue, NumberStyles.Integer, CultureInfo.InvariantCulture);
2814-
break;
2772+
// TdsEnums.ENV_LOCALE (5) is only supported in TDS <= 7 which is no longer supported
28152773

2816-
case TdsEnums.ENV_COMPFLAGS:
2817-
result = TryReadTwoStringFields(env, stateObj);
2818-
if (result != TdsOperationStatus.Done)
2819-
{
2820-
return result;
2821-
}
2822-
break;
2774+
// TdsEnums.ENV_COMPFLAGS (6) is only supported in TDS <= 7 which is no longer supported
28232775

28242776
case TdsEnums.ENV_COLLATION:
28252777
Debug.Assert(env._newLength == 5 || env._newLength == 0, "Improper length in new collation!");
@@ -3829,7 +3781,6 @@ private TdsOperationStatus TryProcessLoginAck(TdsParserStateObject stateObj, out
38293781
{
38303782
throw SQL.InvalidTDSVersion();
38313783
}
3832-
_is2005 = true;
38333784
break;
38343785
case TdsEnums.SQL2008_MAJOR << 24 | TdsEnums.SQL2008_MINOR:
38353786
if (increment != TdsEnums.SQL2008_INCREMENT)
@@ -3857,7 +3808,6 @@ private TdsOperationStatus TryProcessLoginAck(TdsParserStateObject stateObj, out
38573808
}
38583809
_is2012 |= _is2022;
38593810
_is2008 |= _is2012;
3860-
_is2005 |= _is2008;
38613811

38623812
stateObj._outBytesUsed = stateObj._outputHeaderLen;
38633813
byte len;
@@ -5178,7 +5128,7 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
51785128
}
51795129

51805130
// read the collation for 7.x servers
5181-
if (col.metaType.IsCharType && (tdsType != TdsEnums.SQLXMLTYPE) && ((tdsType != TdsEnums.SQLJSON)))
5131+
if (col.metaType.IsCharType && (tdsType != TdsEnums.SQLXMLTYPE) && (tdsType != TdsEnums.SQLJSON))
51825132
{
51835133
result = TryProcessCollation(stateObj, out col.collation);
51845134
if (result != TdsOperationStatus.Done)
@@ -9431,8 +9381,7 @@ internal Task TdsExecuteRPC(SqlCommand cmd, IList<_SqlRPC> rpcArray, int timeout
94319381
continue;
94329382
}
94339383

9434-
if ((!_is2005 && !mt.Is80Supported) ||
9435-
(!_is2008 && !mt.Is90Supported))
9384+
if (!_is2008 && !mt.Is90Supported)
94369385
{
94379386
throw ADP.VersionDoesNotSupportDataType(mt.TypeName);
94389387
}
@@ -9797,8 +9746,6 @@ private Task TDSExecuteRPCAddParameter(TdsParserStateObject stateObj, SqlParamet
97979746
}
97989747
else if (mt.SqlDbType == SqlDbType.Udt)
97999748
{
9800-
Debug.Assert(_is2005, "Invalid DataType UDT for non-2005 or later server!");
9801-
98029749
int maxSupportedSize = Is2008OrNewer ? int.MaxValue : short.MaxValue;
98039750
byte[] udtVal = null;
98049751
SqlServer.Server.Format format = SqlServer.Server.Format.Native;
@@ -9891,7 +9838,7 @@ private Task TDSExecuteRPCAddParameter(TdsParserStateObject stateObj, SqlParamet
98919838
else if ((!mt.IsVarTime) && (mt.SqlDbType != SqlDbType.Date))
98929839
{ // Time, Date, DateTime2, DateTimeoffset do not have the size written out
98939840
maxsize = (size > actualSize) ? size : actualSize;
9894-
if (maxsize == 0 && _is2005)
9841+
if (maxsize == 0)
98959842
{
98969843
// 2005 doesn't like 0 as MaxSize. Change it to 2 for unicode types (SQL9 - 682322)
98979844
if (mt.IsNCharType)
@@ -11224,8 +11171,6 @@ private int GetNotificationHeaderSize(SqlNotificationRequest notificationRequest
1122411171
// Write query notificaiton header data, not including the notificaiton header length
1122511172
private void WriteQueryNotificationHeaderData(SqlNotificationRequest notificationRequest, TdsParserStateObject stateObj)
1122611173
{
11227-
Debug.Assert(_is2005, "WriteQueryNotificationHeaderData called on a non-2005 server");
11228-
1122911174
// We may need to update the notification header length if the header is changed in the future
1123011175

1123111176
Debug.Assert(notificationRequest != null, "notificationRequest is null");
@@ -13284,16 +13229,15 @@ private TdsOperationStatus TryProcessUDTMetaData(SqlMetaDataPriv metaData, TdsPa
1328413229
+ " _connHandler = {14}\n\t"
1328513230
+ " _fMARS = {15}\n\t"
1328613231
+ " _sessionPool = {16}\n\t"
13287-
+ " _is2005 = {17}\n\t"
13288-
+ " _sniSpnBuffer = {18}\n\t"
13289-
+ " _errors = {19}\n\t"
13290-
+ " _warnings = {20}\n\t"
13291-
+ " _attentionErrors = {21}\n\t"
13292-
+ " _attentionWarnings = {22}\n\t"
13293-
+ " _statistics = {23}\n\t"
13294-
+ " _statisticsIsInTransaction = {24}\n\t"
13295-
+ " _fPreserveTransaction = {25}"
13296-
+ " _fParallel = {26}"
13232+
+ " _sniSpnBuffer = {17}\n\t"
13233+
+ " _errors = {18}\n\t"
13234+
+ " _warnings = {19}\n\t"
13235+
+ " _attentionErrors = {20}\n\t"
13236+
+ " _attentionWarnings = {21}\n\t"
13237+
+ " _statistics = {22}\n\t"
13238+
+ " _statisticsIsInTransaction = {23}\n\t"
13239+
+ " _fPreserveTransaction = {24}"
13240+
+ " _fParallel = {25}"
1329713241
;
1329813242
internal string TraceString()
1329913243
{
@@ -13316,7 +13260,6 @@ internal string TraceString()
1331613260
_connHandler == null ? "(null)" : _connHandler.ObjectID.ToString((IFormatProvider)null),
1331713261
_fMARS ? bool.TrueString : bool.FalseString,
1331813262
_sessionPool == null ? "(null)" : _sessionPool.TraceString(),
13319-
_is2005 ? bool.TrueString : bool.FalseString,
1332013263
_serverSpn == null ? "(null)" : _serverSpn.Length.ToString((IFormatProvider)null),
1332113264
_physicalStateObj != null ? "(null)" : _physicalStateObj.ErrorCount.ToString((IFormatProvider)null),
1332213265
_physicalStateObj != null ? "(null)" : _physicalStateObj.WarningCount.ToString((IFormatProvider)null),

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

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -714,14 +714,8 @@ override protected internal bool IsNonPoolableTransactionRoot
714714
return IsTransactionRoot && (!Is2008OrNewer || Pool == null);
715715
}
716716
}
717-
718-
override internal bool Is2000
719-
{
720-
get
721-
{
722-
return _loginAck.isVersion8;
723-
}
724-
}
717+
718+
override internal bool Is2000 => true;
725719

726720
override internal bool Is2005OrNewer
727721
{

0 commit comments

Comments
 (0)
0