Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -919,6 +919,7 @@
<AutoGen>True</AutoGen>
<DependentUpon>Strings.resx</DependentUpon>
</Compile>
<Compile Include="Microsoft\Data\SqlTypes\SqlJson.cs" />
<EmbeddedResource Include="$(CommonSourceRoot)Resources\Strings.resx">
<Link>Resources\Strings.resx</Link>
<LogicalName>Microsoft.Data.SqlClient.Resources.Strings.resources</LogicalName>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6464,7 +6464,7 @@ internal string BuildParamList(TdsParser parser, SqlParameterCollection paramete
paramList.Append(size);
paramList.Append(')');
}
else if (mt.IsPlp && (mt.SqlDbType != SqlDbType.Xml) && (mt.SqlDbType != SqlDbType.Udt))
else if (mt.IsPlp && (mt.SqlDbType != SqlDbType.Xml) && (mt.SqlDbType != SqlDbType.Udt) && (mt.SqlDbType != (SqlDbType)35))
{
paramList.Append("(max) ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1365,6 +1365,8 @@ private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword,
// The SQLDNSCaching feature is implicitly set
requestedFeatures |= TdsEnums.FeatureExtension.SQLDNSCaching;

requestedFeatures |= TdsEnums.FeatureExtension.JsonSupport;

_parser.TdsLogin(login, requestedFeatures, _recoverySessionData, _fedAuthFeatureExtensionData, encrypt);
}

Expand Down Expand Up @@ -2812,6 +2814,24 @@ internal void OnFeatureExtAck(int featureId, byte[] data)
break;
}

case TdsEnums.FEATUREEXT_JSONSUPPORT:
{
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlInternalConnectionTds.OnFeatureExtAck|ADV> {0}, Received feature extension acknowledgement for JSONSUPPORT", ObjectID);
if (data.Length != 1)
{
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlInternalConnectionTds.OnFeatureExtAck|ERR> {0}, Unknown token for JSONSUPPORT", ObjectID);
throw SQL.ParsingError(ParsingErrorState.CorruptedTdsStream);
}
byte JsonSupportVersion = data[0];
if (JsonSupportVersion == 0 || JsonSupportVersion > 1)
{
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlInternalConnectionTds.OnFeatureExtAck|ERR> {0}, Invalid version number for JSONSUPPORT", ObjectID);
throw SQL.ParsingError();
}
_parser.IsJsonSupportEnabled = true;
break;
}

default:
{
// Unknown feature ack
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ internal static void Assert(string message)
/// </summary>
internal int DataClassificationVersion { get; set; }

internal bool IsJsonSupportEnabled = false;

private SqlCollation _cachedCollation;

internal TdsParser(bool MARS, bool fAsynchronous)
Expand Down Expand Up @@ -5703,6 +5705,7 @@ private bool TryReadSqlStringValue(SqlBuffer value, byte type, int length, Encod
case TdsEnums.SQLVARCHAR:
case TdsEnums.SQLBIGVARCHAR:
case TdsEnums.SQLTEXT:
case TdsEnums.SQLJSONTYPE:
// If bigvarchar(max), we only read the first chunk here,
// expecting the caller to read the rest
if (encoding == null)
Expand Down Expand Up @@ -6160,6 +6163,7 @@ internal bool TryReadSqlValue(SqlBuffer value, SqlMetaDataPriv md, int length, T
case TdsEnums.SQLNCHAR:
case TdsEnums.SQLNVARCHAR:
case TdsEnums.SQLNTEXT:
case TdsEnums.SQLJSONTYPE:
if (!TryReadSqlStringValue(value, tdsType, length, md.encoding, isPlp, stateObj))
{
return false;
Expand Down Expand Up @@ -7650,6 +7654,7 @@ internal bool TryGetDataLength(SqlMetaDataPriv colmeta, TdsParserStateObject sta
if (colmeta.metaType.IsPlp)
{
Debug.Assert(colmeta.tdsType == TdsEnums.SQLXMLTYPE ||
colmeta.tdsType == TdsEnums.SQLJSONTYPE ||
colmeta.tdsType == TdsEnums.SQLBIGVARCHAR ||
colmeta.tdsType == TdsEnums.SQLBIGVARBINARY ||
colmeta.tdsType == TdsEnums.SQLNVARCHAR ||
Expand Down Expand Up @@ -8106,6 +8111,21 @@ internal int WriteFedAuthFeatureRequest(FederatedAuthenticationFeatureExtensionD
return len;
}

internal int WriteJsonSupportFeatureRequest(bool write /* if false just calculates the length */)
{
int len = 6; // 1byte = featureID, 4bytes = featureData length, 1 bytes = Version

if (write)
{
// Write Feature ID
_physicalStateObj.WriteByte(TdsEnums.FEATUREEXT_JSONSUPPORT);
WriteInt(1, _physicalStateObj);
_physicalStateObj.WriteByte(1);
}

return len;
}

private void WriteLoginData(SqlLogin rec,
TdsEnums.FeatureExtension requestedFeatures,
SessionData recoverySessionData,
Expand Down Expand Up @@ -8416,6 +8436,11 @@ private int ApplyFeatureExData(TdsEnums.FeatureExtension requestedFeatures,
length += WriteSQLDNSCachingFeatureRequest(write);
}

if ((requestedFeatures & TdsEnums.FeatureExtension.JsonSupport) != 0)
{
length += WriteJsonSupportFeatureRequest(write);
}

length++; // for terminator
if (write)
{
Expand Down Expand Up @@ -11153,6 +11178,7 @@ private Task WriteUnterminatedSqlValue(object value, MetaType type, int actualLe
case TdsEnums.SQLNVARCHAR:
case TdsEnums.SQLNTEXT:
case TdsEnums.SQLXMLTYPE:
case TdsEnums.SQLJSONTYPE:

if (type.IsPlp)
{
Expand Down Expand Up @@ -11803,6 +11829,7 @@ private Task WriteUnterminatedValue(object value, MetaType type, byte scale, int
case TdsEnums.SQLNVARCHAR:
case TdsEnums.SQLNTEXT:
case TdsEnums.SQLXMLTYPE:
case TdsEnums.SQLJSONTYPE:
{
Debug.Assert(!isDataFeed || (value is TextDataFeed || value is XmlDataFeed), "Value must be a TextReader or XmlReader");
Debug.Assert(isDataFeed || (value is string || value is byte[]), "Value is a byte array or string");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Microsoft.Data.SqlClient
{
internal class SqlJson
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,7 @@
<Compile Include="Microsoft\Data\SqlClient\TdsParser.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserHelperClasses.cs" />
<Compile Include="Microsoft\Data\SqlClient\TdsParserStateObject.netfx.cs" />
<Compile Include="Microsoft\Data\SqlTypes\SqlJson.cs" />
<Compile Include="Microsoft\Data\SqlTypes\SqlFileStream.cs" />
<Compile Include="Microsoft\Data\SqlTypes\SqlStreamChars.cs" />
<Compile Include="Microsoft\Data\SqlTypes\SqlTypeWorkarounds.netfx.cs" />
Expand Down Expand Up @@ -764,6 +765,9 @@
<Version>$(SystemBuffersVersion)</Version>
</PackageReference>
</ItemGroup>
<ItemGroup>
<Folder Include="microsoft.data.sqlclient\netfx\src\microsoft\data\sqltypes\" />
</ItemGroup>
<Import Project="$(CommonSourceRoot)tools\targets\GenerateResourceStringsSource.targets" />
<Import Project="$(NetFxSource)tools\targets\GenerateThisAssemblyCs.targets" />
<Import Project="$(NetFxSource)tools\targets\GenerateAssemblyRef.targets" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7172,7 +7172,7 @@ internal string BuildParamList(TdsParser parser, SqlParameterCollection paramete
paramList.Append(size);
paramList.Append(')');
}
else if (mt.IsPlp && (mt.SqlDbType != SqlDbType.Xml) && (mt.SqlDbType != SqlDbType.Udt))
else if (mt.IsPlp && (mt.SqlDbType != SqlDbType.Xml) && (mt.SqlDbType != SqlDbType.Udt) && (mt.SqlDbType != (SqlDbType)35))
{
paramList.Append("(max) ");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1638,6 +1638,8 @@ private void Login(ServerInfo server, TimeoutTimer timeout, string newPassword,
// The SQLDNSCaching feature is implicitly set
requestedFeatures |= TdsEnums.FeatureExtension.SQLDNSCaching;

requestedFeatures |= TdsEnums.FeatureExtension.JsonSupport;

_parser.TdsLogin(login, requestedFeatures, _recoverySessionData, _fedAuthFeatureExtensionData, _originalNetworkAddressInfo, encrypt);
}

Expand Down Expand Up @@ -3239,6 +3241,24 @@ internal void OnFeatureExtAck(int featureId, byte[] data)
break;
}

case TdsEnums.FEATUREEXT_JSONSUPPORT:
{
SqlClientEventSource.Log.TryAdvancedTraceEvent("<sc.SqlInternalConnectionTds.OnFeatureExtAck|ADV> {0}, Received feature extension acknowledgement for JSONSUPPORT", ObjectID);
if (data.Length != 1)
{
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlInternalConnectionTds.OnFeatureExtAck|ERR> {0}, Unknown token for JSONSUPPORT", ObjectID);
throw SQL.ParsingError(ParsingErrorState.CorruptedTdsStream);
}
byte JsonSupportVersion = data[0];
if (JsonSupportVersion == 0 || JsonSupportVersion > 1)
{
SqlClientEventSource.Log.TryTraceEvent("<sc.SqlInternalConnectionTds.OnFeatureExtAck|ERR> {0}, Invalid version number for JSONSUPPORT", ObjectID);
throw SQL.ParsingError(ParsingErrorState.CorruptedTdsStream);
}
_parser.IsJsonSupportEnabled = true;
break;
}

default:
{
// Unknown feature ack
Expand Down
Loading