diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/ServerInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/ServerInfo.cs
index 49e6167b49..051aff00a2 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/ServerInfo.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/ServerInfo.cs
@@ -59,23 +59,23 @@ private ServerInfo(SqlConnectionOptions userOptions, string serverName)
///
internal ServerInfo(
SqlConnectionOptions userOptions,
- RoutingInfo routing,
+ TdsEnvChangeRoutingInfo routingInfo,
string preRoutingServerName,
string serverSpn)
{
- Debug.Assert(userOptions != null && routing != null);
- Debug.Assert(routing.ServerName != null, "server name should never be null");
+ Debug.Assert(userOptions != null && routingInfo != null);
+ Debug.Assert(routingInfo.ServerName != null, "server name should never be null");
// Ensure user server name is not null
// NOTE: string.Format should be used here to ensure invariant culture is used for port number.
- UserServerName = routing == null || routing.ServerName == null
+ UserServerName = routingInfo == null || routingInfo.ServerName == null
? string.Empty
- : string.Format(CultureInfo.InvariantCulture, "{0},{1}", routing.ServerName, routing.Port);
+ : string.Format(CultureInfo.InvariantCulture, "{0},{1}", routingInfo.ServerName, routingInfo.Port);
PreRoutingServerName = preRoutingServerName;
UserProtocol = TdsEnums.TCP;
SetDerivedNames(UserProtocol, UserServerName);
- ResolvedDatabaseName = routing?.DatabaseName ?? userOptions.InitialCatalog;
+ ResolvedDatabaseName = routingInfo?.DatabaseName ?? userOptions.InitialCatalog;
ServerSPN = serverSpn;
}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs
index c4dd11d07a..93c06da3aa 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Connection/SqlConnectionInternal.cs
@@ -730,7 +730,7 @@ internal SqlConnectionPoolGroupProviderInfo PoolGroupProviderInfo
internal string RoutingDestination { get; private set; }
- internal RoutingInfo RoutingInfo { get; private set; } = null;
+ internal TdsEnvChangeRoutingInfo RoutingInfo { get; private set; } = null;
internal int ServerProcessId
{
@@ -1841,8 +1841,8 @@ internal void OnFeatureExtAck(int featureId, byte[] data)
/// Generates (if appropriate) and sends a Federated Authentication Access token to the
/// server, using the Federated Authentication Info.
///
- /// Federated Authentication Info.
- internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
+ /// Federated Authentication Info.
+ internal void OnFedAuthInfo(TdsFedAuthInfoToken fedAuthInfoToken)
{
// @TODO: Seriously, put this into a hash set or give it a helper or something! We're gonna forget one in *one* spot and cause a big ol bug someday.
Debug.Assert((ConnectionOptions._hasUserIdKeyword && ConnectionOptions._hasPasswordKeyword)
@@ -1856,7 +1856,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
|| ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryWorkloadIdentity
|| (ConnectionOptions.Authentication == SqlAuthenticationMethod.ActiveDirectoryIntegrated && _fedAuthRequired),
"Credentials aren't provided for calling MSAL");
- Debug.Assert(fedAuthInfo != null, "info should not be null.");
+ Debug.Assert(fedAuthInfoToken != null, "info should not be null.");
Debug.Assert(_dbConnectionPoolAuthenticationContextKey == null,
"_dbConnectionPoolAuthenticationContextKey should be null.");
SqlClientEventSource.Log.TryTraceEvent(" {0}, Generating federated authentication token", ObjectID);
@@ -1877,8 +1877,8 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
// Construct the dbAuthenticationContextKey with information from FedAuthInfo and
// store for later use, when inserting in to the token cache.
_dbConnectionPoolAuthenticationContextKey = new DbConnectionPoolAuthenticationContextKey(
- fedAuthInfo.StsUrl,
- fedAuthInfo.Spn);
+ fedAuthInfoToken.StsUrl,
+ fedAuthInfoToken.Spn);
// Try to retrieve the authentication context from the pool, if one does exist for
// this key.
@@ -1921,7 +1921,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
else if (_forceExpiryLocked)
{
attemptRefreshTokenLocked = TryGetFedAuthTokenLocked(
- fedAuthInfo,
+ fedAuthInfoToken,
dbConnectionPoolAuthenticationContext,
out _fedAuthToken);
}
@@ -1948,7 +1948,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
// context before trying to update. If the lock could not be obtained, it
// will return false, without attempting to fetch a new token.
attemptRefreshTokenLocked = TryGetFedAuthTokenLocked(
- fedAuthInfo,
+ fedAuthInfoToken,
dbConnectionPoolAuthenticationContext,
out _fedAuthToken);
@@ -1986,7 +1986,7 @@ internal void OnFedAuthInfo(SqlFedAuthInfo fedAuthInfo)
if (dbConnectionPoolAuthenticationContext == null || attemptRefreshTokenUnLocked)
{
// Get the Federated Authentication Token.
- _fedAuthToken = GetFedAuthToken(fedAuthInfo);
+ _fedAuthToken = GetFedAuthToken(fedAuthInfoToken);
Debug.Assert(_fedAuthToken != null, "_fedAuthToken should not be null.");
if (_dbConnectionPool != null)
@@ -3015,8 +3015,8 @@ private void FailoverPermissionDemand() =>
///
/// Get the Federated Authentication Token.
///
- /// Information obtained from server as Federated Authentication Info.
- private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
+ /// Information obtained from server as Federated Authentication Info.
+ private SqlFedAuthToken GetFedAuthToken(TdsFedAuthInfoToken fedAuthInfoToken)
{
// Number of milliseconds to sleep for the initial back off, if a
// retry period is not specified by the provider.
@@ -3042,8 +3042,8 @@ private SqlFedAuthToken GetFedAuthToken(SqlFedAuthInfo fedAuthInfo)
{
var authParamsBuilder = new SqlAuthenticationParametersBuilder(
authenticationMethod: ConnectionOptions.Authentication,
- resource: fedAuthInfo.Spn,
- authority: fedAuthInfo.StsUrl,
+ resource: fedAuthInfoToken.Spn,
+ authority: fedAuthInfoToken.StsUrl,
serverName: ConnectionOptions.DataSource,
databaseName: ConnectionOptions.InitialCatalog)
.WithConnectionId(_clientConnectionId)
@@ -4469,7 +4469,7 @@ internal static bool ShouldDisableTnir(
/// Tries to acquire a lock on the authentication context. If successful in acquiring the
/// lock, gets a new token and assigns it in the out parameter. Else returns false.
///
- /// Federated Authentication Info
+ /// Federated Authentication Info
///
/// Authentication Context cached in the connection pool.
///
@@ -4477,12 +4477,12 @@ internal static bool ShouldDisableTnir(
/// Out parameter, carrying the token if we acquired a lock and got the token.
///
private bool TryGetFedAuthTokenLocked(
- SqlFedAuthInfo fedAuthInfo,
+ TdsFedAuthInfoToken fedAuthInfoToken,
DbConnectionPoolAuthenticationContext dbConnectionPoolAuthenticationContext,
out SqlFedAuthToken fedAuthToken)
{
- Debug.Assert(fedAuthInfo != null, "fedAuthInfo should not be null.");
+ Debug.Assert(fedAuthInfoToken != null, "fedAuthInfo should not be null.");
Debug.Assert(dbConnectionPoolAuthenticationContext != null,
"dbConnectionPoolAuthenticationContext should not be null.");
@@ -4526,7 +4526,7 @@ private bool TryGetFedAuthTokenLocked(
if (authenticationContextLocked)
{
// Get the Federated Authentication Token.
- fedAuthToken = GetFedAuthToken(fedAuthInfo);
+ fedAuthToken = GetFedAuthToken(fedAuthInfoToken);
Debug.Assert(fedAuthToken != null, "fedAuthToken should not be null.");
}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/TdsParser.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/TdsParser.cs
index 9c5febc828..4707cb9086 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/TdsParser.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/TdsParser.cs
@@ -2586,7 +2586,7 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
{
if (dataStream != null)
{
- _SqlMetaDataSet metaDataSet;
+ TdsColumnMetadataToken metaDataSet;
result = TryProcessColInfo(dataStream.MetaData, dataStream, stateObj, out metaDataSet);
if (result != TdsOperationStatus.Done)
{
@@ -2777,14 +2777,14 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
case TdsEnums.SQLFEDAUTHINFO:
{
_connHandler._federatedAuthenticationInfoReceived = true;
- SqlFedAuthInfo info;
+ TdsFedAuthInfoToken infoToken;
- result = TryProcessFedAuthInfo(stateObj, tokenLength, out info);
+ result = TryProcessFedAuthInfo(stateObj, tokenLength, out infoToken);
if (result != TdsOperationStatus.Done)
{
return result;
}
- _connHandler.OnFedAuthInfo(info);
+ _connHandler.OnFedAuthInfo(infoToken);
break;
}
case TdsEnums.SQLSESSIONSTATE:
@@ -2800,7 +2800,7 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
{
if (tokenLength != TdsEnums.VARNULL)
{
- _SqlMetaDataSet metadata;
+ TdsColumnMetadataToken metadata;
result = TryProcessMetaData(tokenLength, stateObj, out metadata,
cmdHandler?.ColumnEncryptionSetting ?? SqlCommandColumnEncryptionSetting.UseConnectionSetting);
if (result != TdsOperationStatus.Done)
@@ -2935,16 +2935,19 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
break;
case TdsEnums.SQLRETURNVALUE:
{
- SqlReturnValue returnValue;
- result = TryProcessReturnValue(tokenLength, stateObj, out returnValue,
- cmdHandler?.ColumnEncryptionSetting ?? SqlCommandColumnEncryptionSetting.UseConnectionSetting);
+ result = TryProcessReturnValue(
+ tokenLength,
+ stateObj,
+ out TdsReturnValueToken returnValueToken,
+ cmdHandler?.ColumnEncryptionSetting ?? SqlCommandColumnEncryptionSetting.UseConnectionSetting);
+
if (result != TdsOperationStatus.Done)
{
return result;
}
if (cmdHandler != null)
{
- cmdHandler.OnReturnValue(returnValue, stateObj);
+ cmdHandler.OnReturnValue(returnValueToken, stateObj);
}
break;
}
@@ -2962,7 +2965,7 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
{
if (dataStream != null)
{
- MultiPartTableName[] tableNames;
+ TdsTableName[] tableNames;
result = TryProcessTableName(tokenLength, stateObj, out tableNames);
if (result != TdsOperationStatus.Done)
{
@@ -2998,17 +3001,17 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
if (stateObj._cleanupAltMetaDataSetArray == null)
{
// create object on demand (lazy creation)
- stateObj._cleanupAltMetaDataSetArray = new _SqlMetaDataSetCollection();
+ stateObj._cleanupAltMetaDataSetArray = new TdsAltMetadataCollection();
}
- _SqlMetaDataSet cleanupAltMetaDataSet;
+ TdsColumnMetadataToken cleanupAltMetaDataSet;
result = TryProcessAltMetaData(tokenLength, stateObj, out cleanupAltMetaDataSet);
if (result != TdsOperationStatus.Done)
{
return result;
}
- stateObj._cleanupAltMetaDataSetArray.SetAltMetaData(cleanupAltMetaDataSet);
+ stateObj._cleanupAltMetaDataSetArray.SetAltMetadata(cleanupAltMetaDataSet);
if (dataStream != null)
{
byte metadataConsumedByte;
@@ -3046,7 +3049,7 @@ internal TdsOperationStatus TryRun(RunBehavior runBehavior, SqlCommand cmdHandle
return result;
}
- result = TrySkipRow(stateObj._cleanupAltMetaDataSetArray.GetAltMetaData(altRowId), stateObj);
+ result = TrySkipRow(stateObj._cleanupAltMetaDataSetArray.GetAltMetadata(altRowId), stateObj);
if (result != TdsOperationStatus.Done)
{
// skip altRow
@@ -3408,7 +3411,7 @@ private TdsOperationStatus TryProcessEnvChange(int tokenLength, TdsParserStateOb
{
return result;
}
- env._newRoutingInfo = new RoutingInfo(protocol, port, serverName);
+ env._newRoutingInfo = new TdsEnvChangeRoutingInfo(protocol, port, serverName);
ushort oldLength;
result = stateObj.TryReadUInt16(out oldLength);
if (result != TdsOperationStatus.Done)
@@ -3516,7 +3519,7 @@ private TdsOperationStatus TryProcessEnhancedRoutingToken(SqlEnvChange env, TdsP
return result;
}
- env._newRoutingInfo = new RoutingInfo(protocol, port, serverName, databaseName);
+ env._newRoutingInfo = new TdsEnvChangeRoutingInfo(protocol, port, serverName, databaseName);
ushort oldLength;
result = stateObj.TryReadUInt16(out oldLength);
@@ -4390,9 +4393,9 @@ private TdsOperationStatus TryProcessLoginAck(TdsParserStateObject stateObj)
return TdsOperationStatus.Done;
}
- private TdsOperationStatus TryProcessFedAuthInfo(TdsParserStateObject stateObj, int tokenLen, out SqlFedAuthInfo sqlFedAuthInfo)
+ private TdsOperationStatus TryProcessFedAuthInfo(TdsParserStateObject stateObj, int tokenLen, out TdsFedAuthInfoToken tdsFedAuthInfoToken)
{
- sqlFedAuthInfo = null;
+ tdsFedAuthInfoToken = null;
string spn = null;
string stsUrl = null;
@@ -4521,8 +4524,8 @@ private TdsOperationStatus TryProcessFedAuthInfo(TdsParserStateObject stateObj,
throw SQL.ParsingError(ParsingErrorState.FedAuthInfoDoesNotContainStsurlAndSpn);
}
- sqlFedAuthInfo = new(spn, stsUrl);
- SqlClientEventSource.Log.TryTraceEvent(" Processed FEDAUTHINFO token stream: {0}", sqlFedAuthInfo);
+ tdsFedAuthInfoToken = new(spn, stsUrl);
+ SqlClientEventSource.Log.TryTraceEvent(" Processed FEDAUTHINFO token stream: {0}", tdsFedAuthInfoToken);
return TdsOperationStatus.Done;
}
@@ -4621,11 +4624,11 @@ internal TdsOperationStatus TryProcessError(byte token, TdsParserStateObject sta
internal TdsOperationStatus TryProcessReturnValue(int length,
TdsParserStateObject stateObj,
- out SqlReturnValue returnValue,
+ out TdsReturnValueToken returnValueToken,
SqlCommandColumnEncryptionSetting columnEncryptionSetting)
{
- returnValue = null;
- SqlReturnValue rec = new SqlReturnValue();
+ returnValueToken = null;
+ TdsReturnValueToken rec = new TdsReturnValueToken();
rec.length = length; // In 2005 this length is -1
TdsOperationStatus result = stateObj.TryReadUInt16(out _);
if (result != TdsOperationStatus.Done)
@@ -4684,7 +4687,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
// Check if the column is encrypted.
if (IsColumnEncryptionSupported)
{
- rec.isEncrypted = (TdsEnums.IsEncrypted == (flags & TdsEnums.IsEncrypted));
+ rec.IsEncrypted = (TdsEnums.IsEncrypted == (flags & TdsEnums.IsEncrypted));
}
// read the type
@@ -4720,19 +4723,19 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
}
}
- rec.metaType = MetaType.GetSqlDataType(tdsType, userType, tdsLen);
- rec.type = rec.metaType.SqlDbType;
+ rec.MetaType = MetaType.GetSqlDataType(tdsType, userType, tdsLen);
+ rec.DbType = rec.MetaType.SqlDbType;
// always use the nullable type for parameters if 2005 or later
// older servers sometimes send fixed length return values
- rec.tdsType = rec.metaType.NullableType;
+ rec.TdsType = rec.MetaType.NullableType;
rec.IsNullable = true;
if (tdsLen == TdsEnums.SQL_USHORTVARMAXLEN)
{
- rec.metaType = MetaType.GetMaxMetaTypeFromMetaType(rec.metaType);
+ rec.MetaType = MetaType.GetMaxMetaTypeFromMetaType(rec.MetaType);
}
- if (rec.type == SqlDbType.Decimal)
+ if (rec.DbType == SqlDbType.Decimal)
{
result = stateObj.TryReadByte(out rec.precision);
if (result != TdsOperationStatus.Done)
@@ -4746,7 +4749,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
}
}
- if (rec.metaType.IsVarTime)
+ if (rec.MetaType.IsVarTime)
{
result = stateObj.TryReadByte(out rec.scale);
if (result != TdsOperationStatus.Done)
@@ -4757,7 +4760,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
if (tdsType == TdsEnums.SQLUDT)
{
- result = TryProcessUDTMetaData((SqlMetaDataPriv)rec, stateObj);
+ result = TryProcessUDTMetaData((TdsTypeInfo)rec, stateObj);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -4773,7 +4776,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
}
}
- if (rec.type == SqlDbType.Xml)
+ if (rec.DbType == SqlDbType.Xml)
{
// Read schema info
byte schemapresent;
@@ -4790,13 +4793,13 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
{
return result;
}
- if (rec.xmlSchemaCollection is null)
+ if (rec.XmlSchemaCollection is null)
{
- rec.xmlSchemaCollection = new SqlMetaDataXmlSchemaCollection();
+ rec.XmlSchemaCollection = new SqlMetaDataXmlSchemaCollection();
}
if (len != 0)
{
- result = stateObj.TryReadString(len, out rec.xmlSchemaCollection.Database);
+ result = stateObj.TryReadString(len, out rec.XmlSchemaCollection.Database);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -4810,7 +4813,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
}
if (len != 0)
{
- result = stateObj.TryReadString(len, out rec.xmlSchemaCollection.OwningSchema);
+ result = stateObj.TryReadString(len, out rec.XmlSchemaCollection.OwningSchema);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -4826,7 +4829,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
if (slen != 0)
{
- result = stateObj.TryReadString(slen, out rec.xmlSchemaCollection.Name);
+ result = stateObj.TryReadString(slen, out rec.XmlSchemaCollection.Name);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -4834,7 +4837,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
}
}
}
- else if (rec.metaType.IsCharType && rec.metaType.SqlDbType != SqlDbTypeExtensions.Json)
+ else if (rec.MetaType.IsCharType && rec.MetaType.SqlDbType != SqlDbTypeExtensions.Json)
{
// read the collation for 8.x servers
result = TryProcessCollation(stateObj, out rec.collation);
@@ -4845,7 +4848,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
if (rec.collation.IsUTF8)
{ // UTF8 collation
- rec.encoding = s_utf8EncodingWithoutBom;
+ rec.Encoding = s_utf8EncodingWithoutBom;
}
else
{
@@ -4854,19 +4857,19 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
// If the column lcid is the same as the default, use the default encoder
if (codePage == _defaultCodePage)
{
- rec.codePage = _defaultCodePage;
- rec.encoding = _defaultEncoding;
+ rec.CodePage = _defaultCodePage;
+ rec.Encoding = _defaultEncoding;
}
else
{
- rec.codePage = codePage;
- rec.encoding = System.Text.Encoding.GetEncoding(rec.codePage);
+ rec.CodePage = codePage;
+ rec.Encoding = System.Text.Encoding.GetEncoding(rec.CodePage);
}
}
}
// For encrypted parameters, read the unencrypted type and encryption information.
- if (IsColumnEncryptionSupported && rec.isEncrypted)
+ if (IsColumnEncryptionSupported && rec.IsEncrypted)
{
result = TryProcessTceCryptoMetadata(stateObj, rec, cipherTable: null, columnEncryptionSetting: columnEncryptionSetting, isReturnValue: true);
if (result != TdsOperationStatus.Done)
@@ -4887,7 +4890,7 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
// always read as sql types
int intlen;
- if (rec.metaType.IsPlp)
+ if (rec.MetaType.IsPlp)
{
intlen = int.MaxValue; // If plp data, read it all
}
@@ -4900,32 +4903,32 @@ internal TdsOperationStatus TryProcessReturnValue(int length,
intlen = (int)valLen;
}
- if (rec.type == SqlDbTypeExtensions.Vector)
+ if (rec.DbType == SqlDbTypeExtensions.Vector)
{
rec.length = tdsLen;
}
if (isNull)
{
- GetNullSqlValue(rec.value, rec, SqlCommandColumnEncryptionSetting.Disabled, _connHandler);
+ GetNullSqlValue(rec.Value, rec, SqlCommandColumnEncryptionSetting.Disabled, _connHandler);
}
else
{
// We should never do any decryption here, so pass disabled as the command encryption override.
// We only read the binary value and decryption will be performed by OnReturnValue().
- result = TryReadSqlValue(rec.value, rec, intlen, stateObj, SqlCommandColumnEncryptionSetting.Disabled, columnName: null /*Not used*/);
+ result = TryReadSqlValue(rec.Value, rec, intlen, stateObj, SqlCommandColumnEncryptionSetting.Disabled, columnName: null /*Not used*/);
if (result != TdsOperationStatus.Done)
{
return result;
}
}
- returnValue = rec;
+ returnValueToken = rec;
return TdsOperationStatus.Done;
}
internal TdsOperationStatus TryProcessTceCryptoMetadata(TdsParserStateObject stateObj,
- SqlMetaDataPriv col,
+ TdsTypeInfo col,
SqlTceCipherInfoTable cipherTable,
SqlCommandColumnEncryptionSetting columnEncryptionSetting,
bool isReturnValue)
@@ -4962,8 +4965,8 @@ internal TdsOperationStatus TryProcessTceCryptoMetadata(TdsParserStateObject sta
}
// Read the base TypeInfo
- col.baseTI = new SqlMetaDataPriv();
- result = TryProcessTypeInfo(stateObj, col.baseTI, userType);
+ col.BaseTypeInfo = new TdsTypeInfo();
+ result = TryProcessTypeInfo(stateObj, col.BaseTypeInfo, userType);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -5011,7 +5014,7 @@ internal TdsOperationStatus TryProcessTceCryptoMetadata(TdsParserStateObject sta
return result;
}
- Debug.Assert(col.cipherMD == null, "col.cipherMD should be null in TryProcessTceCryptoMetadata.");
+ Debug.Assert(col.CipherMetadata == null, "col.cipherMD should be null in TryProcessTceCryptoMetadata.");
// Check if TCE is enable and if it is set the crypto MD for the column.
// TCE is enabled if the command is set to enabled or to resultset only and this is not a return value
@@ -5022,7 +5025,7 @@ internal TdsOperationStatus TryProcessTceCryptoMetadata(TdsParserStateObject sta
_connHandler != null && _connHandler.ConnectionOptions != null &&
_connHandler.ConnectionOptions.ColumnEncryptionSetting == SqlConnectionColumnEncryptionSetting.Enabled))
{
- col.cipherMD = new SqlCipherMetadata(cipherTable != null ? (SqlTceCipherInfoEntry)cipherTable[index] : null,
+ col.CipherMetadata = new SqlCipherMetadata(cipherTable != null ? (SqlTceCipherInfoEntry)cipherTable[index] : null,
index,
cipherAlgorithmId: cipherAlgorithmId,
cipherAlgorithmName: cipherAlgorithmName,
@@ -5032,7 +5035,7 @@ internal TdsOperationStatus TryProcessTceCryptoMetadata(TdsParserStateObject sta
else
{
// If TCE is disabled mark the MD as not encrypted.
- col.isEncrypted = false;
+ col.IsEncrypted = false;
}
return TdsOperationStatus.Done;
@@ -5102,7 +5105,7 @@ internal void DrainData(TdsParserStateObject stateObj)
SqlDataReader.SharedState sharedState = stateObj._readerState;
if (sharedState != null && sharedState._dataReady)
{
- _SqlMetaDataSet metadata = stateObj._cleanupMetaData;
+ TdsColumnMetadataToken metadata = stateObj._cleanupMetaData;
TdsOperationStatus result;
if (stateObj._partialHeaderBytesRead > 0)
{
@@ -5126,7 +5129,7 @@ internal void DrainData(TdsParserStateObject stateObj)
// iia. if we still have bytes left from a partially read column, skip
if (sharedState._nextColumnDataToRead < sharedState._nextColumnHeaderToRead)
{
- if ((sharedState._nextColumnHeaderToRead > 0) && (metadata[sharedState._nextColumnHeaderToRead - 1].metaType.IsPlp))
+ if ((sharedState._nextColumnHeaderToRead > 0) && (metadata[sharedState._nextColumnHeaderToRead - 1].MetaType.IsPlp))
{
if (stateObj._longlen != 0)
{
@@ -5182,13 +5185,13 @@ internal void ThrowUnsupportedCollationEncountered(TdsParserStateObject stateObj
ThrowExceptionAndWarning(stateObj);
}
- internal TdsOperationStatus TryProcessAltMetaData(int cColumns, TdsParserStateObject stateObj, out _SqlMetaDataSet metaData)
+ internal TdsOperationStatus TryProcessAltMetaData(int cColumns, TdsParserStateObject stateObj, out TdsColumnMetadataToken metaData)
{
Debug.Assert(cColumns > 0, "should have at least 1 column in altMetaData!");
metaData = null;
- _SqlMetaDataSet altMetaDataSet = new _SqlMetaDataSet(cColumns, null);
+ TdsColumnMetadataToken altMetaDataSet = new TdsColumnMetadataToken(cColumns, null);
TdsOperationStatus result = stateObj.TryReadUInt16(out altMetaDataSet.id);
if (result != TdsOperationStatus.Done)
@@ -5217,7 +5220,7 @@ internal TdsOperationStatus TryProcessAltMetaData(int cColumns, TdsParserStateOb
for (int i = 0; i < cColumns; i++)
{
// internal meta data class
- _SqlMetaData col = altMetaDataSet[i];
+ TdsColumnMetadata col = altMetaDataSet[i];
result = stateObj.TryReadByte(out col.op);
if (result != TdsOperationStatus.Done)
@@ -5441,7 +5444,7 @@ internal TdsOperationStatus TryProcessCipherInfoTable(TdsParserStateObject state
return TdsOperationStatus.Done;
}
- internal TdsOperationStatus TryProcessMetaData(int cColumns, TdsParserStateObject stateObj, out _SqlMetaDataSet metaData, SqlCommandColumnEncryptionSetting columnEncryptionSetting)
+ internal TdsOperationStatus TryProcessMetaData(int cColumns, TdsParserStateObject stateObj, out TdsColumnMetadataToken metaData, SqlCommandColumnEncryptionSetting columnEncryptionSetting)
{
Debug.Assert(cColumns > 0, "should have at least 1 column in metadata!");
@@ -5459,7 +5462,7 @@ internal TdsOperationStatus TryProcessMetaData(int cColumns, TdsParserStateObjec
}
// Read the ColumnData fields
- _SqlMetaDataSet newMetaData = new _SqlMetaDataSet(cColumns, cipherTable);
+ TdsColumnMetadataToken newMetaData = new TdsColumnMetadataToken(cColumns, cipherTable);
for (int i = 0; i < cColumns; i++)
{
result = TryCommonProcessMetaData(stateObj, newMetaData[i], cipherTable, fColMD: true, columnEncryptionSetting: columnEncryptionSetting);
@@ -5477,7 +5480,7 @@ internal TdsOperationStatus TryProcessMetaData(int cColumns, TdsParserStateObjec
private bool IsVarTimeTds(byte tdsType) => tdsType == TdsEnums.SQLTIME || tdsType == TdsEnums.SQLDATETIME2 || tdsType == TdsEnums.SQLDATETIMEOFFSET;
- private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, SqlMetaDataPriv col, UInt32 userType)
+ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, TdsTypeInfo col, UInt32 userType)
{
byte byteLen;
byte tdsType;
@@ -5508,9 +5511,9 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
}
}
- col.metaType = MetaType.GetSqlDataType(tdsType, userType, col.length);
- col.type = col.metaType.SqlDbType;
- col.tdsType = (col.IsNullable ? col.metaType.NullableType : col.metaType.TDSType);
+ col.MetaType = MetaType.GetSqlDataType(tdsType, userType, col.length);
+ col.DbType = col.MetaType.SqlDbType;
+ col.TdsType = (col.IsNullable ? col.MetaType.NullableType : col.MetaType.TDSType);
if (TdsEnums.SQLUDT == tdsType)
{
@@ -5529,8 +5532,8 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
tdsType == TdsEnums.SQLNVARCHAR ||
tdsType == TdsEnums.SQLUDT,
"Invalid streaming datatype");
- col.metaType = MetaType.GetMaxMetaTypeFromMetaType(col.metaType);
- Debug.Assert(col.metaType.IsLong, "Max datatype not IsLong");
+ col.MetaType = MetaType.GetMaxMetaTypeFromMetaType(col.MetaType);
+ Debug.Assert(col.MetaType.IsLong, "Max datatype not IsLong");
col.length = int.MaxValue;
if (tdsType == TdsEnums.SQLXMLTYPE)
{
@@ -5548,13 +5551,13 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
{
return result;
}
- if (col.xmlSchemaCollection is null)
+ if (col.XmlSchemaCollection is null)
{
- col.xmlSchemaCollection = new SqlMetaDataXmlSchemaCollection();
+ col.XmlSchemaCollection = new SqlMetaDataXmlSchemaCollection();
}
if (byteLen != 0)
{
- result = stateObj.TryReadString(byteLen, out col.xmlSchemaCollection.Database);
+ result = stateObj.TryReadString(byteLen, out col.XmlSchemaCollection.Database);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -5568,7 +5571,7 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
}
if (byteLen != 0)
{
- result = stateObj.TryReadString(byteLen, out col.xmlSchemaCollection.OwningSchema);
+ result = stateObj.TryReadString(byteLen, out col.XmlSchemaCollection.OwningSchema);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -5583,7 +5586,7 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
}
if (byteLen != 0)
{
- result = stateObj.TryReadString(shortLen, out col.xmlSchemaCollection.Name);
+ result = stateObj.TryReadString(shortLen, out col.XmlSchemaCollection.Name);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -5593,7 +5596,7 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
}
}
- if (col.type == SqlDbType.Decimal)
+ if (col.DbType == SqlDbType.Decimal)
{
result = stateObj.TryReadByte(out col.precision);
if (result != TdsOperationStatus.Done)
@@ -5607,7 +5610,7 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
}
}
- if (col.metaType.IsVarTime)
+ if (col.MetaType.IsVarTime)
{
result = stateObj.TryReadByte(out col.scale);
if (result != TdsOperationStatus.Done)
@@ -5619,7 +5622,7 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
// calculate actual column length here
// TODO: variable-length calculation needs to be encapsulated better
- switch (col.metaType.SqlDbType)
+ switch (col.MetaType.SqlDbType)
{
case SqlDbType.Time:
col.length = MetaType.GetTimeSizeFromScale(col.scale);
@@ -5640,7 +5643,7 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
}
// read the collation for 7.x servers
- if (col.metaType.IsCharType && (tdsType != TdsEnums.SQLXMLTYPE) && (tdsType != TdsEnums.SQLJSON))
+ if (col.MetaType.IsCharType && (tdsType != TdsEnums.SQLXMLTYPE) && (tdsType != TdsEnums.SQLJSON))
{
result = TryProcessCollation(stateObj, out col.collation);
if (result != TdsOperationStatus.Done)
@@ -5650,7 +5653,7 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
if (col.collation.IsUTF8)
{ // UTF8 collation
- col.encoding = s_utf8EncodingWithoutBom;
+ col.Encoding = s_utf8EncodingWithoutBom;
}
else
{
@@ -5658,18 +5661,18 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
if (codePage == _defaultCodePage)
{
- col.codePage = _defaultCodePage;
- col.encoding = _defaultEncoding;
+ col.CodePage = _defaultCodePage;
+ col.Encoding = _defaultEncoding;
}
else
{
- col.codePage = codePage;
- col.encoding = System.Text.Encoding.GetEncoding(col.codePage);
+ col.CodePage = codePage;
+ col.Encoding = System.Text.Encoding.GetEncoding(col.CodePage);
}
}
}
- if (col.type == SqlDbTypeExtensions.Vector)
+ if (col.DbType == SqlDbTypeExtensions.Vector)
{
result = stateObj.TryReadByte(out col.scale);
if (result != TdsOperationStatus.Done)
@@ -5681,7 +5684,7 @@ private TdsOperationStatus TryProcessTypeInfo(TdsParserStateObject stateObj, Sql
return TdsOperationStatus.Done;
}
- private TdsOperationStatus TryCommonProcessMetaData(TdsParserStateObject stateObj, _SqlMetaData col, SqlTceCipherInfoTable cipherTable, bool fColMD, SqlCommandColumnEncryptionSetting columnEncryptionSetting)
+ private TdsOperationStatus TryCommonProcessMetaData(TdsParserStateObject stateObj, TdsColumnMetadata col, SqlTceCipherInfoTable cipherTable, bool fColMD, SqlCommandColumnEncryptionSetting columnEncryptionSetting)
{
byte byteLen;
uint userType;
@@ -5716,7 +5719,7 @@ private TdsOperationStatus TryCommonProcessMetaData(TdsParserStateObject stateOb
if (fColMD && IsColumnEncryptionSupported)
{
- col.isEncrypted = (TdsEnums.IsEncrypted == (flags & TdsEnums.IsEncrypted));
+ col.IsEncrypted = (TdsEnums.IsEncrypted == (flags & TdsEnums.IsEncrypted));
}
// Read TypeInfo
@@ -5727,10 +5730,10 @@ private TdsOperationStatus TryCommonProcessMetaData(TdsParserStateObject stateOb
}
// Read tablename if present
- if (col.metaType.IsLong && !col.metaType.IsPlp)
+ if (col.MetaType.IsLong && !col.MetaType.IsPlp)
{
int unusedLen = 0xFFFF; //We ignore this value
- result = TryProcessOneTable(stateObj, ref unusedLen, out col.multiPartTableName);
+ result = TryProcessOneTable(stateObj, ref unusedLen, out col.tableName);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -5738,7 +5741,7 @@ private TdsOperationStatus TryCommonProcessMetaData(TdsParserStateObject stateOb
}
// Read the TCE column cryptoinfo
- if (fColMD && IsColumnEncryptionSupported && col.isEncrypted)
+ if (fColMD && IsColumnEncryptionSupported && col.IsEncrypted)
{
// If the column is encrypted, we should have a valid cipherTable
if (cipherTable != null)
@@ -5769,7 +5772,7 @@ private TdsOperationStatus TryCommonProcessMetaData(TdsParserStateObject stateOb
return TdsOperationStatus.Done;
}
- private TdsOperationStatus TryProcessUDTMetaData(SqlMetaDataPriv metaData, TdsParserStateObject stateObj)
+ private TdsOperationStatus TryProcessUDTMetaData(TdsTypeInfo metaData, TdsParserStateObject stateObj)
{
ushort shortLength;
byte byteLength;
@@ -5788,13 +5791,13 @@ private TdsOperationStatus TryProcessUDTMetaData(SqlMetaDataPriv metaData, TdsPa
{
return result;
}
- if (metaData.udt is null)
+ if (metaData.Udt is null)
{
- metaData.udt = new SqlMetaDataUdt();
+ metaData.Udt = new SqlMetaDataUdt();
}
if (byteLength != 0)
{
- result = stateObj.TryReadString(byteLength, out metaData.udt.DatabaseName);
+ result = stateObj.TryReadString(byteLength, out metaData.Udt.DatabaseName);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -5809,7 +5812,7 @@ private TdsOperationStatus TryProcessUDTMetaData(SqlMetaDataPriv metaData, TdsPa
}
if (byteLength != 0)
{
- result = stateObj.TryReadString(byteLength, out metaData.udt.SchemaName);
+ result = stateObj.TryReadString(byteLength, out metaData.Udt.SchemaName);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -5824,7 +5827,7 @@ private TdsOperationStatus TryProcessUDTMetaData(SqlMetaDataPriv metaData, TdsPa
}
if (byteLength != 0)
{
- result = stateObj.TryReadString(byteLength, out metaData.udt.TypeName);
+ result = stateObj.TryReadString(byteLength, out metaData.Udt.TypeName);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -5838,7 +5841,7 @@ private TdsOperationStatus TryProcessUDTMetaData(SqlMetaDataPriv metaData, TdsPa
}
if (shortLength != 0)
{
- result = stateObj.TryReadString(shortLength, out metaData.udt.AssemblyQualifiedName);
+ result = stateObj.TryReadString(shortLength, out metaData.Udt.AssemblyQualifiedName);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -5885,12 +5888,12 @@ private void WriteUDTMetaData(object value, string database, string schema, stri
}
}
- internal TdsOperationStatus TryProcessTableName(int length, TdsParserStateObject stateObj, out MultiPartTableName[] multiPartTableNames)
+ internal TdsOperationStatus TryProcessTableName(int length, TdsParserStateObject stateObj, out TdsTableName[] multiPartTableNames)
{
int tablesAdded = 0;
- MultiPartTableName[] tables = new MultiPartTableName[1];
- MultiPartTableName mpt;
+ TdsTableName[] tables = new TdsTableName[1];
+ TdsTableName mpt;
while (length > 0)
{
// UNDONE: BUG(?) SQL 8.003 returns two tables sometimes
@@ -5908,7 +5911,7 @@ internal TdsOperationStatus TryProcessTableName(int length, TdsParserStateObject
}
else
{
- MultiPartTableName[] newTables = new MultiPartTableName[tables.Length + 1];
+ TdsTableName[] newTables = new TdsTableName[tables.Length + 1];
Array.Copy(tables, 0, newTables, 0, tables.Length);
newTables[tables.Length] = mpt;
tables = newTables;
@@ -5921,15 +5924,15 @@ internal TdsOperationStatus TryProcessTableName(int length, TdsParserStateObject
return TdsOperationStatus.Done;
}
- private TdsOperationStatus TryProcessOneTable(TdsParserStateObject stateObj, ref int length, out MultiPartTableName multiPartTableName)
+ private TdsOperationStatus TryProcessOneTable(TdsParserStateObject stateObj, ref int length, out TdsTableName tdsTableName)
{
ushort tableLen;
- MultiPartTableName mpt;
+ TdsTableName mpt;
string value;
- multiPartTableName = default(MultiPartTableName);
+ tdsTableName = default(TdsTableName);
- mpt = new MultiPartTableName();
+ mpt = new TdsTableName();
byte nParts;
// Find out how many parts in the TDS stream
@@ -6009,12 +6012,12 @@ private TdsOperationStatus TryProcessOneTable(TdsParserStateObject stateObj, ref
}
Debug.Assert(nParts == 0, "ProcessTableName:Unidentified parts in the table name token stream!");
- multiPartTableName = mpt;
+ tdsTableName = mpt;
return TdsOperationStatus.Done;
}
// augments current metadata with table and key information
- private TdsOperationStatus TryProcessColInfo(_SqlMetaDataSet columns, SqlDataReader reader, TdsParserStateObject stateObj, out _SqlMetaDataSet metaData)
+ private TdsOperationStatus TryProcessColInfo(TdsColumnMetadataToken columns, SqlDataReader reader, TdsParserStateObject stateObj, out TdsColumnMetadataToken metaData)
{
Debug.Assert(columns != null && columns.Length > 0, "no metadata available!");
@@ -6022,7 +6025,7 @@ private TdsOperationStatus TryProcessColInfo(_SqlMetaDataSet columns, SqlDataRea
for (int i = 0; i < columns.Length; i++)
{
- _SqlMetaData col = columns[i];
+ TdsColumnMetadata col = columns[i];
TdsOperationStatus result = stateObj.TryReadByte(out _);
if (result != TdsOperationStatus.Done)
@@ -6070,7 +6073,7 @@ private TdsOperationStatus TryProcessColInfo(_SqlMetaDataSet columns, SqlDataRea
if ((reader.TableNames != null) && (col.tableNum > 0))
{
Debug.Assert(reader.TableNames.Length >= col.tableNum, "invalid tableNames array!");
- col.multiPartTableName = reader.TableNames[col.tableNum - 1];
+ col.tableName = reader.TableNames[col.tableNum - 1];
}
// MDAC 60109: expressions are readonly
@@ -6089,7 +6092,7 @@ private TdsOperationStatus TryProcessColInfo(_SqlMetaDataSet columns, SqlDataRea
// for long columns, reads off textptrs, reads length, check nullability
// for other columns, reads length, checks nullability
// returns length and nullability
- internal TdsOperationStatus TryProcessColumnHeader(SqlMetaDataPriv col, TdsParserStateObject stateObj, int columnOrdinal, out bool isNull, out ulong length)
+ internal TdsOperationStatus TryProcessColumnHeader(TdsTypeInfo col, TdsParserStateObject stateObj, int columnOrdinal, out bool isNull, out ulong length)
{
// query NBC row information first
if (stateObj.IsNullCompressionBitSet(columnOrdinal))
@@ -6103,9 +6106,9 @@ internal TdsOperationStatus TryProcessColumnHeader(SqlMetaDataPriv col, TdsParse
return TryProcessColumnHeaderNoNBC(col, stateObj, out isNull, out length);
}
- private TdsOperationStatus TryProcessColumnHeaderNoNBC(SqlMetaDataPriv col, TdsParserStateObject stateObj, out bool isNull, out ulong length)
+ private TdsOperationStatus TryProcessColumnHeaderNoNBC(TdsTypeInfo col, TdsParserStateObject stateObj, out bool isNull, out ulong length)
{
- if (col.metaType.IsLong && !col.metaType.IsPlp)
+ if (col.MetaType.IsLong && !col.MetaType.IsPlp)
{
if (stateObj.IsSnapshotContinuing())
{
@@ -6167,7 +6170,7 @@ private TdsOperationStatus TryProcessColumnHeaderNoNBC(SqlMetaDataPriv col, TdsP
return result;
}
- isNull = IsNull(col.metaType, longlen);
+ isNull = IsNull(col.MetaType, longlen);
length = (isNull ? 0 : longlen);
return TdsOperationStatus.Done;
}
@@ -6208,13 +6211,13 @@ internal TdsOperationStatus TryGetAltRowId(TdsParserStateObject stateObj, out in
}
// Used internally by BulkCopy only
- private TdsOperationStatus TryProcessRow(_SqlMetaDataSet columns, object[] buffer, int[] map, TdsParserStateObject stateObj)
+ private TdsOperationStatus TryProcessRow(TdsColumnMetadataToken columns, object[] buffer, int[] map, TdsParserStateObject stateObj)
{
SqlBuffer data = new SqlBuffer();
for (int i = 0; i < columns.Length; i++)
{
- _SqlMetaData md = columns[i];
+ TdsColumnMetadata md = columns[i];
Debug.Assert(md != null, "_SqlMetaData should not be null for column " + i.ToString(CultureInfo.InvariantCulture));
bool isNull;
@@ -6236,7 +6239,7 @@ private TdsOperationStatus TryProcessRow(_SqlMetaDataSet columns, object[] buffe
// We only read up to 2Gb. Throw if data is larger. Very large data
// should be read in chunks in sequential read mode
// For Plp columns, we may have gotten only the length of the first chunk
- result = TryReadSqlValue(data, md, md.metaType.IsPlp ? (int.MaxValue) : (int)len, stateObj,
+ result = TryReadSqlValue(data, md, md.MetaType.IsPlp ? (int.MaxValue) : (int)len, stateObj,
SqlCommandColumnEncryptionSetting.Disabled /*Column Encryption Disabled for Bulk Copy*/,
md.column);
if (result != TdsOperationStatus.Done)
@@ -6282,17 +6285,17 @@ internal static bool ShouldHonorTceForRead(
}
internal static object GetNullSqlValue(SqlBuffer nullVal,
- SqlMetaDataPriv md,
+ TdsTypeInfo md,
SqlCommandColumnEncryptionSetting columnEncryptionSetting,
SqlConnectionInternal connection)
{
- SqlDbType type = md.type;
+ SqlDbType type = md.DbType;
if (type == SqlDbType.VarBinary && // if its a varbinary
- md.isEncrypted &&// and encrypted
+ md.IsEncrypted &&// and encrypted
ShouldHonorTceForRead(columnEncryptionSetting, connection))
{
- type = md.baseTI.type; // the use the actual (plaintext) type
+ type = md.BaseTypeInfo.DbType; // the use the actual (plaintext) type
}
switch (type)
@@ -6401,23 +6404,23 @@ internal static object GetNullSqlValue(SqlBuffer nullVal,
break;
default:
- Debug.Fail("unknown null sqlType!" + md.type.ToString());
+ Debug.Fail("unknown null sqlType!" + md.DbType.ToString());
break;
}
return nullVal;
}
- internal TdsOperationStatus TrySkipRow(_SqlMetaDataSet columns, TdsParserStateObject stateObj)
+ internal TdsOperationStatus TrySkipRow(TdsColumnMetadataToken columns, TdsParserStateObject stateObj)
{
return TrySkipRow(columns, 0, stateObj);
}
- internal TdsOperationStatus TrySkipRow(_SqlMetaDataSet columns, int startCol, TdsParserStateObject stateObj)
+ internal TdsOperationStatus TrySkipRow(TdsColumnMetadataToken columns, int startCol, TdsParserStateObject stateObj)
{
for (int i = startCol; i < columns.Length; i++)
{
- _SqlMetaData md = columns[i];
+ TdsColumnMetadata md = columns[i];
TdsOperationStatus result = TrySkipValue(md, i, stateObj);
if (result != TdsOperationStatus.Done)
@@ -6431,7 +6434,7 @@ internal TdsOperationStatus TrySkipRow(_SqlMetaDataSet columns, int startCol, Td
///
/// This method skips bytes of a single column value from the media. It supports NBCROW and handles all types of values, including PLP and long
///
- internal TdsOperationStatus TrySkipValue(SqlMetaDataPriv md, int columnOrdinal, TdsParserStateObject stateObj)
+ internal TdsOperationStatus TrySkipValue(TdsTypeInfo md, int columnOrdinal, TdsParserStateObject stateObj)
{
if (stateObj.IsNullCompressionBitSet(columnOrdinal))
{
@@ -6439,7 +6442,7 @@ internal TdsOperationStatus TrySkipValue(SqlMetaDataPriv md, int columnOrdinal,
}
TdsOperationStatus result;
- if (md.metaType.IsPlp)
+ if (md.MetaType.IsPlp)
{
result = TrySkipPlpValue(ulong.MaxValue, stateObj, out _);
if (result != TdsOperationStatus.Done)
@@ -6447,9 +6450,9 @@ internal TdsOperationStatus TrySkipValue(SqlMetaDataPriv md, int columnOrdinal,
return result;
}
}
- else if (md.metaType.IsLong)
+ else if (md.MetaType.IsLong)
{
- Debug.Assert(!md.metaType.IsPlp, "Plp types must be handled using SkipPlpValue");
+ Debug.Assert(!md.MetaType.IsPlp, "Plp types must be handled using SkipPlpValue");
byte textPtrLen;
result = stateObj.TryReadByte(out textPtrLen);
@@ -6467,7 +6470,7 @@ internal TdsOperationStatus TrySkipValue(SqlMetaDataPriv md, int columnOrdinal,
}
int length;
- result = TryGetTokenLength(md.tdsType, stateObj, out length);
+ result = TryGetTokenLength(md.TdsType, stateObj, out length);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -6482,14 +6485,14 @@ internal TdsOperationStatus TrySkipValue(SqlMetaDataPriv md, int columnOrdinal,
else
{
int length;
- result = TryGetTokenLength(md.tdsType, stateObj, out length);
+ result = TryGetTokenLength(md.TdsType, stateObj, out length);
if (result != TdsOperationStatus.Done)
{
return result;
}
// if false, no value to skip - it's null
- if (!IsNull(md.metaType, (ulong)length))
+ if (!IsNull(md.MetaType, (ulong)length))
{
result = stateObj.TrySkipBytes(length);
if (result != TdsOperationStatus.Done)
@@ -6607,21 +6610,21 @@ out string resultString
///
/// Deserializes the unencrypted bytes into a value based on the target type info.
///
- internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedBytes, SqlMetaDataPriv md, TdsParserStateObject stateObj, byte normalizationVersion)
+ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedBytes, TdsTypeInfo md, TdsParserStateObject stateObj, byte normalizationVersion)
{
if (normalizationVersion != 0x01)
{
throw SQL.UnsupportedNormalizationVersion(normalizationVersion);
}
- byte tdsType = md.baseTI.tdsType;
+ byte tdsType = md.BaseTypeInfo.TdsType;
int length = unencryptedBytes.Length;
// For normalized types, the length and scale of the actual type might be different than the value's.
- int denormalizedLength = md.baseTI.length;
- byte denormalizedScale = md.baseTI.scale;
+ int denormalizedLength = md.BaseTypeInfo.length;
+ byte denormalizedScale = md.BaseTypeInfo.scale;
- Debug.Assert(false == md.baseTI.isEncrypted, "Double encryption detected");
+ Debug.Assert(false == md.BaseTypeInfo.IsEncrypted, "Double encryption detected");
//DEVNOTE: When modifying the following routines (for deserialization) please pay attention to
// deserialization code in DecryptWithKey () method and modify it accordingly.
switch (tdsType)
@@ -6784,7 +6787,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
// If this is a fixed length type, pad with zeros to get to the fixed length size.
if (tdsType == TdsEnums.SQLBINARY || tdsType == TdsEnums.SQLBIGBINARY)
{
- byte[] bytes = new byte[md.baseTI.length];
+ byte[] bytes = new byte[md.BaseTypeInfo.length];
Buffer.BlockCopy(unencryptedBytes, 0, bytes, 0, unencryptedBytes.Length);
unencryptedBytes = bytes;
}
@@ -6815,7 +6818,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
bits[i] = BinaryPrimitives.ReadInt32LittleEndian(span.Slice(index));
index += 4;
}
- value.SetToDecimal(md.baseTI.precision, md.baseTI.scale, fPositive, bits);
+ value.SetToDecimal(md.BaseTypeInfo.precision, md.BaseTypeInfo.scale, fPositive, bits);
break;
case TdsEnums.SQLCHAR:
@@ -6824,7 +6827,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
case TdsEnums.SQLBIGVARCHAR:
case TdsEnums.SQLTEXT:
{
- System.Text.Encoding encoding = md.baseTI.encoding;
+ System.Text.Encoding encoding = md.BaseTypeInfo.Encoding;
if (encoding == null)
{
@@ -6841,7 +6844,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
// If this is a fixed length type, pad with spaces to get to the fixed length size.
if (tdsType == TdsEnums.SQLCHAR || tdsType == TdsEnums.SQLBIGCHAR)
{
- strValue = strValue.PadRight(md.baseTI.length);
+ strValue = strValue.PadRight(md.BaseTypeInfo.length);
}
value.SetToString(strValue);
@@ -6857,7 +6860,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
// If this is a fixed length type, pad with spaces to get to the fixed length size.
if (tdsType == TdsEnums.SQLNCHAR)
{
- strValue = strValue.PadRight(md.baseTI.length / ADP.CharSize);
+ strValue = strValue.PadRight(md.BaseTypeInfo.length / ADP.CharSize);
}
value.SetToString(strValue);
@@ -6888,7 +6891,7 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
break;
default:
- MetaType metaType = md.baseTI.metaType;
+ MetaType metaType = md.BaseTypeInfo.MetaType;
// If we don't have a metatype already, construct one to get the proper type name.
if (metaType == null)
@@ -6903,18 +6906,18 @@ internal bool DeserializeUnencryptedValue(SqlBuffer value, byte[] unencryptedByt
}
internal TdsOperationStatus TryReadSqlValue(SqlBuffer value,
- SqlMetaDataPriv md,
+ TdsTypeInfo md,
int length,
TdsParserStateObject stateObj,
SqlCommandColumnEncryptionSetting columnEncryptionOverride,
string columnName,
SqlCommand command = null)
{
- bool isPlp = md.metaType.IsPlp;
- byte tdsType = md.tdsType;
+ bool isPlp = md.MetaType.IsPlp;
+ byte tdsType = md.TdsType;
TdsOperationStatus result;
- Debug.Assert(isPlp || !IsNull(md.metaType, (ulong)length), "null value should not get here!");
+ Debug.Assert(isPlp || !IsNull(md.MetaType, (ulong)length), "null value should not get here!");
if (isPlp)
{
// We must read the column value completely, no matter what length is passed in
@@ -6948,7 +6951,7 @@ internal TdsOperationStatus TryReadSqlValue(SqlBuffer value,
return result;
}
- if (md.isEncrypted
+ if (md.IsEncrypted
&& (columnEncryptionOverride == SqlCommandColumnEncryptionSetting.Enabled
|| columnEncryptionOverride == SqlCommandColumnEncryptionSetting.ResultSetOnly
|| (columnEncryptionOverride == SqlCommandColumnEncryptionSetting.UseConnectionSetting
@@ -6958,7 +6961,7 @@ internal TdsOperationStatus TryReadSqlValue(SqlBuffer value,
try
{
// CipherInfo is present, decrypt and read
- byte[] unencryptedBytes = SqlSecurityUtility.DecryptWithKey(b, md.cipherMD, _connHandler.Connection, command);
+ byte[] unencryptedBytes = SqlSecurityUtility.DecryptWithKey(b, md.CipherMetadata, _connHandler.Connection, command);
if (unencryptedBytes != null)
{
@@ -7047,7 +7050,7 @@ internal TdsOperationStatus TryReadSqlValue(SqlBuffer value,
case TdsEnums.SQLNVARCHAR:
case TdsEnums.SQLNTEXT:
case TdsEnums.SQLJSON:
- result = TryReadSqlStringValue(value, tdsType, length, md.encoding, isPlp, stateObj);
+ result = TryReadSqlStringValue(value, tdsType, length, md.Encoding, isPlp, stateObj);
if (result != TdsOperationStatus.Done)
{
return result;
@@ -8664,25 +8667,25 @@ internal int GetEncodingCharLength(string value, int numChars, int charOffset, E
// Returns the data stream length of the data identified by tds type or SqlMetaData returns
// Returns either the total size or the size of the first chunk for partially length prefixed types.
//
- internal TdsOperationStatus TryGetDataLength(SqlMetaDataPriv colmeta, TdsParserStateObject stateObj, out ulong length)
+ internal TdsOperationStatus TryGetDataLength(TdsTypeInfo colmeta, TdsParserStateObject stateObj, out ulong length)
{
// Handle 2005 specific tokens
- if (colmeta.metaType.IsPlp)
+ if (colmeta.MetaType.IsPlp)
{
- Debug.Assert(colmeta.tdsType == TdsEnums.SQLXMLTYPE ||
- colmeta.tdsType == TdsEnums.SQLBIGVARCHAR ||
- colmeta.tdsType == TdsEnums.SQLBIGVARBINARY ||
- colmeta.tdsType == TdsEnums.SQLNVARCHAR ||
- colmeta.tdsType == TdsEnums.SQLJSON ||
+ Debug.Assert(colmeta.TdsType == TdsEnums.SQLXMLTYPE ||
+ colmeta.TdsType == TdsEnums.SQLBIGVARCHAR ||
+ colmeta.TdsType == TdsEnums.SQLBIGVARBINARY ||
+ colmeta.TdsType == TdsEnums.SQLNVARCHAR ||
+ colmeta.TdsType == TdsEnums.SQLJSON ||
// Large UDTs is WinFS-only
- colmeta.tdsType == TdsEnums.SQLUDT,
+ colmeta.TdsType == TdsEnums.SQLUDT,
"GetDataLength:Invalid streaming datatype");
return stateObj.TryReadPlpLength(true, out length);
}
else
{
int intLength;
- TdsOperationStatus result = TryGetTokenLength(colmeta.tdsType, stateObj, out intLength);
+ TdsOperationStatus result = TryGetTokenLength(colmeta.TdsType, stateObj, out intLength);
if (result != TdsOperationStatus.Done)
{
length = 0;
@@ -9904,7 +9907,7 @@ internal SqlDataReader TdsExecuteTransactionManagerRequest(
dtcReader.Bind(stateObj);
// force consumption of metadata
- _SqlMetaDataSet metaData = dtcReader.MetaData;
+ TdsColumnMetadataToken metaData = dtcReader.MetaData;
}
else
{
@@ -11432,7 +11435,7 @@ internal Task WriteBulkCopyDone(TdsParserStateObject stateObj)
/// decrypt the CEK and keep it ready for encryption.
///
///
- internal void LoadColumnEncryptionKeys(_SqlMetaDataSet metadataCollection, SqlConnection connection, SqlCommand command = null)
+ internal void LoadColumnEncryptionKeys(TdsColumnMetadataToken metadataCollection, SqlConnection connection, SqlCommand command = null)
{
if (IsColumnEncryptionSupported && ShouldEncryptValuesForBulkCopy())
{
@@ -11440,10 +11443,10 @@ internal void LoadColumnEncryptionKeys(_SqlMetaDataSet metadataCollection, SqlCo
{
if (metadataCollection[col] != null)
{
- _SqlMetaData md = metadataCollection[col];
- if (md.isEncrypted)
+ TdsColumnMetadata md = metadataCollection[col];
+ if (md.IsEncrypted)
{
- SqlSecurityUtility.DecryptSymmetricKey(md.cipherMD, connection, command);
+ SqlSecurityUtility.DecryptSymmetricKey(md.CipherMetadata, connection, command);
}
}
}
@@ -11479,7 +11482,7 @@ internal void WriteEncryptionEntries(ref SqlTceCipherInfoTable cekTable, TdsPars
/// Writes a CEK Table (as part of COLMETADATA token) for bulk copy.
///
///
- internal void WriteCekTable(_SqlMetaDataSet metadataCollection, TdsParserStateObject stateObj)
+ internal void WriteCekTable(TdsColumnMetadataToken metadataCollection, TdsParserStateObject stateObj)
{
if (!IsColumnEncryptionSupported)
{
@@ -11490,14 +11493,14 @@ internal void WriteCekTable(_SqlMetaDataSet metadataCollection, TdsParserStateOb
// Note- Cek table (with 0 entries) will be present if TCE
// was enabled and server supports it!
// OR if encryption was disabled in connection options
- if (metadataCollection.cekTable == null ||
+ if (metadataCollection.CekTable == null ||
!ShouldEncryptValuesForBulkCopy())
{
WriteShort(0x00, stateObj);
return;
}
- SqlTceCipherInfoTable cekTable = metadataCollection.cekTable;
+ SqlTceCipherInfoTable cekTable = metadataCollection.CekTable;
ushort count = (ushort)cekTable.Size;
WriteShort(count, stateObj);
@@ -11509,20 +11512,20 @@ internal void WriteCekTable(_SqlMetaDataSet metadataCollection, TdsParserStateOb
/// Writes the UserType and TYPE_INFO values for CryptoMetadata (for bulk copy).
///
///
- internal void WriteTceUserTypeAndTypeInfo(SqlMetaDataPriv mdPriv, TdsParserStateObject stateObj)
+ internal void WriteTceUserTypeAndTypeInfo(TdsTypeInfo mdPriv, TdsParserStateObject stateObj)
{
// Write the UserType (4 byte value)
WriteInt(0x0, stateObj); // TODO: fix this- timestamp columns have 0x50 value here
- Debug.Assert(SqlDbType.Xml != mdPriv.type);
- Debug.Assert(SqlDbType.Udt != mdPriv.type);
+ Debug.Assert(SqlDbType.Xml != mdPriv.DbType);
+ Debug.Assert(SqlDbType.Udt != mdPriv.DbType);
- stateObj.WriteByte(mdPriv.tdsType);
+ stateObj.WriteByte(mdPriv.TdsType);
- switch (mdPriv.type)
+ switch (mdPriv.DbType)
{
case SqlDbType.Decimal:
- WriteTokenLength(mdPriv.tdsType, mdPriv.length, stateObj);
+ WriteTokenLength(mdPriv.TdsType, mdPriv.length, stateObj);
stateObj.WriteByte(mdPriv.precision);
stateObj.WriteByte(mdPriv.scale);
break;
@@ -11535,8 +11538,8 @@ internal void WriteTceUserTypeAndTypeInfo(SqlMetaDataPriv mdPriv, TdsParserState
stateObj.WriteByte(mdPriv.scale);
break;
default:
- WriteTokenLength(mdPriv.tdsType, mdPriv.length, stateObj);
- if (mdPriv.metaType.IsCharType)
+ WriteTokenLength(mdPriv.TdsType, mdPriv.length, stateObj);
+ if (mdPriv.MetaType.IsCharType)
{
WriteUnsignedInt(mdPriv.collation._info, stateObj);
stateObj.WriteByte(mdPriv.collation._sortId);
@@ -11549,40 +11552,40 @@ internal void WriteTceUserTypeAndTypeInfo(SqlMetaDataPriv mdPriv, TdsParserState
/// Writes the crypto metadata (as part of COLMETADATA token) for encrypted columns.
///
///
- internal void WriteCryptoMetadata(_SqlMetaData md, TdsParserStateObject stateObj)
+ internal void WriteCryptoMetadata(TdsColumnMetadata md, TdsParserStateObject stateObj)
{
if (!IsColumnEncryptionSupported || // TCE Feature supported
- !md.isEncrypted || // Column is not encrypted
+ !md.IsEncrypted || // Column is not encrypted
!ShouldEncryptValuesForBulkCopy())
{ // TCE disabled on connection string
return;
}
// Write the ordinal
- WriteShort(md.cipherMD.CekTableOrdinal, stateObj);
+ WriteShort(md.CipherMetadata.CekTableOrdinal, stateObj);
// Write UserType and TYPEINFO
- WriteTceUserTypeAndTypeInfo(md.baseTI, stateObj);
+ WriteTceUserTypeAndTypeInfo(md.BaseTypeInfo, stateObj);
// Write Encryption Algo
- stateObj.WriteByte(md.cipherMD.CipherAlgorithmId);
+ stateObj.WriteByte(md.CipherMetadata.CipherAlgorithmId);
- if (TdsEnums.CustomCipherAlgorithmId == md.cipherMD.CipherAlgorithmId)
+ if (TdsEnums.CustomCipherAlgorithmId == md.CipherMetadata.CipherAlgorithmId)
{
// Write the algorithm name
- Debug.Assert(md.cipherMD.CipherAlgorithmName.Length < 256);
- stateObj.WriteByte((byte)md.cipherMD.CipherAlgorithmName.Length);
- WriteString(md.cipherMD.CipherAlgorithmName, stateObj);
+ Debug.Assert(md.CipherMetadata.CipherAlgorithmName.Length < 256);
+ stateObj.WriteByte((byte)md.CipherMetadata.CipherAlgorithmName.Length);
+ WriteString(md.CipherMetadata.CipherAlgorithmName, stateObj);
}
// Write Encryption Algo Type
- stateObj.WriteByte(md.cipherMD.EncryptionType);
+ stateObj.WriteByte(md.CipherMetadata.EncryptionType);
// Write Normalization Version
- stateObj.WriteByte(md.cipherMD.NormalizationRuleVersion);
+ stateObj.WriteByte(md.CipherMetadata.NormalizationRuleVersion);
}
- internal void WriteBulkCopyMetaData(_SqlMetaDataSet metadataCollection, int count, TdsParserStateObject stateObj)
+ internal void WriteBulkCopyMetaData(TdsColumnMetadataToken metadataCollection, int count, TdsParserStateObject stateObj)
{
if (!(State == TdsParserState.OpenNotLoggedIn || State == TdsParserState.OpenLoggedIn))
{
@@ -11599,7 +11602,7 @@ internal void WriteBulkCopyMetaData(_SqlMetaDataSet metadataCollection, int coun
{
if (metadataCollection[i] != null)
{
- _SqlMetaData md = metadataCollection[i];
+ TdsColumnMetadata md = metadataCollection[i];
// read user type - 4 bytes 2005, 2 backwards
WriteInt(0x0, stateObj);
@@ -11615,7 +11618,7 @@ internal void WriteBulkCopyMetaData(_SqlMetaDataSet metadataCollection, int coun
{ // TCE Supported
if (ShouldEncryptValuesForBulkCopy())
{ // TCE enabled on connection options
- flags |= (UInt16)(md.isEncrypted ? (UInt16)(TdsEnums.IsEncrypted << 8) : (UInt16)0);
+ flags |= (UInt16)(md.IsEncrypted ? (UInt16)(TdsEnums.IsEncrypted << 8) : (UInt16)0);
}
}
@@ -11626,11 +11629,11 @@ internal void WriteBulkCopyMetaData(_SqlMetaDataSet metadataCollection, int coun
// discuss ...
// xml datatype does not have token length in its metadata. So it should be a noop.
- switch (md.type)
+ switch (md.DbType)
{
case SqlDbType.Decimal:
- stateObj.WriteByte(md.tdsType);
- WriteTokenLength(md.tdsType, md.length, stateObj);
+ stateObj.WriteByte(md.TdsType);
+ WriteTokenLength(md.TdsType, md.length, stateObj);
stateObj.WriteByte(md.precision);
stateObj.WriteByte(md.scale);
break;
@@ -11643,26 +11646,26 @@ internal void WriteBulkCopyMetaData(_SqlMetaDataSet metadataCollection, int coun
WriteTokenLength(TdsEnums.SQLBIGVARBINARY, md.length, stateObj);
break;
case SqlDbType.Date:
- stateObj.WriteByte(md.tdsType);
+ stateObj.WriteByte(md.TdsType);
break;
case SqlDbType.Time:
case SqlDbType.DateTime2:
case SqlDbType.DateTimeOffset:
- stateObj.WriteByte(md.tdsType);
+ stateObj.WriteByte(md.TdsType);
stateObj.WriteByte(md.scale);
break;
case SqlDbTypeExtensions.Json:
stateObj.WriteByteArray(s_jsonMetadataSubstituteSequence, s_jsonMetadataSubstituteSequence.Length, 0);
break;
case SqlDbTypeExtensions.Vector:
- stateObj.WriteByte(md.tdsType);
- WriteTokenLength(md.tdsType, md.length, stateObj);
+ stateObj.WriteByte(md.TdsType);
+ WriteTokenLength(md.TdsType, md.length, stateObj);
stateObj.WriteByte(md.scale);
break;
default:
- stateObj.WriteByte(md.tdsType);
- WriteTokenLength(md.tdsType, md.length, stateObj);
- if (md.metaType.IsCharType)
+ stateObj.WriteByte(md.TdsType);
+ WriteTokenLength(md.TdsType, md.length, stateObj);
+ if (md.MetaType.IsCharType)
{
WriteUnsignedInt(md.collation._info, stateObj);
stateObj.WriteByte(md.collation._sortId);
@@ -11670,10 +11673,10 @@ internal void WriteBulkCopyMetaData(_SqlMetaDataSet metadataCollection, int coun
break;
}
- if (md.metaType.IsLong && !md.metaType.IsPlp)
+ if (md.MetaType.IsLong && !md.MetaType.IsPlp)
{
- WriteShort(md.tableName.Length, stateObj);
- WriteString(md.tableName, stateObj);
+ WriteShort(md.TableName.Length, stateObj);
+ WriteString(md.TableName, stateObj);
}
WriteCryptoMetadata(md, stateObj);
@@ -11704,7 +11707,7 @@ internal bool ShouldEncryptValuesForBulkCopy()
/// Encrypts a column value (for SqlBulkCopy)
///
///
- internal object EncryptColumnValue(object value, SqlMetaDataPriv metadata, string column, TdsParserStateObject stateObj, bool isDataFeed, bool isSqlType)
+ internal object EncryptColumnValue(object value, TdsTypeInfo metadata, string column, TdsParserStateObject stateObj, bool isDataFeed, bool isSqlType)
{
Debug.Assert(IsColumnEncryptionSupported, "Server doesn't support encryption, yet we received encryption metadata");
Debug.Assert(ShouldEncryptValuesForBulkCopy(), "Encryption attempted when not requested");
@@ -11715,7 +11718,7 @@ internal object EncryptColumnValue(object value, SqlMetaDataPriv metadata, strin
}
int actualLengthInBytes;
- switch (metadata.baseTI.metaType.NullableType)
+ switch (metadata.BaseTypeInfo.MetaType.NullableType)
{
case TdsEnums.SQLBIGBINARY:
case TdsEnums.SQLBIGVARBINARY:
@@ -11730,11 +11733,11 @@ internal object EncryptColumnValue(object value, SqlMetaDataPriv metadata, strin
// to report the size of data to be copied out (for serialization). If we underreport the
// size, truncation will happen for us!
actualLengthInBytes = (isSqlType) ? ((SqlBinary)value).Length : ((byte[])value).Length;
- if (metadata.baseTI.length > 0 &&
- actualLengthInBytes > metadata.baseTI.length)
+ if (metadata.BaseTypeInfo.length > 0 &&
+ actualLengthInBytes > metadata.BaseTypeInfo.length)
{
// see comments above
- actualLengthInBytes = metadata.baseTI.length;
+ actualLengthInBytes = metadata.BaseTypeInfo.length;
}
break;
@@ -11753,10 +11756,10 @@ internal object EncryptColumnValue(object value, SqlMetaDataPriv metadata, strin
actualLengthInBytes = _defaultEncoding.GetByteCount(stringValue);
// If the string length is > max length, then use the max length (see comments above)
- if (metadata.baseTI.length > 0 &&
- actualLengthInBytes > metadata.baseTI.length)
+ if (metadata.BaseTypeInfo.length > 0 &&
+ actualLengthInBytes > metadata.BaseTypeInfo.length)
{
- actualLengthInBytes = metadata.baseTI.length; // this ensure truncation!
+ actualLengthInBytes = metadata.BaseTypeInfo.length; // this ensure truncation!
}
break;
@@ -11765,16 +11768,16 @@ internal object EncryptColumnValue(object value, SqlMetaDataPriv metadata, strin
case TdsEnums.SQLNTEXT:
actualLengthInBytes = ((isSqlType) ? ((SqlString)value).Value.Length : ((string)value).Length) * 2;
- if (metadata.baseTI.length > 0 &&
- actualLengthInBytes > metadata.baseTI.length)
+ if (metadata.BaseTypeInfo.length > 0 &&
+ actualLengthInBytes > metadata.BaseTypeInfo.length)
{ // see comments above
- actualLengthInBytes = metadata.baseTI.length;
+ actualLengthInBytes = metadata.BaseTypeInfo.length;
}
break;
default:
- actualLengthInBytes = metadata.baseTI.length;
+ actualLengthInBytes = metadata.BaseTypeInfo.length;
break;
}
@@ -11783,33 +11786,33 @@ internal object EncryptColumnValue(object value, SqlMetaDataPriv metadata, strin
{
// SqlType
serializedValue = SerializeUnencryptedSqlValue(value,
- metadata.baseTI.metaType,
+ metadata.BaseTypeInfo.MetaType,
actualLengthInBytes,
offset: 0,
- normalizationVersion: metadata.cipherMD.NormalizationRuleVersion,
+ normalizationVersion: metadata.CipherMetadata.NormalizationRuleVersion,
stateObj: stateObj);
}
else
{
serializedValue = SerializeUnencryptedValue(value,
- metadata.baseTI.metaType,
- metadata.baseTI.scale,
+ metadata.BaseTypeInfo.MetaType,
+ metadata.BaseTypeInfo.scale,
actualLengthInBytes,
offset: 0,
isDataFeed: isDataFeed,
- normalizationVersion: metadata.cipherMD.NormalizationRuleVersion,
+ normalizationVersion: metadata.CipherMetadata.NormalizationRuleVersion,
stateObj: stateObj);
}
Debug.Assert(serializedValue != null, "serializedValue should not be null in TdsExecuteRPC.");
return SqlSecurityUtility.EncryptWithKey(
serializedValue,
- metadata.cipherMD,
+ metadata.CipherMetadata,
_connHandler.Connection,
null);
}
- internal Task WriteBulkCopyValue(object value, SqlMetaDataPriv metadata, TdsParserStateObject stateObj, bool isSqlType, bool isDataFeed, bool isNull)
+ internal Task WriteBulkCopyValue(object value, TdsTypeInfo metadata, TdsParserStateObject stateObj, bool isSqlType, bool isDataFeed, bool isNull)
{
Debug.Assert(!isSqlType || value is INullable, "isSqlType is true, but value can not be type cast to an INullable");
Debug.Assert(!isDataFeed ^ value is DataFeed, "Incorrect value for isDataFeed");
@@ -11827,9 +11830,9 @@ internal Task WriteBulkCopyValue(object value, SqlMetaDataPriv metadata, TdsPars
}
try
{
- if (metadata.encoding != null)
+ if (metadata.Encoding != null)
{
- _defaultEncoding = metadata.encoding;
+ _defaultEncoding = metadata.Encoding;
}
if (metadata.collation != null)
{
@@ -11842,9 +11845,9 @@ internal Task WriteBulkCopyValue(object value, SqlMetaDataPriv metadata, TdsPars
_defaultCollation = metadata.collation;
_defaultLCID = _defaultCollation.LCID;
}
- _defaultCodePage = metadata.codePage;
+ _defaultCodePage = metadata.CodePage;
- MetaType metatype = metadata.metaType;
+ MetaType metatype = metadata.MetaType;
int ccb = 0;
int ccbStringBytes = 0;
@@ -11944,7 +11947,7 @@ internal Task WriteBulkCopyValue(object value, SqlMetaDataPriv metadata, TdsPars
case SqlDbType.NText:
case SqlDbType.Image:
stateObj.WriteByteArray(s_longDataHeader, s_longDataHeader.Length, 0);
- WriteTokenLength(metadata.tdsType, ccbStringBytes == 0 ? ccb : ccbStringBytes, stateObj);
+ WriteTokenLength(metadata.TdsType, ccbStringBytes == 0 ? ccb : ccbStringBytes, stateObj);
break;
case SqlDbType.VarChar:
@@ -11960,7 +11963,7 @@ internal Task WriteBulkCopyValue(object value, SqlMetaDataPriv metadata, TdsPars
}
else
{
- WriteTokenLength(metadata.tdsType, ccbStringBytes == 0 ? ccb : ccbStringBytes, stateObj);
+ WriteTokenLength(metadata.TdsType, ccbStringBytes == 0 ? ccb : ccbStringBytes, stateObj);
}
if (isSqlType)
@@ -14137,7 +14140,7 @@ static int IncrementSnapshotDataSize(TdsParserStateObject stateObj, bool resetti
}
}
- internal int ReadPlpAnsiChars(ref char[] buff, int offst, int len, SqlMetaDataPriv metadata, TdsParserStateObject stateObj)
+ internal int ReadPlpAnsiChars(ref char[] buff, int offst, int len, TdsTypeInfo metadata, TdsParserStateObject stateObj)
{
int charsRead = 0;
int charsLeft = 0;
@@ -14168,7 +14171,7 @@ internal int ReadPlpAnsiChars(ref char[] buff, int offst, int len, SqlMetaDataPr
if (stateObj._plpdecoder == null)
{
- Encoding enc = metadata.encoding;
+ Encoding enc = metadata.Encoding;
if (enc == null)
{
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/TdsParserStateObject.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/TdsParserStateObject.cs
index d8aa9355d7..d52101baf6 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/TdsParserStateObject.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/TdsParserStateObject.cs
@@ -226,8 +226,8 @@ private enum SnapshotStatus
private readonly byte[] _partialHeaderBuffer = new byte[TdsEnums.HEADER_LEN]; // Scratch buffer for ProcessHeader
internal int _partialHeaderBytesRead;
- internal _SqlMetaDataSet _cleanupMetaData;
- internal _SqlMetaDataSetCollection _cleanupAltMetaDataSetArray;
+ internal TdsColumnMetadataToken _cleanupMetaData;
+ internal TdsAltMetadataCollection _cleanupAltMetaDataSetArray;
private SniContext _sniContext = SniContext.Undefined;
#if DEBUG
@@ -4932,8 +4932,8 @@ private sealed class StateObjectData
private int _inBytesPacket;
private byte _messageStatus;
internal NullBitmap _nullBitmapInfo;
- private _SqlMetaDataSet _cleanupMetaData;
- internal _SqlMetaDataSetCollection _cleanupAltMetaDataSetArray;
+ private TdsColumnMetadataToken _cleanupMetaData;
+ internal TdsAltMetadataCollection _cleanupAltMetaDataSetArray;
private SnapshottedStateFlags _state;
private ulong _longLen;
private ulong _longLenLeft;
@@ -5096,7 +5096,7 @@ internal void CloneCleanupAltMetaDataSetArray()
{
if (_stateObj._cleanupAltMetaDataSetArray != null && object.ReferenceEquals(_replayStateData?._cleanupAltMetaDataSetArray ?? default, _stateObj._cleanupAltMetaDataSetArray))
{
- _stateObj._cleanupAltMetaDataSetArray = (_SqlMetaDataSetCollection)_stateObj._cleanupAltMetaDataSetArray.Clone();
+ _stateObj._cleanupAltMetaDataSetArray = (TdsAltMetadataCollection)_stateObj._cleanupAltMetaDataSetArray.Clone();
}
}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/RoutingInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/RoutingInfo.cs
deleted file mode 100644
index c40c4cd970..0000000000
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/RoutingInfo.cs
+++ /dev/null
@@ -1,28 +0,0 @@
-// 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.
-
-namespace Microsoft.Data.SqlClient.Parser.Tokens;
-
-internal class RoutingInfo
-{
- internal RoutingInfo(byte protocol, ushort port, string serverName, string databaseName = null)
- {
- Protocol = protocol;
- Port = port;
- ServerName = serverName;
- DatabaseName = databaseName;
- }
-
- internal byte Protocol { get; private set; }
-
- internal ushort Port { get; private set; }
-
- internal string ServerName { get; private set; }
-
- ///
- /// The DatabaseName property is only used when routing via an EnhancedRouting ENVCHANGE token.
- /// It is not used when routing via the normal Routing ENVCHANGE token.
- ///
- internal string DatabaseName { get; private set; }
-}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/SqlFedAuthInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/SqlFedAuthInfo.cs
deleted file mode 100644
index 67e9c5529f..0000000000
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/SqlFedAuthInfo.cs
+++ /dev/null
@@ -1,25 +0,0 @@
-// 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.
-
-#nullable enable
-
-namespace Microsoft.Data.SqlClient.Parser.Tokens;
-
-internal sealed class SqlFedAuthInfo
-{
- internal SqlFedAuthInfo(string spn, string stsurl)
- {
- Spn = spn;
- StsUrl = stsurl;
- }
-
- internal string Spn { get; }
-
- internal string StsUrl { get; }
-
- public override string ToString()
- {
- return $"SPN: {Spn}, STSURL: {StsUrl}";
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/SqlMetaDataPriv.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/SqlMetaDataPriv.cs
deleted file mode 100644
index 60a005a8c6..0000000000
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/SqlMetaDataPriv.cs
+++ /dev/null
@@ -1,123 +0,0 @@
-// 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;
-using System.Data;
-using System.Text;
-
-namespace Microsoft.Data.SqlClient.Parser.Tokens;
-
-internal class SqlMetaDataPriv
-{
- [Flags]
- private enum SqlMetaDataPrivFlags : byte
- {
- None = 0,
- IsNullable = 1 << 1,
- IsMultiValued = 1 << 2
- }
-
- internal SqlDbType type; // SqlDbType enum value
- internal byte tdsType; // underlying tds type
- internal byte precision = TdsEnums.UNKNOWN_PRECISION_SCALE; // give default of unknown (-1)
- internal byte scale = TdsEnums.UNKNOWN_PRECISION_SCALE; // give default of unknown (-1)
- private SqlMetaDataPrivFlags flags;
- internal int length;
- internal SqlCollation collation;
- internal int codePage;
- internal Encoding encoding;
- internal bool isEncrypted; // TCE encrypted?
- internal SqlMetaDataPriv baseTI; // for encrypted columns, represents the TYPE_INFO for plaintext value
- internal SqlCipherMetadata cipherMD; // Cipher related metadata for encrypted columns.
-
- internal MetaType metaType; // cached metaType
- public SqlMetaDataUdt udt;
- public SqlMetaDataXmlSchemaCollection xmlSchemaCollection;
-
- internal SqlMetaDataPriv()
- {
- }
-
- ///
- /// Is the algorithm handle for the cipher encryption initialized?
- ///
- internal bool IsAlgorithmInitialized()
- {
- if (cipherMD != null)
- {
- return cipherMD.IsAlgorithmInitialized();
- }
-
- return false;
- }
-
- public bool IsNullable
- {
- get => HasFlag(SqlMetaDataPrivFlags.IsNullable);
- set => Set(SqlMetaDataPrivFlags.IsNullable, value);
- }
-
- public bool IsMultiValued
- {
- get => HasFlag(SqlMetaDataPrivFlags.IsMultiValued);
- set => Set(SqlMetaDataPrivFlags.IsMultiValued, value);
- }
-
- ///
- /// Returns the normalization rule version byte.
- ///
- ///
- internal byte NormalizationRuleVersion
- {
- get
- {
- if (cipherMD != null)
- {
- return cipherMD.NormalizationRuleVersion;
- }
-
- return 0x00;
- }
- }
-
- private bool HasFlag(SqlMetaDataPrivFlags flag)
- {
- return (flags & flag) != 0;
- }
-
- private void Set(SqlMetaDataPrivFlags flag, bool value)
- {
- flags = value ? flags | flag : flags & ~flag;
- }
-
- internal virtual void CopyFrom(SqlMetaDataPriv original)
- {
- this.type = original.type;
- this.tdsType = original.tdsType;
- this.precision = original.precision;
- this.scale = original.scale;
- this.length = original.length;
- this.collation = original.collation;
- this.codePage = original.codePage;
- this.encoding = original.encoding;
- this.metaType = original.metaType;
- this.flags = original.flags;
-
- if (original.udt != null)
- {
- udt = new SqlMetaDataUdt();
- udt.CopyFrom(original.udt);
- }
-
- if (original.xmlSchemaCollection != null)
- {
- xmlSchemaCollection = new SqlMetaDataXmlSchemaCollection();
- xmlSchemaCollection.CopyFrom(original.xmlSchemaCollection);
- }
-
- this.isEncrypted = original.isEncrypted;
- this.baseTI = original.baseTI;
- this.cipherMD = original.cipherMD;
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/SqlReturnValue.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/SqlReturnValue.cs
deleted file mode 100644
index dcac65ac5c..0000000000
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/SqlReturnValue.cs
+++ /dev/null
@@ -1,21 +0,0 @@
-// 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.
-
-namespace Microsoft.Data.SqlClient.Parser.Tokens;
-
-internal sealed class SqlReturnValue : SqlMetaDataPriv
-{
- // @TODO: Make auto properties (and rename to match)
- internal string parameter;
- internal readonly SqlBuffer value;
-
- #if NETFRAMEWORK
- internal ushort parmIndex; //2005 or later only
- #endif
-
- internal SqlReturnValue() : base()
- {
- value = new SqlBuffer();
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsAltMetadataCollection.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsAltMetadataCollection.cs
new file mode 100644
index 0000000000..6f32066c85
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsAltMetadataCollection.cs
@@ -0,0 +1,88 @@
+// 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.Collections.Generic;
+using System.Diagnostics;
+
+namespace Microsoft.Data.SqlClient.Parser.Tokens;
+
+///
+/// Represents a collection of alternative metadata sets within a SQLALTMETADATA or SQLALTROW token.
+///
+internal sealed class TdsAltMetadataCollection
+{
+ private readonly List _altMetadataSetArray;
+
+ internal TdsAltMetadataCollection()
+ {
+ _altMetadataSetArray = new List();
+ }
+
+ ///
+ /// Gets or sets the primary metadata set associated with an alternative metadata collection.
+ ///
+ internal TdsColumnMetadataToken MetadataSet { get; set; }
+
+ ///
+ /// Clones the collection and each metadata-set object; nested schema and encryption metadata may remain shared.
+ ///
+ public object Clone()
+ {
+ TdsAltMetadataCollection result = new() { MetadataSet = MetadataSet?.Clone() };
+
+ foreach (TdsColumnMetadataToken set in _altMetadataSetArray)
+ {
+ result._altMetadataSetArray.Add(set.Clone());
+ }
+
+ return result;
+ }
+
+ ///
+ /// Retrieves the alternate metadata set that corresponds to the specified identifier.
+ ///
+ /// The identifier of the alternate metadata set to retrieve.
+ ///
+ /// The instance that matches the specified identifier,
+ /// or null if no matching metadata set is found.
+ ///
+ internal TdsColumnMetadataToken GetAltMetadata(int id)
+ {
+ foreach (TdsColumnMetadataToken altMetaDataSet in _altMetadataSetArray)
+ {
+ if (altMetaDataSet.id == id)
+ {
+ return altMetaDataSet;
+ }
+ }
+
+ // @TODO: Debug fail usage here isn't ideal.
+ Debug.Fail("Can't match up altMetaDataSet with given id");
+ return null;
+ }
+
+ ///
+ /// Updates or adds an alternative metadata set to the collection.
+ ///
+ ///
+ /// Alternative metadata set to update or add to the collection.
+ ///
+ internal void SetAltMetadata(TdsColumnMetadataToken altMetadataSet)
+ {
+ // If alt metadata with same id is found, override it rather than adding a new one
+ int newId = altMetadataSet.id;
+ for (int i = 0; i < _altMetadataSetArray.Count; i++)
+ {
+ if (_altMetadataSetArray[i].id == newId)
+ {
+ // override the existing metadata with the same id
+ _altMetadataSetArray[i] = altMetadataSet;
+ return;
+ }
+ }
+
+ // if we did not find metadata to override, add as new
+ _altMetadataSetArray.Add(altMetadataSet);
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsColumnMetadata.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsColumnMetadata.cs
new file mode 100644
index 0000000000..267c96a1e2
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsColumnMetadata.cs
@@ -0,0 +1,213 @@
+// 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;
+using System.Data;
+
+namespace Microsoft.Data.SqlClient.Parser.Tokens;
+
+///
+/// Represents metadata information for a specific column in a TDS stream. Corresponds with a
+/// single column within a SQLCOLMETADATA/SQLALTMETADATA token.
+///
+internal sealed class TdsColumnMetadata : TdsTypeInfo
+{
+ [Flags]
+ private enum MetadataFlags
+ {
+ None = 0,
+
+ Updatable = 1 << 0,
+ UpdateableUnknown = 1 << 1,
+ IsDifferentName = 1 << 2,
+ IsKey = 1 << 3,
+ IsHidden = 1 << 4,
+ IsExpression = 1 << 5,
+ IsIdentity = 1 << 6,
+ IsColumnSet = 1 << 7,
+
+ IsUpdatableMask = (Updatable | UpdateableUnknown) // two bit field (0 is read only, 1 is updatable, 2 is updatability unknown)
+ }
+
+ ///
+ /// Represents the original name of the column in the data source if an alias is used.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryReadString.
+ internal string baseColumn;
+
+ ///
+ /// Represents the name of the column in the TDS stream.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryReadString.
+ internal string column;
+
+ ///
+ /// Represents the operation type associated with the column metadata, primarily used for
+ /// alternate-row column processing.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryRead*.
+ internal byte op; // for altrow-columns only
+
+ ///
+ /// Stores the multipart name details of the table associated with the column, including server,
+ /// catalog, schema, and table names.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryProcessOneTable.
+ internal TdsTableName tableName;
+
+ ///
+ /// Identifies the table associated with a column, if applicable, within the context of a
+ /// metadata structure.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryRead*.
+ internal byte tableNum;
+
+ private MetadataFlags _flags;
+
+ internal TdsColumnMetadata(int ordinal) : base()
+ {
+ Ordinal = ordinal;
+ }
+
+ ///
+ /// Gets the catalog name associated with the column's metadata.
+ ///
+ internal string CatalogName => tableName.CatalogName;
+
+
+ internal bool Is2008DateTimeType => DbType is SqlDbType.Date
+ or SqlDbType.Time
+ or SqlDbType.DateTime2
+ or SqlDbType.DateTimeOffset;
+
+ ///
+ /// Indicates whether the column is part of a sparse column set.
+ ///
+ public bool IsColumnSet
+ {
+ get => HasFlag(MetadataFlags.IsColumnSet);
+ set => SetFlag(MetadataFlags.IsColumnSet, value);
+ }
+
+ ///
+ /// Indicates whether the column has a name that differs from its original name in the data
+ /// source.
+ ///
+ public bool IsDifferentName
+ {
+ get => HasFlag(MetadataFlags.IsDifferentName);
+ set => SetFlag(MetadataFlags.IsDifferentName, value);
+ }
+
+ ///
+ /// Indicates whether the column in the metadata is based on an expression
+ /// rather than a direct column reference.
+ ///
+ public bool IsExpression
+ {
+ get => HasFlag(MetadataFlags.IsExpression);
+ set => SetFlag(MetadataFlags.IsExpression, value);
+ }
+
+ ///
+ /// Indicates whether the column is hidden in the result set metadata.
+ ///
+ public bool IsHidden
+ {
+ get => HasFlag(MetadataFlags.IsHidden);
+ set => SetFlag(MetadataFlags.IsHidden, value);
+ }
+
+ ///
+ /// Indicates whether the column is an identity column in the database.
+ ///
+ public bool IsIdentity
+ {
+ get => HasFlag(MetadataFlags.IsIdentity);
+ set => SetFlag(MetadataFlags.IsIdentity, value);
+ }
+
+ ///
+ /// Indicates whether the column is part of the primary key in the table or view.
+ ///
+ public bool IsKey
+ {
+ get => HasFlag(MetadataFlags.IsKey);
+ set => SetFlag(MetadataFlags.IsKey, value);
+ }
+
+ ///
+ /// Indicates whether the column is a large UDT with the maximum allowable length.
+ ///
+ internal bool IsLargeUdt => DbType == SqlDbType.Udt && length == int.MaxValue;
+
+ ///
+ /// Indicates whether the column is read-only in the context of the data source.
+ ///
+ public bool IsReadOnly => !HasFlag(MetadataFlags.IsUpdatableMask);
+
+ ///
+ /// Gets the zero-based position of the column within the result set metadata.
+ ///
+ internal int Ordinal { get; }
+
+ ///
+ /// Gets or sets the operand value associated with the column metadata.
+ ///
+ internal ushort Operand { get; set; }
+
+ ///
+ /// Represents the schema name associated with the table containing the column.
+ ///
+ internal string SchemaName => tableName.SchemaName;
+
+ ///
+ /// Gets the name of the server associated with the column's metadata.
+ ///
+ internal string ServerName => tableName.ServerName;
+
+ ///
+ /// Represents the name of the table associated with the column metadata.
+ ///
+ internal string TableName => tableName.TableName;
+
+ ///
+ /// Indicates whether the associated column can be updated.
+ ///
+ public byte Updatability
+ {
+ get => (byte)(_flags & MetadataFlags.IsUpdatableMask);
+ set => _flags = (MetadataFlags)((value & (byte)MetadataFlags.IsUpdatableMask) | ((int)_flags & ~(byte)MetadataFlags.IsUpdatableMask));
+ }
+
+ ///
+ /// Creates a copy of the current TdsColumnMetadata instance.
+ ///
+ ///
+ /// A new TdsColumnMetadata object that is a copy of the current instance.
+ ///
+ public object Clone()
+ {
+ TdsColumnMetadata result = new TdsColumnMetadata(Ordinal);
+ result.CopyFrom(this);
+ result.column = column;
+ result.baseColumn = baseColumn;
+ result.tableName = tableName;
+ result.tableNum = tableNum;
+ result._flags = _flags;
+ result.op = op;
+ result.Operand = Operand;
+ return result;
+ }
+
+ private bool HasFlag(MetadataFlags flag)
+ {
+ return (_flags & flag) != 0;
+ }
+
+ private void SetFlag(MetadataFlags flag, bool value)
+ {
+ _flags = value ? _flags | flag : _flags & ~flag;
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsColumnMetadataToken.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsColumnMetadataToken.cs
new file mode 100644
index 0000000000..e4e2a85474
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsColumnMetadataToken.cs
@@ -0,0 +1,173 @@
+// 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.Collections.ObjectModel;
+using System.Data;
+using System.Data.Common;
+using System.Diagnostics;
+
+namespace Microsoft.Data.SqlClient.Parser.Tokens;
+
+///
+/// Represents a metadata token that contains column information from the TDS stream. This
+/// corresponds to a SQLCOLMETADATA or SQLALTMETADATA token.
+///
+internal sealed class TdsColumnMetadataToken
+{
+ ///
+ /// Represents the identifier associated with an alternative metadata set in the TDS stream.
+ ///
+ // @TODO: This cannot be converted to an auto-property yet because it is accessed as an out parameter from TryReadUint16
+ internal ushort id;
+
+ private readonly TdsColumnMetadata[] _metadataArray;
+ private int _hiddenColumnCount; // @TODO: -1 is used as magic value for "unread hidden columns". We should derive all this from _visibleColumnMap?
+ private int[] _visibleColumnMap;
+
+ internal TdsColumnMetadataToken(int count)
+ {
+ _hiddenColumnCount = -1;
+ _metadataArray = new TdsColumnMetadata[count];
+ for (int i = 0; i < _metadataArray.Length; ++i)
+ {
+ _metadataArray[i] = new TdsColumnMetadata(i);
+ }
+ }
+
+ internal TdsColumnMetadataToken(int count, SqlTceCipherInfoTable cipherTable)
+ : this(count)
+ {
+ CekTable = cipherTable;
+ }
+
+ private TdsColumnMetadataToken(TdsColumnMetadataToken original)
+ {
+ id = original.id;
+ _hiddenColumnCount = original._hiddenColumnCount;
+ _visibleColumnMap = original._visibleColumnMap;
+ DbColumnSchema = original.DbColumnSchema;
+ SchemaTable = original.SchemaTable;
+ CekTable = original.CekTable;
+
+ if (original._metadataArray == null)
+ {
+ _metadataArray = null;
+ }
+ else
+ {
+ _metadataArray = new TdsColumnMetadata[original._metadataArray.Length];
+ for (int idx = 0; idx < _metadataArray.Length; idx++)
+ {
+ _metadataArray[idx] = (TdsColumnMetadata)original._metadataArray[idx].Clone();
+ }
+ }
+ }
+
+ ///
+ /// Provides access to the metadata array associated with this token. Allows retrieval and
+ /// updating of metadata at a specific index.
+ ///
+ internal TdsColumnMetadata this[int index]
+ {
+ get => _metadataArray[index];
+
+ set
+ {
+ // @TODO: If we're only allowed to set this to null, it feels like we're doing something wrong.
+ Debug.Assert(value == null, "used only by SqlBulkCopy");
+ _metadataArray[index] = value;
+ }
+ }
+
+ ///
+ /// Represents the table of column encryption keys (CEKs) associated with this metadata token.
+ ///
+ internal SqlTceCipherInfoTable CekTable { get; }
+
+ ///
+ /// Represents the schema of database columns associated with this metadata token.
+ ///
+ internal ReadOnlyCollection DbColumnSchema { get; set; }
+
+ ///
+ /// Gets the number of metadata entries in the associated metadata array. This includes both
+ /// visible and hidden columns.
+ ///
+ internal int Length => _metadataArray.Length;
+
+ ///
+ /// Represents the schema metadata for the columns associated with this token.
+ ///
+ internal DataTable SchemaTable { get; set; }
+
+ ///
+ /// Gets the number of visible columns excluding hidden columns.
+ ///
+ internal int VisibleColumnCount
+ {
+ get
+ {
+ if (_hiddenColumnCount == -1)
+ {
+ SetupHiddenColumns();
+ }
+
+ return Length - _hiddenColumnCount;
+ }
+ }
+
+ ///
+ /// Creates a new instance with independently cloned column metadata entries. Cached schema data,
+ /// the CEK table, and nested encryption metadata remain shared with the current instance.
+ ///
+ public TdsColumnMetadataToken Clone()
+ {
+ return new TdsColumnMetadataToken(this);
+ }
+
+ ///
+ /// Retrieves the index of a visible column based on the provided index,
+ /// considering hidden columns.
+ ///
+ /// The input index of the column to retrieve.
+ /// The index of the visible column corresponding to the given input index.
+ public int GetVisibleColumnIndex(int index)
+ {
+ if (_hiddenColumnCount == -1)
+ {
+ SetupHiddenColumns();
+ }
+
+ return _visibleColumnMap?[index] ?? index;
+ }
+
+ private void SetupHiddenColumns()
+ {
+ int hiddenColumnCount = 0;
+ for (int index = 0; index < Length; index++)
+ {
+ if (_metadataArray[index].IsHidden)
+ {
+ hiddenColumnCount += 1;
+ }
+ }
+
+ if (hiddenColumnCount > 0)
+ {
+ int[] visibleColumnMap = new int[Length - hiddenColumnCount];
+ int mapIndex = 0;
+ for (int metaDataIndex = 0; metaDataIndex < Length; metaDataIndex++)
+ {
+ if (!_metadataArray[metaDataIndex].IsHidden)
+ {
+ visibleColumnMap[mapIndex] = metaDataIndex;
+ mapIndex += 1;
+ }
+ }
+ _visibleColumnMap = visibleColumnMap;
+ }
+
+ _hiddenColumnCount = hiddenColumnCount;
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsEnvChangeRoutingInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsEnvChangeRoutingInfo.cs
new file mode 100644
index 0000000000..8f8e4ca1d9
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsEnvChangeRoutingInfo.cs
@@ -0,0 +1,43 @@
+// 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.
+
+namespace Microsoft.Data.SqlClient.Parser.Tokens;
+
+///
+/// Represents the routing information related to environment changes in the TDS protocol. This
+/// information is included within an SQLENVCHANGE token when the type is ENV_ROUTING or
+/// ENV_ENHANCEDROUTING.
+///
+internal class TdsEnvChangeRoutingInfo
+{
+ internal TdsEnvChangeRoutingInfo(byte protocol, ushort port, string serverName, string databaseName = null)
+ {
+ Protocol = protocol;
+ Port = port;
+ ServerName = serverName;
+ DatabaseName = databaseName;
+ }
+
+ ///
+ /// The DatabaseName property is only used when routing via an EnhancedRouting ENVCHANGE token.
+ /// It is not used when routing via the normal Routing ENVCHANGE token.
+ ///
+ internal string DatabaseName { get; private set; }
+
+ ///
+ /// Represents the port used for establishing a connection in a TDS routing environment.
+ ///
+ internal ushort Port { get; private set; }
+
+ ///
+ /// Represents the protocol used for routing in a Routing or EnhancedRouting ENVCHANGE token.
+ ///
+ // @TODO: Should this be an enum of protocol types?
+ internal byte Protocol { get; private set; }
+
+ ///
+ /// Specifies the name of the server involved in the routing process of the TDS environment.
+ ///
+ internal string ServerName { get; private set; }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsFedAuthInfoToken.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsFedAuthInfoToken.cs
new file mode 100644
index 0000000000..fc2509c6c0
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsFedAuthInfoToken.cs
@@ -0,0 +1,52 @@
+// 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.
+
+#nullable enable
+
+namespace Microsoft.Data.SqlClient.Parser.Tokens;
+
+///
+/// Represents a token used for Federated Authentication in TDS protocol communication.
+/// This corresponds with the SQLFEDAUTHINFO token in the TDS spec.
+///
+///
+/// The TdsFedAuthInfoToken encapsulates information required for Federated Authentication
+/// when establishing a connection with a SQL Server. It contains the Service Principal Name (SPN)
+/// and the Security Token Service (STS) URL required for obtaining authentication tokens.
+///
+internal sealed class TdsFedAuthInfoToken
+{
+ ///
+ /// Represents a token used for Federated Authentication in the TDS (Tabular Data Stream) protocol.
+ ///
+ ///
+ /// The TdsFedAuthInfoToken is responsible for encapsulating the Service Principal Name (SPN)
+ /// and Security Token Service (STS) URL, both of which are essential for Federated Authentication.
+ /// This token is used when negotiating secure connections with SQL Server instances.
+ ///
+ internal TdsFedAuthInfoToken(string spn, string stsUrl)
+ {
+ Spn = spn;
+ StsUrl = stsUrl;
+ }
+
+ ///
+ /// Gets the Service Principal Name (SPN) associated with the federated authentication token.
+ /// The server-provided SPN is passed to the authentication provider as the token resource.
+ ///
+ internal string Spn { get; }
+
+ ///
+ /// Gets the Security Token Service (STS) URL associated with the federated authentication token.
+ /// The STS URL is used to identify the authentication service endpoint responsible
+ /// for issuing security tokens in the federated authentication process.
+ ///
+ internal string StsUrl { get; }
+
+ ///
+ public override string ToString()
+ {
+ return $"SPN: {Spn}, STSURL: {StsUrl}";
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsReturnValueToken.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsReturnValueToken.cs
new file mode 100644
index 0000000000..b67358cb1f
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsReturnValueToken.cs
@@ -0,0 +1,37 @@
+// 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.
+
+namespace Microsoft.Data.SqlClient.Parser.Tokens;
+
+///
+/// Represents a token that encapsulates information about a return value from a SQL Server stored
+/// procedure or function. This represents the SQLRETURNVALUE token.
+///
+///
+/// This token is used internally by the TDS (Tabular Data Stream) parser to handle return values
+/// associated with parameters in TDS responses. It contains metadata describing the parameter and
+/// its value.
+///
+internal sealed class TdsReturnValueToken : TdsTypeInfo
+{
+ ///
+ /// Gets or sets the name of the parameter associated with a returned value.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryReadString.
+ internal string parameter;
+
+ ///
+/// Constructs a new instance of TdsReturnValueToken with the value initialized to a new
+ /// instance.
+ ///
+ internal TdsReturnValueToken() : base()
+ {
+ Value = new SqlBuffer();
+ }
+
+ ///
+ /// Gets the value associated with the return parameter token.
+ ///
+ internal SqlBuffer Value { get; }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/MultiPartTableName.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsTableName.cs
similarity index 57%
rename from src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/MultiPartTableName.cs
rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsTableName.cs
index 516eced6fd..73d1cb7582 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/MultiPartTableName.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsTableName.cs
@@ -7,15 +7,23 @@
namespace Microsoft.Data.SqlClient.Parser.Tokens;
-internal struct MultiPartTableName
+///
+/// Represents a TDS-specific table name, which may include server, catalog, schema, and table segments.
+///
+internal struct TdsTableName
{
+ internal static readonly TdsTableName Null = new([null, null, null, null]);
+
private string _multipartName;
private string _serverName;
private string _catalogName;
private string _schemaName;
private string _tableName;
- internal MultiPartTableName(string[] parts)
+ ///
+ /// Constructs a new instance from an array of name parts.
+ ///
+ internal TdsTableName(string[] parts)
{
_multipartName = null;
_serverName = parts[0];
@@ -24,8 +32,14 @@ internal MultiPartTableName(string[] parts)
_tableName = parts[3];
}
- internal MultiPartTableName(string multipartName)
+ ///
+ /// Constructs a new instance from a multipart name. This name must be parsed before its
+ /// constituent parts can be accessed.
+ ///
+ /// Multipart name.
+ internal TdsTableName(string multipartName)
{
+ // @TODO: Is it faster to just parse this now versus rather than check everytime the parts are accessed?
_multipartName = multipartName;
_serverName = null;
_catalogName = null;
@@ -33,6 +47,9 @@ internal MultiPartTableName(string multipartName)
_tableName = null;
}
+ ///
+ /// Gets or sets the server name associated with the TDS-specific table name.
+ ///
internal string ServerName
{
get
@@ -42,6 +59,10 @@ internal string ServerName
}
set { _serverName = value; }
}
+
+ ///
+ /// Gets or sets the catalog name segment of the TDS-specific table name.
+ ///
internal string CatalogName
{
get
@@ -51,6 +72,10 @@ internal string CatalogName
}
set { _catalogName = value; }
}
+
+ ///
+ /// Gets or sets the schema name associated with the TDS-specific table name.
+ ///
internal string SchemaName
{
get
@@ -60,6 +85,10 @@ internal string SchemaName
}
set { _schemaName = value; }
}
+
+ ///
+ /// Gets or sets the table name segment of the TDS-specific table representation.
+ ///
internal string TableName
{
get
@@ -74,7 +103,11 @@ private void ParseMultipartName()
{
if (_multipartName != null)
{
- string[] parts = MultipartIdentifier.ParseMultipartIdentifier(_multipartName, Strings.SQL_TDSParserTableName, false);
+ string[] parts = MultipartIdentifier.ParseMultipartIdentifier(
+ _multipartName,
+ Strings.SQL_TDSParserTableName,
+ throwOnEmptyMultipartIdentifier: false);
+
_serverName = parts[0];
_catalogName = parts[1];
_schemaName = parts[2];
@@ -82,6 +115,4 @@ private void ParseMultipartName()
_multipartName = null;
}
}
-
- internal static readonly MultiPartTableName Null = new(new string[] { null, null, null, null });
}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsTypeInfo.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsTypeInfo.cs
new file mode 100644
index 0000000000..1447d74298
--- /dev/null
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/TdsTypeInfo.cs
@@ -0,0 +1,180 @@
+// 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;
+using System.Data;
+using System.Text;
+
+namespace Microsoft.Data.SqlClient.Parser.Tokens;
+
+///
+/// Represents metadata information for a SQL Server TDS data type, including type properties and
+/// encoding settings. Provides functionality for handling encryption and normalization details.
+///
+internal class TdsTypeInfo
+{
+ [Flags]
+ private enum TdsTypeInfoFlags : byte
+ {
+ None = 0,
+ IsNullable = 1 << 1,
+ IsMultiValued = 1 << 2
+ }
+
+ ///
+ /// Represents the collation settings associated with character-based SQL Server types.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryRead*.
+ internal SqlCollation collation;
+
+
+ ///
+ /// Represents the length property associated with SQL Server type information. Used for
+ /// defining the size or limit of a data type within the TDS protocol.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryRead*.
+ internal int length;
+
+
+ ///
+ /// Specifies the numeric precision for a numeric SQL Server data type. Defaults to
+ /// UNKNOWN_PRECISION_SCALE when not explicitly set.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryRead*.
+ internal byte precision = TdsEnums.UNKNOWN_PRECISION_SCALE;
+
+
+ ///
+ /// Specifies the scale component of a numeric SQL Server type. Defaults to
+ /// UNKNOWN_PRECISION_SCALE when not explicitly set.
+ ///
+ // @TODO: This cannot be an auto property yet because this value is set via an out parameter in TryRead*.
+ internal byte scale = TdsEnums.UNKNOWN_PRECISION_SCALE; // give default of unknown (-1)
+
+ private TdsTypeInfoFlags flags;
+
+ internal TdsTypeInfo()
+ {
+ }
+
+ ///
+ /// Gets or sets the plaintext type information for the column if the column is encrypted.
+ ///
+ internal TdsTypeInfo BaseTypeInfo { get; set; }
+
+ ///
+ /// Gets or sets the encryption-related metadata associated with the SQL Server TDS data type.
+ ///
+ internal SqlCipherMetadata CipherMetadata { get; set; }
+
+ ///
+ /// Gets or sets the code page used for character encoding associated with the TDS data type
+ /// instance.
+ ///
+ internal int CodePage { get; set; }
+
+ ///
+ /// Represents the database type of the current instance.
+ ///
+ internal SqlDbType DbType { get; set; }
+
+ ///
+ /// Gets or sets the character encoding used for string data representation.
+ ///
+ internal Encoding Encoding { get; set; }
+
+ ///
+ /// Is the algorithm handle for the cipher encryption initialized?
+ ///
+ internal bool IsAlgorithmInitialized() => CipherMetadata?.IsAlgorithmInitialized() ?? false;
+
+ ///
+ /// Gets or sets whether the type described by the current instance is TCE encrypted.
+ ///
+ internal bool IsEncrypted { get; set; }
+
+ ///
+ /// Indicates whether the associated SQL Server TDS data type supports multiple values.
+ ///
+ public bool IsMultiValued
+ {
+ get => HasFlag(TdsTypeInfoFlags.IsMultiValued);
+ set => Set(TdsTypeInfoFlags.IsMultiValued, value);
+ }
+
+ ///
+ /// Indicates whether the associated database column allows null values.
+ ///
+ public bool IsNullable
+ {
+ get => HasFlag(TdsTypeInfoFlags.IsNullable);
+ set => Set(TdsTypeInfoFlags.IsNullable, value);
+ }
+
+ ///
+ /// Gets or sets the cached MetaType information associated with the current instance.
+ ///
+ internal MetaType MetaType { get; set; }
+
+ ///
+ /// Returns the normalization rule version byte.
+ ///
+ internal byte NormalizationRuleVersion => CipherMetadata?.NormalizationRuleVersion ?? 0x00;
+
+ ///
+ /// Gets or sets the TDS (Tabular Data Stream) type of the instance.
+ ///
+ internal byte TdsType { get; set; }
+
+ ///
+ /// Gets or sets the UDT metadata associated with this object.
+ ///
+ public SqlMetaDataUdt Udt { get; set; }
+
+ ///
+ /// Gets or sets the metadata for the XML schema collection associated with this data type.
+ ///
+ public SqlMetaDataXmlSchemaCollection XmlSchemaCollection { get; set; }
+
+ // @TODO: Can this be converted to Clone like all the other token types do?
+ internal virtual void CopyFrom(TdsTypeInfo original)
+ {
+ this.DbType = original.DbType;
+ this.TdsType = original.TdsType;
+ this.precision = original.precision;
+ this.scale = original.scale;
+ this.length = original.length;
+ this.collation = original.collation;
+ this.CodePage = original.CodePage;
+ this.Encoding = original.Encoding;
+ this.MetaType = original.MetaType;
+ this.flags = original.flags;
+
+ if (original.Udt != null)
+ {
+ Udt = new SqlMetaDataUdt();
+ Udt.CopyFrom(original.Udt);
+ }
+
+ if (original.XmlSchemaCollection != null)
+ {
+ XmlSchemaCollection = new SqlMetaDataXmlSchemaCollection();
+ XmlSchemaCollection.CopyFrom(original.XmlSchemaCollection);
+ }
+
+ this.IsEncrypted = original.IsEncrypted;
+ this.BaseTypeInfo = original.BaseTypeInfo;
+ this.CipherMetadata = original.CipherMetadata;
+ }
+
+ private bool HasFlag(TdsTypeInfoFlags flag)
+ {
+ return (flags & flag) != 0;
+ }
+
+ private void Set(TdsTypeInfoFlags flag, bool value)
+ {
+ flags = value ? flags | flag : flags & ~flag;
+ }
+}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/_SqlMetaData.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/_SqlMetaData.cs
deleted file mode 100644
index e83725184c..0000000000
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/_SqlMetaData.cs
+++ /dev/null
@@ -1,158 +0,0 @@
-// 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;
-using System.Data;
-
-namespace Microsoft.Data.SqlClient.Parser.Tokens;
-
-internal sealed class _SqlMetaData : SqlMetaDataPriv
-{
- [Flags]
- private enum _SqlMetadataFlags : int
- {
- None = 0,
-
- Updatable = 1 << 0,
- UpdateableUnknown = 1 << 1,
- IsDifferentName = 1 << 2,
- IsKey = 1 << 3,
- IsHidden = 1 << 4,
- IsExpression = 1 << 5,
- IsIdentity = 1 << 6,
- IsColumnSet = 1 << 7,
-
- IsUpdatableMask = (Updatable | UpdateableUnknown) // two bit field (0 is read only, 1 is updatable, 2 is updatability unknown)
- }
-
- internal string column;
- internal string baseColumn;
- internal MultiPartTableName multiPartTableName;
- internal readonly int ordinal;
- internal byte tableNum;
- internal byte op; // for altrow-columns only
- internal ushort operand; // for altrow-columns only
- private _SqlMetadataFlags flags;
-
- internal _SqlMetaData(int ordinal) : base()
- {
- this.ordinal = ordinal;
- }
-
- private bool HasFlag(_SqlMetadataFlags flag)
- {
- return (flags & flag) != 0;
- }
-
- internal string serverName
- {
- get
- {
- return multiPartTableName.ServerName;
- }
- }
- internal string catalogName
- {
- get
- {
- return multiPartTableName.CatalogName;
- }
- }
- internal string schemaName
- {
- get
- {
- return multiPartTableName.SchemaName;
- }
- }
- internal string tableName
- {
- get
- {
- return multiPartTableName.TableName;
- }
- }
-
- public byte Updatability
- {
- get => (byte)(flags & _SqlMetadataFlags.IsUpdatableMask);
- set => flags = (_SqlMetadataFlags)((value & (byte)_SqlMetadataFlags.IsUpdatableMask) | ((int)flags & ~(byte)_SqlMetadataFlags.IsUpdatableMask));
- }
-
- public bool IsReadOnly
- {
- get => !HasFlag(_SqlMetadataFlags.IsUpdatableMask);
- }
-
- public bool IsDifferentName
- {
- get => HasFlag(_SqlMetadataFlags.IsDifferentName);
- set => Set(_SqlMetadataFlags.IsDifferentName, value);
- }
-
- public bool IsKey
- {
- get => HasFlag(_SqlMetadataFlags.IsKey);
- set => Set(_SqlMetadataFlags.IsKey, value);
- }
-
- public bool IsHidden
- {
- get => HasFlag(_SqlMetadataFlags.IsHidden);
- set => Set(_SqlMetadataFlags.IsHidden, value);
- }
-
- public bool IsExpression
- {
- get => HasFlag(_SqlMetadataFlags.IsExpression);
- set => Set(_SqlMetadataFlags.IsExpression, value);
- }
-
- public bool IsIdentity
- {
- get => HasFlag(_SqlMetadataFlags.IsIdentity);
- set => Set(_SqlMetadataFlags.IsIdentity, value);
- }
-
- public bool IsColumnSet
- {
- get => HasFlag(_SqlMetadataFlags.IsColumnSet);
- set => Set(_SqlMetadataFlags.IsColumnSet, value);
- }
-
- private void Set(_SqlMetadataFlags flag, bool value)
- {
- flags = value ? flags | flag : flags & ~flag;
- }
-
- internal bool Is2008DateTimeType
- {
- get
- {
- return SqlDbType.Date == type || SqlDbType.Time == type || SqlDbType.DateTime2 == type || SqlDbType.DateTimeOffset == type;
- }
- }
-
- internal bool IsLargeUdt
- {
- get
- {
- return type == SqlDbType.Udt && length == int.MaxValue;
- }
- }
-
- public object Clone()
- {
- _SqlMetaData result = new _SqlMetaData(ordinal);
- result.CopyFrom(this);
- result.column = column;
- result.baseColumn = baseColumn;
- result.multiPartTableName = multiPartTableName;
- result.tableNum = tableNum;
- result.flags = flags;
- result.op = op;
- result.operand = operand;
- return result;
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/_SqlMetaDataSet.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/_SqlMetaDataSet.cs
deleted file mode 100644
index dbb420dc72..0000000000
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/_SqlMetaDataSet.cs
+++ /dev/null
@@ -1,144 +0,0 @@
-// 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.Collections.ObjectModel;
-using System.Data;
-using System.Data.Common;
-using System.Diagnostics;
-
-namespace Microsoft.Data.SqlClient.Parser.Tokens;
-
-internal sealed class _SqlMetaDataSet
-{
- internal readonly SqlTceCipherInfoTable cekTable; // table of "column encryption keys" used for this metadataset
- internal ushort id; // for altrow-columns only
-
- internal DataTable schemaTable;
- private readonly _SqlMetaData[] _metaDataArray;
- internal ReadOnlyCollection dbColumnSchema;
-
- private int _hiddenColumnCount;
- private int[] _visibleColumnMap;
-
- internal _SqlMetaDataSet(int count)
- {
- _hiddenColumnCount = -1;
- _metaDataArray = new _SqlMetaData[count];
- for (int i = 0; i < _metaDataArray.Length; ++i)
- {
- _metaDataArray[i] = new _SqlMetaData(i);
- }
- }
-
- internal _SqlMetaDataSet(int count, SqlTceCipherInfoTable cipherTable)
- : this(count)
- {
- cekTable = cipherTable;
- }
-
- private _SqlMetaDataSet(_SqlMetaDataSet original)
- {
- id = original.id;
- _hiddenColumnCount = original._hiddenColumnCount;
- _visibleColumnMap = original._visibleColumnMap;
- dbColumnSchema = original.dbColumnSchema;
- schemaTable = original.schemaTable;
- cekTable = original.cekTable;
-
- if (original._metaDataArray == null)
- {
- _metaDataArray = null;
- }
- else
- {
- _metaDataArray = new _SqlMetaData[original._metaDataArray.Length];
- for (int idx = 0; idx < _metaDataArray.Length; idx++)
- {
- _metaDataArray[idx] = (_SqlMetaData)original._metaDataArray[idx].Clone();
- }
- }
- }
-
- internal int Length
- {
- get
- {
- return _metaDataArray.Length;
- }
- }
-
- internal int VisibleColumnCount
- {
- get
- {
- if (_hiddenColumnCount == -1)
- {
- SetupHiddenColumns();
- }
- return Length - _hiddenColumnCount;
- }
- }
-
- internal _SqlMetaData this[int index]
- {
- get
- {
- return _metaDataArray[index];
- }
- set
- {
- Debug.Assert(value == null, "used only by SqlBulkCopy");
- _metaDataArray[index] = value;
- }
- }
-
- public int GetVisibleColumnIndex(int index)
- {
- if (_hiddenColumnCount == -1)
- {
- SetupHiddenColumns();
- }
- if (_visibleColumnMap is null)
- {
- return index;
- }
- else
- {
- return _visibleColumnMap[index];
- }
- }
-
- public _SqlMetaDataSet Clone()
- {
- return new _SqlMetaDataSet(this);
- }
-
- private void SetupHiddenColumns()
- {
- int hiddenColumnCount = 0;
- for (int index = 0; index < Length; index++)
- {
- if (_metaDataArray[index].IsHidden)
- {
- hiddenColumnCount += 1;
- }
- }
-
- if (hiddenColumnCount > 0)
- {
- int[] visibleColumnMap = new int[Length - hiddenColumnCount];
- int mapIndex = 0;
- for (int metaDataIndex = 0; metaDataIndex < Length; metaDataIndex++)
- {
- if (!_metaDataArray[metaDataIndex].IsHidden)
- {
- visibleColumnMap[mapIndex] = metaDataIndex;
- mapIndex += 1;
- }
- }
- _visibleColumnMap = visibleColumnMap;
- }
- _hiddenColumnCount = hiddenColumnCount;
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/_SqlMetaDataSetCollection.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/_SqlMetaDataSetCollection.cs
deleted file mode 100644
index 0c19c8ce58..0000000000
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/Parser/Tokens/_SqlMetaDataSetCollection.cs
+++ /dev/null
@@ -1,61 +0,0 @@
-// 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.Collections.Generic;
-using System.Diagnostics;
-
-namespace Microsoft.Data.SqlClient.Parser.Tokens;
-
-internal sealed class _SqlMetaDataSetCollection
-{
- private readonly List<_SqlMetaDataSet> _altMetaDataSetArray;
- internal _SqlMetaDataSet metaDataSet;
-
- internal _SqlMetaDataSetCollection()
- {
- _altMetaDataSetArray = new List<_SqlMetaDataSet>();
- }
-
- internal void SetAltMetaData(_SqlMetaDataSet altMetaDataSet)
- {
- // If altmetadata with same id is found, override it rather than adding a new one
- int newId = altMetaDataSet.id;
- for (int i = 0; i < _altMetaDataSetArray.Count; i++)
- {
- if (_altMetaDataSetArray[i].id == newId)
- {
- // override the existing metadata with the same id
- _altMetaDataSetArray[i] = altMetaDataSet;
- return;
- }
- }
-
- // if we did not find metadata to override, add as new
- _altMetaDataSetArray.Add(altMetaDataSet);
- }
-
- internal _SqlMetaDataSet GetAltMetaData(int id)
- {
- foreach (_SqlMetaDataSet altMetaDataSet in _altMetaDataSetArray)
- {
- if (altMetaDataSet.id == id)
- {
- return altMetaDataSet;
- }
- }
- Debug.Fail("Can't match up altMetaDataSet with given id");
- return null;
- }
-
- public object Clone()
- {
- _SqlMetaDataSetCollection result = new _SqlMetaDataSetCollection() { metaDataSet = metaDataSet?.Clone() };
-
- foreach (_SqlMetaDataSet set in _altMetaDataSetArray)
- {
- result._altMetaDataSetArray.Add(set.Clone());
- }
- return result;
- }
-}
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs
index 4dd0e5f3c4..66a19acbe4 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs
@@ -28,9 +28,9 @@ namespace Microsoft.Data.SqlClient
internal sealed class _ColumnMapping
{
internal readonly int _sourceColumnOrdinal;
- internal readonly _SqlMetaData _metadata;
+ internal readonly TdsColumnMetadata _metadata;
- internal _ColumnMapping(int columnId, _SqlMetaData metadata)
+ internal _ColumnMapping(int columnId, TdsColumnMetadata metadata)
{
_sourceColumnOrdinal = columnId;
_metadata = metadata;
@@ -54,10 +54,10 @@ internal Row(int rowCount)
// The controlling class for one result (metadata + rows)
internal sealed class Result
{
- private readonly _SqlMetaDataSet _metadata;
+ private readonly TdsColumnMetadataToken _metadata;
private readonly List _rowset;
- internal Result(_SqlMetaDataSet metadata)
+ internal Result(TdsColumnMetadataToken metadata)
{
_metadata = metadata;
_rowset = new List();
@@ -65,7 +65,7 @@ internal Result(_SqlMetaDataSet metadata)
internal int Count => _rowset.Count;
- internal _SqlMetaDataSet MetaData => _metadata;
+ internal TdsColumnMetadataToken MetaData => _metadata;
internal Row this[int index] => _rowset[index];
@@ -90,7 +90,7 @@ internal BulkCopySimpleResultSet()
// Callback function for the tdsparser
// (note that setting the metadata adds a resultset)
- internal void SetMetaData(_SqlMetaDataSet metadata)
+ internal void SetMetaData(TdsColumnMetadataToken metadata)
{
_resultSet = new Result(metadata);
_results.Add(_resultSet);
@@ -254,7 +254,7 @@ private int RowNumber
// Per-operation clone of the destination table metadata, used when CacheMetadata is
// enabled so that column-pruning in AnalyzeTargetAndCreateUpdateBulkCommand does not
// mutate the cached BulkCopySimpleResultSet.
- private _SqlMetaDataSet _operationMetaData;
+ private TdsColumnMetadataToken _operationMetaData;
#if DEBUG
internal static bool s_setAlwaysTaskOnWrite; //when set and in DEBUG mode, TdsParser::WriteBulkCopyValue will always return a task
@@ -700,7 +700,7 @@ private void CacheMetadataIfEnabled(BulkCopySimpleResultSet result)
// metaDataSet is passed in by the caller so that when CacheMetadata is enabled, the
// caller can supply a clone, allowing this method to null-prune unmatched/rejected
// columns freely without mutating the shared cache.
- private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet internalResults, _SqlMetaDataSet metaDataSet)
+ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet internalResults, TdsColumnMetadataToken metaDataSet)
{
Debug.Assert(internalResults != null, "Where are the results from the initial query?");
Debug.Assert(metaDataSet != null, "metaDataSet must not be null");
@@ -797,7 +797,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
_sortedColumnMappings = new List<_ColumnMapping>(metaDataSet.Length);
for (int i = 0; i < metaDataSet.Length; i++)
{
- _SqlMetaData metadata = metaDataSet[i];
+ TdsColumnMetadata metadata = metaDataSet[i];
bool matched = false;
bool rejected = false;
@@ -809,7 +809,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
// Are we missing a mapping between the result column and
// this local column (by ordinal or name)?
- if (localColumn._destinationColumnOrdinal != metadata.ordinal
+ if (localColumn._destinationColumnOrdinal != metadata.Ordinal
&& UnquotedName(localColumn.MappedDestinationColumn) != metadata.column)
{
// Yes, so move on to the next local column.
@@ -827,7 +827,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
//
// We will not process timestamp or identity columns.
//
- if (metadata.type == SqlDbType.Timestamp
+ if (metadata.DbType == SqlDbType.Timestamp
|| (metadata.IsIdentity && !IsCopyOption(SqlBulkCopyOptions.KeepIdentity)))
{
rejected = true;
@@ -848,28 +848,28 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
}
// Some datatypes need special handling ...
- if (metadata.type == SqlDbType.Variant)
+ if (metadata.DbType == SqlDbType.Variant)
{
AppendColumnNameAndTypeName(updateBulkCommandText, metadata.column, "sql_variant");
}
- else if (metadata.type == SqlDbType.Udt)
+ else if (metadata.DbType == SqlDbType.Udt)
{
AppendColumnNameAndTypeName(updateBulkCommandText, metadata.column, "varbinary");
}
- else if (metadata.type == SqlDbTypeExtensions.Json)
+ else if (metadata.DbType == SqlDbTypeExtensions.Json)
{
AppendColumnNameAndTypeName(updateBulkCommandText, metadata.column, "json");
}
- else if (metadata.type == SqlDbTypeExtensions.Vector)
+ else if (metadata.DbType == SqlDbTypeExtensions.Vector)
{
AppendColumnNameAndTypeName(updateBulkCommandText, metadata.column, "vector");
}
else
{
- AppendColumnNameAndTypeName(updateBulkCommandText, metadata.column, metadata.type.ToString());
+ AppendColumnNameAndTypeName(updateBulkCommandText, metadata.column, metadata.DbType.ToString());
}
- switch (metadata.metaType.NullableType)
+ switch (metadata.MetaType.NullableType)
{
case TdsEnums.SQLNUMERICN:
case TdsEnums.SQLDECIMALN:
@@ -898,10 +898,10 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
default:
{
// For non-long non-fixed types we need to add the Size
- if (!metadata.metaType.IsFixed && !metadata.metaType.IsLong)
+ if (!metadata.MetaType.IsFixed && !metadata.MetaType.IsLong)
{
int size = metadata.length;
- switch (metadata.metaType.NullableType)
+ switch (metadata.MetaType.NullableType)
{
case TdsEnums.SQLNCHAR:
case TdsEnums.SQLNVARCHAR:
@@ -916,7 +916,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
}
updateBulkCommandText.AppendFormat((IFormatProvider)null, "({0})", size);
}
- else if (metadata.metaType.IsPlp && !(metadata.metaType.SqlDbType is SqlDbType.Xml or SqlDbTypeExtensions.Json or SqlDbTypeExtensions.Vector))
+ else if (metadata.MetaType.IsPlp && !(metadata.MetaType.SqlDbType is SqlDbType.Xml or SqlDbTypeExtensions.Json or SqlDbTypeExtensions.Vector))
{
// Partial length column prefix (max)
updateBulkCommandText.Append("(max)");
@@ -930,7 +930,7 @@ private string AnalyzeTargetAndCreateUpdateBulkCommand(BulkCopySimpleResultSet i
object rowvalue = rowset[i][CollationId];
bool shouldSendCollation;
- switch (metadata.type)
+ switch (metadata.DbType)
{
case SqlDbType.Char:
case SqlDbType.NChar:
@@ -1090,7 +1090,7 @@ private void WriteMetaData(BulkCopySimpleResultSet internalResults)
{
_stateObj.SetTimeoutSeconds(BulkCopyTimeout);
- _SqlMetaDataSet metadataCollection = _operationMetaData ?? internalResults[MetaDataResultId].MetaData;
+ TdsColumnMetadataToken metadataCollection = _operationMetaData ?? internalResults[MetaDataResultId].MetaData;
_stateObj._outputMessageType = TdsEnums.MT_BULK;
_parser.WriteBulkCopyMetaData(metadataCollection, _sortedColumnMappings.Count, _stateObj);
}
@@ -1161,7 +1161,7 @@ private void Dispose(bool disposing)
// Unified method to read a value from the current row
private object GetValueFromSourceRow(int destRowIndex, out bool isSqlType, out bool isDataFeed, out bool isNull)
{
- _SqlMetaData metadata = _sortedColumnMappings[destRowIndex]._metadata;
+ TdsColumnMetadata metadata = _sortedColumnMappings[destRowIndex]._metadata;
int sourceOrdinal = _sortedColumnMappings[destRowIndex]._sourceColumnOrdinal;
switch (_rowSourceType)
@@ -1240,7 +1240,7 @@ private object GetValueFromSourceRow(int destRowIndex, out bool isSqlType, out b
object value = _sqlDataReaderRowSource.GetValue(sourceOrdinal);
isNull = ((value == null) || (value == DBNull.Value));
- if ((!isNull) && (metadata.type == SqlDbType.Udt))
+ if ((!isNull) && (metadata.DbType == SqlDbType.Udt))
{
var columnAsINullable = value as INullable;
isNull = (columnAsINullable != null) && columnAsINullable.IsNull;
@@ -1437,14 +1437,14 @@ private bool ReadFromRowSource()
private SourceColumnMetadata GetColumnMetadata(int ordinal)
{
int sourceOrdinal = _sortedColumnMappings[ordinal]._sourceColumnOrdinal;
- _SqlMetaData metadata = _sortedColumnMappings[ordinal]._metadata;
+ TdsColumnMetadata metadata = _sortedColumnMappings[ordinal]._metadata;
// Handle special Sql data types for SqlDataReader and DataTables
ValueMethod method;
bool isSqlType;
bool isDataFeed;
- if (((_sqlDataReaderRowSource != null) || (_dataTableSource != null)) && ((metadata.metaType.NullableType == TdsEnums.SQLDECIMALN) || (metadata.metaType.NullableType == TdsEnums.SQLNUMERICN)))
+ if (((_sqlDataReaderRowSource != null) || (_dataTableSource != null)) && ((metadata.MetaType.NullableType == TdsEnums.SQLDECIMALN) || (metadata.MetaType.NullableType == TdsEnums.SQLNUMERICN)))
{
isDataFeed = false;
@@ -1487,28 +1487,28 @@ private SourceColumnMetadata GetColumnMetadata(int ordinal)
}
}
// Check for data streams
- else if (_enableStreaming && (metadata.length == MAX_LENGTH || metadata.metaType.SqlDbType == SqlDbTypeExtensions.Json))
+ else if (_enableStreaming && (metadata.length == MAX_LENGTH || metadata.MetaType.SqlDbType == SqlDbTypeExtensions.Json))
{
isSqlType = false;
if (_sqlDataReaderRowSource != null)
{
// MetaData property is not set for SMI, but since streaming is disabled we do not need it
- MetaType mtSource = _sqlDataReaderRowSource.MetaData[sourceOrdinal].metaType;
+ MetaType mtSource = _sqlDataReaderRowSource.MetaData[sourceOrdinal].MetaType;
// There is no memory gain for non-sequential access for binary
- if ((metadata.type == SqlDbType.VarBinary) && (mtSource.IsBinType) && (mtSource.SqlDbType != SqlDbType.Timestamp) && _sqlDataReaderRowSource.IsCommandBehavior(CommandBehavior.SequentialAccess))
+ if ((metadata.DbType == SqlDbType.VarBinary) && (mtSource.IsBinType) && (mtSource.SqlDbType != SqlDbType.Timestamp) && _sqlDataReaderRowSource.IsCommandBehavior(CommandBehavior.SequentialAccess))
{
isDataFeed = true;
method = ValueMethod.DataFeedStream;
}
// For text and XML there is memory gain from streaming on destination side even if reader is non-sequential
- else if ((metadata.type is SqlDbType.VarChar or SqlDbType.NVarChar or SqlDbTypeExtensions.Json) && mtSource.IsCharType && mtSource.SqlDbType != SqlDbType.Xml)
+ else if ((metadata.DbType is SqlDbType.VarChar or SqlDbType.NVarChar or SqlDbTypeExtensions.Json) && mtSource.IsCharType && mtSource.SqlDbType != SqlDbType.Xml)
{
isDataFeed = true;
method = ValueMethod.DataFeedText;
}
- else if ((metadata.type == SqlDbType.Xml) && (mtSource.SqlDbType == SqlDbType.Xml))
+ else if ((metadata.DbType == SqlDbType.Xml) && (mtSource.SqlDbType == SqlDbType.Xml))
{
isDataFeed = true;
method = ValueMethod.DataFeedXml;
@@ -1521,12 +1521,12 @@ private SourceColumnMetadata GetColumnMetadata(int ordinal)
}
else if (_dbDataReaderRowSource != null)
{
- if (metadata.type == SqlDbType.VarBinary)
+ if (metadata.DbType == SqlDbType.VarBinary)
{
isDataFeed = true;
method = ValueMethod.DataFeedStream;
}
- else if ((metadata.type == SqlDbType.VarChar) || (metadata.type == SqlDbType.NVarChar))
+ else if ((metadata.DbType == SqlDbType.VarChar) || (metadata.DbType == SqlDbType.NVarChar))
{
isDataFeed = true;
method = ValueMethod.DataFeedText;
@@ -1756,7 +1756,7 @@ private object ValidateBulkCopyVariant(object value)
}
}
- private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, ref bool isSqlType, out bool coercedToDataFeed)
+ private object ConvertValue(object value, TdsColumnMetadata metadata, bool isNull, ref bool isSqlType, out bool coercedToDataFeed)
{
coercedToDataFeed = false;
@@ -1769,7 +1769,7 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re
return value;
}
- MetaType type = metadata.metaType;
+ MetaType type = metadata.MetaType;
bool typeChanged = false;
// If the column is encrypted then we are going to transparently encrypt this column
@@ -1779,13 +1779,13 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re
byte scale = metadata.scale;
byte precision = metadata.precision;
int length = metadata.length;
- if (metadata.isEncrypted)
+ if (metadata.IsEncrypted)
{
Debug.Assert(_parser.ShouldEncryptValuesForBulkCopy());
- type = metadata.baseTI.metaType;
- scale = metadata.baseTI.scale;
- precision = metadata.baseTI.precision;
- length = metadata.baseTI.length;
+ type = metadata.BaseTypeInfo.MetaType;
+ scale = metadata.BaseTypeInfo.scale;
+ precision = metadata.BaseTypeInfo.precision;
+ length = metadata.BaseTypeInfo.length;
}
try
@@ -1826,11 +1826,11 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re
}
catch (SqlTruncateException)
{
- throw SQL.BulkLoadCannotConvertValue(value.GetType(), mt, metadata.ordinal, RowNumber, metadata.isEncrypted, metadata.column, value.ToString(), ADP.ParameterValueOutOfRange(sqlValue));
+ throw SQL.BulkLoadCannotConvertValue(value.GetType(), mt, metadata.Ordinal, RowNumber, metadata.IsEncrypted, metadata.column, value.ToString(), ADP.ParameterValueOutOfRange(sqlValue));
}
catch (Exception e)
{
- throw SQL.BulkLoadCannotConvertValue(value.GetType(), mt, metadata.ordinal, RowNumber, metadata.isEncrypted, metadata.column, value.ToString(), e);
+ throw SQL.BulkLoadCannotConvertValue(value.GetType(), mt, metadata.Ordinal, RowNumber, metadata.IsEncrypted, metadata.column, value.ToString(), e);
}
}
@@ -1876,7 +1876,7 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re
int maxStringLength = length / 2;
if (str.Length > maxStringLength)
{
- if (metadata.isEncrypted)
+ if (metadata.IsEncrypted)
{
str = "";
}
@@ -1921,7 +1921,7 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re
default:
Debug.Fail("Unknown TdsType!" + type.NullableType.ToString("x2", (IFormatProvider)null));
- throw SQL.BulkLoadCannotConvertValue(value.GetType(), type, metadata.ordinal, RowNumber, metadata.isEncrypted, metadata.column, value.ToString(), null);
+ throw SQL.BulkLoadCannotConvertValue(value.GetType(), type, metadata.Ordinal, RowNumber, metadata.IsEncrypted, metadata.column, value.ToString(), null);
}
if (typeChanged)
@@ -1934,7 +1934,7 @@ private object ConvertValue(object value, _SqlMetaData metadata, bool isNull, re
}
catch (Exception e) when (ADP.IsCatchableExceptionType(e))
{
- throw SQL.BulkLoadCannotConvertValue(value.GetType(), type, metadata.ordinal, RowNumber, metadata.isEncrypted, metadata.column, value.ToString(), e);
+ throw SQL.BulkLoadCannotConvertValue(value.GetType(), type, metadata.Ordinal, RowNumber, metadata.IsEncrypted, metadata.column, value.ToString(), e);
}
}
@@ -2505,14 +2505,14 @@ private Task ReadWriteColumnValueAsync(int col)
bool isNull;
object value = GetValueFromSourceRow(col, out isSqlType, out isDataFeed, out isNull); //this will return Task/null in future: as rTask
- _SqlMetaData metadata = _sortedColumnMappings[col]._metadata;
+ TdsColumnMetadata metadata = _sortedColumnMappings[col]._metadata;
if (!isDataFeed)
{
value = ConvertValue(value, metadata, isNull, ref isSqlType, out isDataFeed);
// If column encryption is requested via connection string option, perform encryption here
if (!isNull && // if value is not NULL
- metadata.isEncrypted)
+ metadata.IsEncrypted)
{ // If we are transparently encrypting
Debug.Assert(_parser.ShouldEncryptValuesForBulkCopy());
value = _parser.EncryptColumnValue(value, metadata, metadata.column, _stateObj, isDataFeed, isSqlType);
@@ -2522,7 +2522,7 @@ private Task ReadWriteColumnValueAsync(int col)
//write part
Task writeTask = null;
- if (metadata.type != SqlDbType.Variant)
+ if (metadata.DbType != SqlDbType.Variant)
{
//this is the most common path
writeTask = _parser.WriteBulkCopyValue(value, metadata, _stateObj, isSqlType, isDataFeed, isNull); //returns Task/Null
@@ -2530,7 +2530,7 @@ private Task ReadWriteColumnValueAsync(int col)
else
{
// Target type shouldn't be encrypted
- Debug.Assert(!metadata.isEncrypted, "Can't encrypt SQL Variant type");
+ Debug.Assert(!metadata.IsEncrypted, "Can't encrypt SQL Variant type");
SqlBuffer.StorageType variantInternalType = SqlBuffer.StorageType.Empty;
if ((_sqlDataReaderRowSource != null) && (_connection.Is2008OrNewer))
{
@@ -3101,7 +3101,7 @@ private void WriteToServerInternalRestContinuedAsync(BulkCopySimpleResultSet int
// CreateAndExecuteInitialQueryAsync). Clone the metadata set so that
// AnalyzeTargetAndCreateUpdateBulkCommand can null-prune unmatched/rejected
// columns without mutating the cache across WriteToServer calls.
- _SqlMetaDataSet metaDataSet = CachedMetadata != null
+ TdsColumnMetadataToken metaDataSet = CachedMetadata != null
? internalResults[MetaDataResultId].MetaData.Clone()
: internalResults[MetaDataResultId].MetaData;
updateBulkCommandText = AnalyzeTargetAndCreateUpdateBulkCommand(internalResults, metaDataSet);
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCachedBuffer.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCachedBuffer.cs
index 9d5fd35951..bd2797ae75 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCachedBuffer.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCachedBuffer.cs
@@ -37,7 +37,7 @@ private SqlCachedBuffer(List cachedBytes)
///
/// Reads off from the network buffer and caches bytes. Only reads one column value in the current row.
///
- internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser parser, TdsParserStateObject stateObj, out SqlCachedBuffer buffer)
+ internal static TdsOperationStatus TryCreate(TdsTypeInfo metadata, TdsParser parser, TdsParserStateObject stateObj, out SqlCachedBuffer buffer)
{
buffer = null;
@@ -67,7 +67,7 @@ internal static TdsOperationStatus TryCreate(SqlMetaDataPriv metadata, TdsParser
}
// For now we only handle Plp data from the parser directly.
- Debug.Assert(metadata.metaType.IsPlp, "SqlCachedBuffer call on a non-plp data");
+ Debug.Assert(metadata.MetaType.IsPlp, "SqlCachedBuffer call on a non-plp data");
do
{
if (plplength == 0)
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs
index 422f2bd778..ed9bc01d62 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlCommand.cs
@@ -176,7 +176,7 @@ public sealed partial class SqlCommand : DbCommand, ICloneable
///
/// Cut down on object creation and cache all the cached metadata
///
- private _SqlMetaDataSet _cachedMetaData;
+ private TdsColumnMetadataToken _cachedMetaData;
///
/// Column Encryption Override. Defaults to SqlConnectionSetting, in which case it will be
@@ -896,7 +896,7 @@ internal int InternalRecordsAffected
// @TODO: Autoproperty
// @TODO: MetaData or Metadata?
- internal _SqlMetaDataSet MetaData => _cachedMetaData;
+ internal TdsColumnMetadataToken MetaData => _cachedMetaData;
// @TODO: Rename to match conventions.
internal int ObjectID { get; } = Interlocked.Increment(ref _objectTypeCount);
@@ -1672,7 +1672,7 @@ internal void OnReturnStatus(int status)
}
}
- internal void OnReturnValue(SqlReturnValue returnValue, TdsParserStateObject stateObj)
+ internal void OnReturnValue(TdsReturnValueToken returnValue, TdsParserStateObject stateObj)
{
// Move the return value to the corresponding output parameter.
// Return parameters are sent in the order in which they were defined in the procedure.
@@ -1684,9 +1684,9 @@ internal void OnReturnValue(SqlReturnValue returnValue, TdsParserStateObject sta
if (_inPrepare)
{
// Store the returned prepare handle if we are returning from sp_prepare
- if (!returnValue.value.IsNull)
+ if (!returnValue.Value.IsNull)
{
- _prepareHandle = returnValue.value.Int32;
+ _prepareHandle = returnValue.Value.Int32;
}
_inPrepare = false;
@@ -1705,7 +1705,7 @@ internal void OnReturnValue(SqlReturnValue returnValue, TdsParserStateObject sta
// If the parameter's direction is InputOutput, Output, or ReturnValue and it needs
// to be transparently encrypted/decrypted, then simply decrypt, deserialize, and
// set the value.
- if (returnValue.cipherMD is not null &&
+ if (returnValue.CipherMetadata is not null &&
thisParam.CipherMetadata is not null &&
(thisParam.Direction == ParameterDirection.Output ||
thisParam.Direction == ParameterDirection.InputOutput ||
@@ -1713,11 +1713,11 @@ thisParam.CipherMetadata is not null &&
{
// @TODO: make this a separate method
// Validate type of the return value is valid for encryption
- if (returnValue.tdsType != TdsEnums.SQLBIGVARBINARY)
+ if (returnValue.TdsType != TdsEnums.SQLBIGVARBINARY)
{
throw SQL.InvalidDataTypeForEncryptedParameter(
thisParam.GetPrefixedParameterName(),
- returnValue.tdsType,
+ returnValue.TdsType,
expectedDataType: TdsEnums.SQLBIGVARBINARY);
}
@@ -1728,17 +1728,17 @@ thisParam.CipherMetadata is not null &&
throw ADP.ClosedConnectionError();
}
- if (!returnValue.value.IsNull)
+ if (!returnValue.Value.IsNull)
{
try
{
Debug.Assert(_activeConnection is not null, @"_activeConnection should not be null");
// Get the key information from the parameter and decrypt the value.
- returnValue.cipherMD.EncryptionInfo = thisParam.CipherMetadata.EncryptionInfo;
+ returnValue.CipherMetadata.EncryptionInfo = thisParam.CipherMetadata.EncryptionInfo;
byte[] unencryptedBytes = SqlSecurityUtility.DecryptWithKey(
- returnValue.value.ByteArray,
- returnValue.cipherMD,
+ returnValue.Value.ByteArray,
+ returnValue.CipherMetadata,
_activeConnection,
this);
@@ -1796,9 +1796,9 @@ thisParam.CipherMetadata is not null &&
_activeConnection.CheckGetExtendedUDTInfo(returnValue, fThrow: true);
// Extract the byte array from the param value
- object data = returnValue.value.IsNull
+ object data = returnValue.Value.IsNull
? DBNull.Value
- : returnValue.value.ByteArray;
+ : returnValue.Value.ByteArray;
// Call the connection to instantiate the UDT object
thisParam.Value = _activeConnection.GetUdtValue(data, returnValue, returnDBNull: false);
@@ -1814,13 +1814,13 @@ thisParam.CipherMetadata is not null &&
}
else
{
- thisParam.SetSqlBuffer(returnValue.value);
+ thisParam.SetSqlBuffer(returnValue.Value);
}
- // @TODO: This seems fishy to me, it seems like it should be part of the SqlReturnValue class
- MetaType mt = MetaType.GetMetaTypeFromSqlDbType(returnValue.type, isMultiValued: false);
+ // @TODO: This seems fishy to me, it seems like it should be part of the TdsReturnValueToken class
+ MetaType mt = MetaType.GetMetaTypeFromSqlDbType(returnValue.DbType, isMultiValued: false);
- if (returnValue.type is SqlDbType.Decimal)
+ if (returnValue.DbType is SqlDbType.Decimal)
{
thisParam.ScaleInternal = returnValue.scale;
thisParam.PrecisionInternal = returnValue.precision;
@@ -1829,7 +1829,7 @@ thisParam.CipherMetadata is not null &&
{
thisParam.ScaleInternal = returnValue.scale;
}
- else if (returnValue.type is SqlDbType.Xml)
+ else if (returnValue.DbType is SqlDbType.Xml)
{
if (thisParam.Value is SqlCachedBuffer cachedBuffer)
{
diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnection.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnection.cs
index 4f62234bce..038b04d7d1 100644
--- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnection.cs
+++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlConnection.cs
@@ -3092,23 +3092,23 @@ private Assembly ResolveTypeAssembly(AssemblyName asmRef, bool throwOnError)
}
}
- internal void CheckGetExtendedUDTInfo(SqlMetaDataPriv metaData, bool fThrow)
+ internal void CheckGetExtendedUDTInfo(TdsTypeInfo metaData, bool fThrow)
{
- if (metaData.udt?.Type == null)
+ if (metaData.Udt?.Type == null)
{ // If null, we have not obtained extended info.
- Debug.Assert(!string.IsNullOrEmpty(metaData.udt?.AssemblyQualifiedName), "Unexpected state on GetUDTInfo");
+ Debug.Assert(!string.IsNullOrEmpty(metaData.Udt?.AssemblyQualifiedName), "Unexpected state on GetUDTInfo");
// Parameter throwOnError determines whether exception from Assembly.Load is thrown.
- metaData.udt.Type =
- Type.GetType(typeName: metaData.udt.AssemblyQualifiedName, assemblyResolver: asmRef => ResolveTypeAssembly(asmRef, fThrow), typeResolver: null, throwOnError: fThrow);
+ metaData.Udt.Type =
+ Type.GetType(typeName: metaData.Udt.AssemblyQualifiedName, assemblyResolver: asmRef => ResolveTypeAssembly(asmRef, fThrow), typeResolver: null, throwOnError: fThrow);
- if (fThrow && metaData.udt.Type == null)
+ if (fThrow && metaData.Udt.Type == null)
{
- throw SQL.UDTUnexpectedResult(metaData.udt.AssemblyQualifiedName);
+ throw SQL.UDTUnexpectedResult(metaData.Udt.AssemblyQualifiedName);
}
}
}
- internal object GetUdtValue(object value, SqlMetaDataPriv metaData, bool returnDBNull)
+ internal object GetUdtValue(object value, TdsTypeInfo metaData, bool returnDBNull)
{
if (returnDBNull && ADP.IsNull(value))
{
@@ -3120,7 +3120,7 @@ internal object GetUdtValue(object value, SqlMetaDataPriv metaData, bool returnD
// Since the serializer doesn't handle nulls...
if (ADP.IsNull(value))
{
- Type t = metaData.udt?.Type;
+ Type t = metaData.Udt?.Type;
Debug.Assert(t != null, "Unexpected null of udtType on GetUdtValue!");
o = t.InvokeMember("Null", BindingFlags.Public | BindingFlags.GetProperty | BindingFlags.Static, null, null, Array.Empty