Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Add UDT support to System.Data.SqlClient. #25142

Merged
merged 3 commits into from
Nov 15, 2017
Merged
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
18 changes: 9 additions & 9 deletions pkg/Microsoft.Private.PackageBaseline/packageIndex.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,6 @@
"BaselineVersion": "2.0.0",
"InboxOn": {}
},
"Microsoft.Windows.Compatibility": {
"InboxOn": {}
},
"Microsoft.Windows.Compatibility.Shims": {
"InboxOn": {}
},
"Microsoft.Phone": {
"InboxOn": {
"wp8": "8.0.0.0"
Expand Down Expand Up @@ -277,6 +271,12 @@
"4.0.3.0": "4.5.0"
}
},
"Microsoft.Windows.Compatibility": {
"InboxOn": {}
},
"Microsoft.Windows.Compatibility.Shims": {
"InboxOn": {}
},
"Microsoft.XmlSerializer.Generator": {
"InboxOn": {},
"AssemblyVersionInPackageVersion": {
Expand Down Expand Up @@ -1193,7 +1193,7 @@
"net461": "4.1.0.0",
"monoandroid10": "Any",
"monotouch10": "Any",
"uap10.0.15138": "4.3.0.0",
"uap10.0.15138": "4.3.1.0",
"xamarinios10": "Any",
"xamarinmac20": "Any",
"xamarintvos10": "Any",
Expand All @@ -1204,7 +1204,7 @@
"4.1.0.0": "4.1.0",
"4.1.1.0": "4.3.0",
"4.2.0.0": "4.4.0",
"4.3.0.0": "4.5.0"
"4.3.1.0": "4.5.0"
}
},
"System.Data.SqlXml": {
Expand Down Expand Up @@ -5596,4 +5596,4 @@
"System.Xml.XDocument"
]
}
}
}
214 changes: 214 additions & 0 deletions src/System.Data.SqlClient/System.Data.SqlClient.sln

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/System.Data.SqlClient/dir.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="..\dir.props" />
<PropertyGroup>
<AssemblyVersion>4.3.0.0</AssemblyVersion>
<AssemblyVersion>4.3.1.0</AssemblyVersion>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For new APIs we generally bump the minor version.

<AssemblyKey>MSFT</AssemblyKey>
<IsUAP>true</IsUAP>
</PropertyGroup>
Expand Down
70 changes: 70 additions & 0 deletions src/System.Data.SqlClient/ref/System.Data.SqlClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

namespace Microsoft.SqlServer.Server
{
public sealed partial class InvalidUdtException : System.SystemException
{
internal InvalidUdtException() { }
}
public partial class SqlDataRecord : System.Data.IDataRecord
{
public SqlDataRecord(params Microsoft.SqlServer.Server.SqlMetaData[] metaData) { }
Expand Down Expand Up @@ -118,6 +122,28 @@ public virtual void SetTimeSpan(int ordinal, System.TimeSpan value) { }
public virtual void SetValue(int ordinal, object value) { }
public virtual int SetValues(params object[] values) { throw null; }
}
public enum DataAccessKind
{
None = 0,
Read = 1
}
public enum SystemDataAccessKind
{
None = 0,
Read = 1
}
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false), System.SerializableAttribute]
public partial class SqlFunctionAttribute : System.Attribute
{
public SqlFunctionAttribute() { }
public bool IsDeterministic { get { throw null; } set { } }
public DataAccessKind DataAccess { get { throw null; } set { } }
public SystemDataAccessKind SystemDataAccess { get { throw null; } set { } }
public bool IsPrecise { get { throw null; } set { } }
public string Name { get { throw null; } set { } }
public string TableDefinition { get { throw null; } set { } }
public string FillRowMethodName { get { throw null; } set { } }
}
public sealed partial class SqlMetaData
{
public SqlMetaData(string name, System.Data.SqlDbType dbType) { }
Expand Down Expand Up @@ -183,6 +209,49 @@ public SqlMetaData(string name, System.Data.SqlDbType dbType, string database, s
public System.TimeSpan Adjust(System.TimeSpan value) { throw null; }
public static Microsoft.SqlServer.Server.SqlMetaData InferFromValue(object value, string name) { throw null; }
}
[System.AttributeUsage(System.AttributeTargets.Method, AllowMultiple = false, Inherited = false), System.SerializableAttribute]
public sealed partial class SqlMethodAttribute : SqlFunctionAttribute
{
public SqlMethodAttribute() { }
public bool OnNullCall { get { throw null; } set { } }
public bool IsMutator { get { throw null; } set { } }
public bool InvokeIfReceiverIsNull { get { throw null; } set { } }
}
public enum Format
{
Unknown = 0,
Native = 1,
UserDefined = 2
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
public sealed partial class SqlUserDefinedAggregateAttribute : System.Attribute
{
public const int MaxByteSizeValue = 8000;
public SqlUserDefinedAggregateAttribute(Format format) { }
public int MaxByteSize { get { throw null; } set { } }
public bool IsInvariantToDuplicates { get { throw null; } set { } }
public bool IsInvariantToNulls { get { throw null; } set { } }
public bool IsInvariantToOrder { get { throw null; } set { } }
public bool IsNullIfEmpty { get { throw null; } set { } }
public Format Format { get { throw null; } }
public string Name { get { throw null; } set { } }
}
[System.AttributeUsage(System.AttributeTargets.Class | System.AttributeTargets.Struct, AllowMultiple = false, Inherited = true)]
public sealed partial class SqlUserDefinedTypeAttribute : System.Attribute
{
public SqlUserDefinedTypeAttribute(Format format) { }
public int MaxByteSize { get { throw null; } set { } }
public bool IsFixedLength { get { throw null; } set { } }
public bool IsByteOrdered { get { throw null; } set { } }
public Format Format { get { throw null; } }
public string ValidationMethodName { get { throw null; } set { } }
public string Name { get { throw null; } set { } }
}
public interface IBinarySerialize
{
void Read(System.IO.BinaryReader r);
void Write(System.IO.BinaryWriter w);
}
}
namespace System.Data.Sql
{
Expand Down Expand Up @@ -693,6 +762,7 @@ public SqlParameter(string parameterName, System.Data.SqlDbType dbType, int size
public override DataRowVersion SourceVersion { get { throw null; } set { } }
public System.Data.SqlDbType SqlDbType { get { throw null; } set { } }
public object SqlValue { get { throw null; } set { } }
public string UdtTypeName { get { throw null; } set { } }
public string TypeName { get { throw null; } set { } }
public override object Value { get { throw null; } set { } }
public string XmlSchemaCollectionDatabase { get { throw null; } set { } }
Expand Down
2 changes: 1 addition & 1 deletion src/System.Data.SqlClient/ref/System.Data.SqlClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<IsPartialFacadeAssembly Condition="'$(TargetGroup)' == 'netfx'">true</IsPartialFacadeAssembly>
<!-- Must match version supported by frameworks which support 4.3.* inbox.
Can be removed when API is added and this assembly is versioned to 4.4.* -->
<AssemblyVersion Condition="'$(TargetsNetFx)' != 'true'">4.3.0.0</AssemblyVersion>
<AssemblyVersion Condition="'$(TargetsNetFx)' != 'true'">4.3.1.0</AssemblyVersion>
Copy link
Member

@weshaggard weshaggard Dec 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As part of this work we need to think about how this works on platforms like UAP where the version is inbox. We likely need to start including the UAP build in the package as well.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Debug|AnyCPU'" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'netfx-Release|AnyCPU'" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ internal static bool IsPlpFormat(SmiMetaData metaData)
internal static ExtendedClrTypeCode DetermineExtendedTypeCodeForUseWithSqlDbType(
SqlDbType dbType,
bool isMultiValued,
object value
)
object value,
Type udtType)
{
ExtendedClrTypeCode extendedCode = ExtendedClrTypeCode.Invalid;

Expand Down Expand Up @@ -315,7 +315,16 @@ object value
}
break;
case SqlDbType.Udt:
throw ADP.DbTypeNotSupported(SqlDbType.Udt.ToString());
// Validate UDT type if caller gave us a type to validate against
if (null == udtType || value.GetType() == udtType)
{
extendedCode = ExtendedClrTypeCode.Object;
}
else
{
extendedCode = ExtendedClrTypeCode.Invalid;
}
break;
case SqlDbType.Time:
if (value.GetType() == typeof(TimeSpan))
extendedCode = ExtendedClrTypeCode.TimeSpan;
Expand Down Expand Up @@ -430,8 +439,8 @@ internal static SqlMetaData SmiExtendedMetaDataToSqlMetaData(SmiExtendedMetaData
source.TypeSpecificNamePart1,
source.TypeSpecificNamePart2,
source.TypeSpecificNamePart3,
true
);
true,
source.Type);
}

return new SqlMetaData(source.Name,
Expand Down Expand Up @@ -460,7 +469,40 @@ internal static SmiExtendedMetaData SqlMetaDataToSmiExtendedMetaData(SqlMetaData
}
else if (SqlDbType.Udt == source.SqlDbType)
{
throw ADP.DbTypeNotSupported(SqlDbType.Udt.ToString());
// Split the input name. UdtTypeName is specified as single 3 part name.
// NOTE: ParseUdtTypeName throws if format is incorrect
string typeName = source.ServerTypeName;
if (null != typeName)
{
string[] names = SqlParameter.ParseTypeName(typeName, true /* isUdtTypeName */);

if (1 == names.Length)
{
typeSpecificNamePart3 = names[0];
}
else if (2 == names.Length)
{
typeSpecificNamePart2 = names[0];
typeSpecificNamePart3 = names[1];
}
else if (3 == names.Length)
{
typeSpecificNamePart1 = names[0];
typeSpecificNamePart2 = names[1];
typeSpecificNamePart3 = names[2];
}
else
{
throw ADP.ArgumentOutOfRange(nameof(typeName));
}

if ((!string.IsNullOrEmpty(typeSpecificNamePart1) && TdsEnums.MAX_SERVERNAME < typeSpecificNamePart1.Length)
|| (!string.IsNullOrEmpty(typeSpecificNamePart2) && TdsEnums.MAX_SERVERNAME < typeSpecificNamePart2.Length)
|| (!string.IsNullOrEmpty(typeSpecificNamePart3) && TdsEnums.MAX_SERVERNAME < typeSpecificNamePart3.Length))
{
throw ADP.ArgumentOutOfRange(nameof(typeName));
}
}
}

return new SmiExtendedMetaData(source.SqlDbType,
Expand All @@ -469,6 +511,7 @@ internal static SmiExtendedMetaData SqlMetaDataToSmiExtendedMetaData(SqlMetaData
source.Scale,
source.LocaleId,
source.CompareOptions,
null,
source.Name,
typeSpecificNamePart1,
typeSpecificNamePart2,
Expand Down Expand Up @@ -603,6 +646,7 @@ internal static SmiExtendedMetaData SmiMetaDataFromDataColumn(DataColumn column,
scale,
columnLocale.LCID,
SmiMetaData.DefaultNVarChar.CompareOptions,
null,
false, // no support for multi-valued columns in a TVP yet
null, // no support for structured columns yet
null, // no support for structured columns yet
Expand Down Expand Up @@ -907,6 +951,7 @@ internal static SmiExtendedMetaData SmiMetaDataFromSchemaTableRow(DataRow schema
scale,
System.Globalization.CultureInfo.CurrentCulture.LCID,
SmiMetaData.GetDefaultForType(colDbType).CompareOptions,
null,
false, // no support for multi-valued columns in a TVP yet
null, // no support for structured columns yet
null, // no support for structured columns yet
Expand Down
Loading