Skip to content

Commit

Permalink
Allow large UDT buffers for netfx (#456)
Browse files Browse the repository at this point in the history
  • Loading branch information
alsicbv authored Apr 8, 2020
1 parent 0b8d7b5 commit 7ec2095
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,12 @@ static internal Exception UDTInvalidSqlType(string typeName)
{
return ADP.Argument(StringsHelper.GetString(Strings.SQLUDT_InvalidSqlType, typeName));
}

static internal Exception UDTInvalidSize(int maxSize, int maxSupportedSize)
{
throw ADP.ArgumentOutOfRange(StringsHelper.GetString(Strings.SQLUDT_InvalidSize, maxSize, maxSupportedSize));
}


static internal Exception InvalidSqlDbTypeForConstructor(SqlDbType type)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9980,10 +9980,12 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo

Debug.Assert(_isYukon, "Invalid DataType UDT for non-Yukon or later server!");

int maxSupportedSize = IsKatmaiOrNewer ? int.MaxValue : short.MaxValue;

if (!isNull)
{
// When writing UDT parameter values to the TDS stream, allow sending byte[] or SqlBytes
// directly to the server and not rejected as invalid. This allows users to handle
// directly to the server and not reject them as invalid. This allows users to handle
// serialization and deserialization logic without having to have SqlClient be aware of
// the types and without using inefficient text representations.
if (value is byte[] rawBytes)
Expand Down Expand Up @@ -10014,19 +10016,15 @@ internal Task TdsExecuteRPC(SqlCommand cmd, _SqlRPC[] rpcArray, int timeout, boo
size = udtVal.Length;

//it may be legitimate, but we dont support it yet
if (size < 0 || (size >= UInt16.MaxValue && maxsize != -1))
throw new IndexOutOfRangeException();
if (size < 0 || (size >= maxSupportedSize && maxsize != -1))
{
throw SQL.UDTInvalidSize(maxsize, maxSupportedSize);
}
}

//if this is NULL value, write special null value
byte[] lenBytes = BitConverter.GetBytes((Int64)size);

if (ADP.IsEmpty(param.UdtTypeName))
throw SQL.MustSetUdtTypeNameForUdtParams();

// Split the input name. TypeName is returned as single 3 part name during DeriveParameters.
// NOTE: ParseUdtTypeName throws if format is incorrect
String[] names = SqlParameter.ParseTypeName(param.UdtTypeName, true /* is UdtTypeName */);
String[] names = SqlParameter.ParseTypeName(param.UdtTypeName, isUdtTypeName: true);
if (!ADP.IsEmpty(names[0]) && TdsEnums.MAX_SERVERNAME < names[0].Length)
{
throw ADP.ArgumentOutOfRange("names");
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -4527,4 +4527,7 @@
<data name="TCE_AttestationProtocolNotSpecifiedForGeneratingEnclavePackage" xml:space="preserve">
<value>Error occurred when generating enclave package. Attestation Protocol has not been specified in the connection string, but the query requires enclave computations.</value>
</data>
</root>
<data name="SQLUDT_InvalidSize" xml:space="preserve">
<value>UDT size must be less than {1}, size: {0}</value>
</data>
</root>

0 comments on commit 7ec2095

Please sign in to comment.