Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@@ -0,0 +1,37 @@
//------------------------------------------------------------------------------
// <copyright file="IBinarySerialize.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
// <owner current="true" primary="true">alazela</owner>
// <owner current="true" primary="true">blained</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">stevesta</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">laled</owner>
// <owner current="true" primary="false">vadimt</owner>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Text;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Reflection.Emit;
using System.Data.SqlTypes;
namespace Microsoft.SqlServer.Server {
// This interface is used by types that want full control over the
// binary serialization format.
public interface IBinarySerialize {
// Read from the specified binary reader.
void Read(BinaryReader r);
// Write to the specified binary writer.
void Write(BinaryWriter w);
}
}

View File

@@ -0,0 +1,167 @@
//------------------------------------------------------------------------------
// <copyright file="SqlDataSourceEnumerator.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">[....]</owner>
//------------------------------------------------------------------------------
namespace System.Data.Sql {
using System;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Diagnostics;
using System.Globalization;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
public sealed class SqlDataSourceEnumerator : DbDataSourceEnumerator {
private static readonly SqlDataSourceEnumerator SingletonInstance = new SqlDataSourceEnumerator();
internal const string ServerName = "ServerName";
internal const string InstanceName = "InstanceName";
internal const string IsClustered = "IsClustered";
internal const string Version = "Version";
private const int timeoutSeconds = ADP.DefaultCommandTimeout;
private long timeoutTime; // variable used for timeout computations, holds the value of the hi-res performance counter at which this request should expire
private SqlDataSourceEnumerator() : base() {
}
public static SqlDataSourceEnumerator Instance {
get {
return SqlDataSourceEnumerator.SingletonInstance;
}
}
override public DataTable GetDataSources() {
#if MONO
throw new NotImplementedException ();
#else
(new NamedPermissionSet("FullTrust")).Demand(); // SQLBUDT 244304
char[] buffer = null;
StringBuilder strbldr = new StringBuilder();
Int32 bufferSize = 1024;
Int32 readLength = 0;
buffer = new char[bufferSize];
bool more = true;
bool failure = false;
IntPtr handle = ADP.PtrZero;
RuntimeHelpers.PrepareConstrainedRegions();
try {
timeoutTime = TdsParserStaticMethods.GetTimeoutSeconds(timeoutSeconds);
RuntimeHelpers.PrepareConstrainedRegions();
try {} finally {
handle = SNINativeMethodWrapper.SNIServerEnumOpen();
}
if (ADP.PtrZero != handle) {
while (more && !TdsParserStaticMethods.TimeoutHasExpired(timeoutTime)) {
readLength = SNINativeMethodWrapper.SNIServerEnumRead(handle, buffer, bufferSize, ref more);
if (readLength > bufferSize) {
failure = true;
more = false;
}
else if (0 < readLength) {
strbldr.Append(buffer, 0, readLength);
}
}
}
}
finally {
if (ADP.PtrZero != handle) {
SNINativeMethodWrapper.SNIServerEnumClose(handle);
}
}
if (failure) {
Debug.Assert(false, "GetDataSources:SNIServerEnumRead returned bad length");
Bid.Trace("<sc.SqlDataSourceEnumerator.GetDataSources|ERR> GetDataSources:SNIServerEnumRead returned bad length, requested %d, received %d", bufferSize, readLength);
throw ADP.ArgumentOutOfRange("readLength");
}
return ParseServerEnumString(strbldr.ToString());
#endif
}
private static string _Version = "Version:";
private static string _Cluster = "Clustered:";
private static int _clusterLength = _Cluster.Length;
private static int _versionLength =_Version.Length;
static private DataTable ParseServerEnumString(string serverInstances) {
DataTable dataTable = new DataTable("SqlDataSources");
dataTable.Locale = CultureInfo.InvariantCulture;
dataTable.Columns.Add(ServerName, typeof(string));
dataTable.Columns.Add(InstanceName, typeof(string));
dataTable.Columns.Add(IsClustered, typeof(string));
dataTable.Columns.Add(Version, typeof(string));
DataRow dataRow = null;
string serverName = null;
string instanceName = null;
string isClustered = null;
string version = null;
// Every row comes in the format "serverName\instanceName;Clustered:[Yes|No];Version:.."
// Every row is terminated by a null character.
// Process one row at a time
foreach (string instance in serverInstances.Split('\0')) {
string value = instance.Trim('\0'); // MDAC 91934
if (0 == value.Length) {
continue;
}
foreach (string instance2 in value.Split(';')) {
if (serverName == null) {
foreach(string instance3 in instance2.Split('\\')) {
if (serverName == null) {
serverName = instance3;
continue;
}
Debug.Assert(instanceName == null);
instanceName = instance3;
}
continue;
}
if (isClustered == null) {
Debug.Assert(String.Compare(_Cluster, 0, instance2, 0, _clusterLength, StringComparison.OrdinalIgnoreCase) == 0);
isClustered = instance2.Substring(_clusterLength);
continue;
}
Debug.Assert(version == null);
Debug.Assert(String.Compare(_Version, 0, instance2, 0, _versionLength, StringComparison.OrdinalIgnoreCase) == 0);
version = instance2.Substring(_versionLength);
}
string query = "ServerName='"+serverName+"'";
if (!ADP.IsEmpty(instanceName)) { // SQL BU DT 20006584: only append instanceName if present.
query += " AND InstanceName='"+instanceName+"'";
}
// SNI returns dupes - do not add them. SQL BU DT 290323
if (dataTable.Select(query).Length == 0) {
dataRow = dataTable.NewRow();
dataRow[0] = serverName;
dataRow[1] = instanceName;
dataRow[2] = isClustered;
dataRow[3] = version;
dataTable.Rows.Add(dataRow);
}
serverName = null;
instanceName = null;
isClustered = null;
version = null;
}
foreach(DataColumn column in dataTable.Columns) {
column.ReadOnly = true;
}
return dataTable;
}
}
}

View File

@@ -0,0 +1,81 @@
//------------------------------------------------------------------------------
// <copyright file="SqlFacetAttribute.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">[....]</owner>
// <owner current="true" primary="false">vadimt</owner>
//------------------------------------------------------------------------------
using System;
namespace Microsoft.SqlServer.Server {
[ AttributeUsage( AttributeTargets.Field | AttributeTargets.Property |
AttributeTargets.ReturnValue | AttributeTargets.Parameter,
AllowMultiple = false,
Inherited = false ) ]
public class SqlFacetAttribute: Attribute {
private bool m_IsFixedLength;
private int m_MaxSize;
private int m_Scale;
private int m_Precision;
private bool m_IsNullable;
// Is this a fixed size field?
public bool IsFixedLength {
get {
return this.m_IsFixedLength;
}
set {
this.m_IsFixedLength = value;
}
}
// The maximum size of the field (in bytes or characters depending on the field type)
// or -1 if the size can be unlimited.
public int MaxSize {
get {
return this.m_MaxSize;
}
set {
this.m_MaxSize = value;
}
}
// Precision, only valid for numeric types.
public int Precision {
get {
return this.m_Precision;
}
set {
this.m_Precision = value;
}
}
// Scale, only valid for numeric types.
public int Scale {
get {
return this.m_Scale;
}
set {
this.m_Scale = value;
}
}
// Is this field nullable?
public bool IsNullable {
get {
return this.m_IsNullable;
}
set {
this.m_IsNullable = value;
}
}
}
}

View File

@@ -0,0 +1,117 @@
//------------------------------------------------------------------------------
// <copyright file="SqlFunctionAttribute.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">[....]</owner>
// <owner current="true" primary="false">vadimt</owner>
//------------------------------------------------------------------------------
using System;
namespace Microsoft.SqlServer.Server {
[Serializable]
public enum DataAccessKind {
None = 0,
Read = 1,
}
[Serializable]
public enum SystemDataAccessKind {
None = 0,
Read = 1,
}
// sql specific attribute
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false), Serializable]
public class SqlFunctionAttribute : System.Attribute {
private bool m_fDeterministic;
private DataAccessKind m_eDataAccess;
private SystemDataAccessKind m_eSystemDataAccess;
private bool m_fPrecise;
private string m_fName;
private string m_fTableDefinition;
private string m_FillRowMethodName;
public SqlFunctionAttribute() {
// default values
m_fDeterministic = false;
m_eDataAccess = DataAccessKind.None;
m_eSystemDataAccess = SystemDataAccessKind.None;
m_fPrecise = false;
m_fName = null;
m_fTableDefinition = null;
m_FillRowMethodName = null;
} // SqlFunctionAttribute
public bool IsDeterministic {
get {
return m_fDeterministic;
}
set {
m_fDeterministic = value;
}
} // Deterministic
public DataAccessKind DataAccess {
get {
return m_eDataAccess;
}
set {
m_eDataAccess = value;
}
} // public bool DataAccessKind
public SystemDataAccessKind SystemDataAccess {
get {
return m_eSystemDataAccess;
}
set {
m_eSystemDataAccess = value;
}
} // public bool SystemDataAccessKind
public bool IsPrecise {
get {
return m_fPrecise;
}
set {
m_fPrecise = value;
}
} // Precise
public string Name {
get {
return m_fName;
}
set {
m_fName = value;
}
}
public string TableDefinition {
get {
return m_fTableDefinition;
}
set {
m_fTableDefinition = value;
}
}
public string FillRowMethodName {
get {
return m_FillRowMethodName;
}
set {
m_FillRowMethodName = value;
}
}
} // class SqlFunctionAttribute
}

View File

@@ -0,0 +1,36 @@
//------------------------------------------------------------------------------
// <copyright file="SqlGenericUtil.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">[....]</owner>
//------------------------------------------------------------------------------
namespace System.Data.Sql {
using System;
using System.Data;
using System.Data.Common;
using System.Diagnostics;
sealed internal class SqlGenericUtil {
private SqlGenericUtil() { /* prevent utility class from being insantiated*/ }
//
// Sql generic exceptions
//
//
// Sql.Definition
//
static internal Exception NullCommandText() {
return ADP.Argument(Res.GetString(Res.Sql_NullCommandText));
}
static internal Exception MismatchedMetaDataDirectionArrayLengths() {
return ADP.Argument(Res.GetString(Res.Sql_MismatchedMetaDataDirectionArrayLengths));
}
}
}//namespace

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,61 @@
//------------------------------------------------------------------------------
// <copyright file="SqlMethodAttribute.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">junfang</owner>
// <owner current="true" primary="false">[....]</owner>
// <owner current="true" primary="false">vadimt</owner>
//------------------------------------------------------------------------------
using System;
namespace Microsoft.SqlServer.Server {
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false), Serializable]
public sealed class SqlMethodAttribute : SqlFunctionAttribute {
private bool m_fCallOnNullInputs;
private bool m_fMutator;
private bool m_fInvokeIfReceiverIsNull;
public SqlMethodAttribute() {
// default values
m_fCallOnNullInputs = true;
m_fMutator = false;
m_fInvokeIfReceiverIsNull = false;
} // SqlMethodAttribute
public bool OnNullCall {
get {
return m_fCallOnNullInputs;
}
set {
m_fCallOnNullInputs = value;
}
} // CallOnNullInputs
public bool IsMutator {
get {
return m_fMutator;
}
set {
m_fMutator = value;
}
} // IsMutator
public bool InvokeIfReceiverIsNull {
get {
return m_fInvokeIfReceiverIsNull;
}
set {
m_fInvokeIfReceiverIsNull = value;
}
} // InvokeIfReceiverIsNull
} // class SqlMethodAttribute
}

View File

@@ -0,0 +1,68 @@
//------------------------------------------------------------------------------
// <copyright file="SqlNotificationRequest.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="false" primary="false">[....]</owner>
//------------------------------------------------------------------------------
namespace System.Data.Sql {
using System;
using System.Data.Common;
using System.Data.SqlClient;
// [System.ComponentModel.TypeConverterAttribute(typeof(System.Data.Sql.SqlNotificationRequest.SqlNotificationRequestConverter))]
public sealed class SqlNotificationRequest {
private string _userData;
private string _options;
private int _timeout;
public SqlNotificationRequest()
: this(null, null, SqlClient.SQL.SqlDependencyTimeoutDefault) {}
public SqlNotificationRequest(string userData, string options, int timeout) {
UserData = userData;
Timeout = timeout;
Options = options;
}
public string Options {
get {
return _options;
}
set {
if ((null != value) && (UInt16.MaxValue < value.Length)) {
throw ADP.ArgumentOutOfRange(String.Empty, ADP.ParameterService);
}
_options = value;
}
}
public int Timeout {
get {
return _timeout;
}
set {
if (0 > value) {
throw ADP.ArgumentOutOfRange(String.Empty, ADP.ParameterTimeout);
}
_timeout = value;
}
}
public string UserData {
get {
return _userData;
}
set {
if ((null != value) && (UInt16.MaxValue < value.Length)) {
throw ADP.ArgumentOutOfRange(String.Empty, ADP.ParameterUserData);
}
_userData = value;
}
}
}
}

View File

@@ -0,0 +1,38 @@
//------------------------------------------------------------------------------
// <copyright file="SqlProcedureAttribute.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">[....]</owner>
// <owner current="true" primary="false">vadimt</owner>
//------------------------------------------------------------------------------
using System;
namespace Microsoft.SqlServer.Server {
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false), Serializable]
public sealed class SqlProcedureAttribute : System.Attribute {
private string m_fName;
public SqlProcedureAttribute() {
// default values
m_fName = null;
}
public string Name {
get {
return m_fName;
}
set {
m_fName = value;
}
}
}
}

View File

@@ -0,0 +1,60 @@
//------------------------------------------------------------------------------
// <copyright file="SqlTriggerAttribute.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">[....]</owner>
// <owner current="true" primary="false">vadimt</owner>
//------------------------------------------------------------------------------
using System;
namespace Microsoft.SqlServer.Server {
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false), Serializable]
public sealed class SqlTriggerAttribute : System.Attribute {
private string m_fName;
private string m_fTarget;
private string m_fEvent;
public SqlTriggerAttribute() {
// default values
m_fName = null;
m_fTarget = null;
m_fEvent = null;
}
public string Name {
get {
return m_fName;
}
set {
m_fName = value;
}
}
public string Target {
get {
return m_fTarget;
}
set {
m_fTarget = value;
}
}
public string Event {
get {
return m_fEvent;
}
set {
m_fEvent = value;
}
}
}
}

View File

@@ -0,0 +1,120 @@
//------------------------------------------------------------------------------
// <copyright file="SqlUserDefinedAggregateAttribute.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">[....]</owner>
// <owner current="true" primary="false">vadimt</owner>
// <owner current="false" primary="false">venkar</owner>
// <owner current="false" primary="false">[....]</owner>
//------------------------------------------------------------------------------
namespace Microsoft.SqlServer.Server {
using System;
using System.Data;
using System.Data.Common;
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple=false, Inherited=false)]
public sealed class SqlUserDefinedAggregateAttribute: Attribute {
private int m_MaxByteSize;
private bool m_fInvariantToDup;
private bool m_fInvariantToNulls;
private bool m_fInvariantToOrder = true;
private bool m_fNullIfEmpty;
private Format m_format;
private string m_fName;
// The maximum value for the maxbytesize field, in bytes.
public const int MaxByteSizeValue = 8000;
// A required attribute on all udaggs, used to indicate that the
// given type is a udagg, and its storage format.
public SqlUserDefinedAggregateAttribute(Format format) {
switch(format) {
case Format.Unknown:
throw ADP.NotSupportedUserDefinedTypeSerializationFormat((Microsoft.SqlServer.Server.Format)format, "format");
case Format.Native:
case Format.UserDefined:
this.m_format = format;
break;
default:
throw ADP.InvalidUserDefinedTypeSerializationFormat((Microsoft.SqlServer.Server.Format)format);
}
}
// The maximum size of this instance, in bytes. Does not have to be
// specified for Native format serialization. The maximum value
// for this property is specified by MaxByteSizeValue.
public int MaxByteSize {
get {
return this.m_MaxByteSize;
}
set {
// MaxByteSize of -1 means 2GB and is valid, as well as 0 to MaxByteSizeValue
if (value < -1 || value > MaxByteSizeValue) {
throw ADP.ArgumentOutOfRange(Res.GetString(Res.SQLUDT_MaxByteSizeValue), "MaxByteSize", value);
}
this.m_MaxByteSize = value;
}
}
public bool IsInvariantToDuplicates {
get {
return this.m_fInvariantToDup;
}
set {
this.m_fInvariantToDup = value;
}
}
public bool IsInvariantToNulls {
get {
return this.m_fInvariantToNulls;
}
set {
this.m_fInvariantToNulls = value;
}
}
public bool IsInvariantToOrder {
get {
return this.m_fInvariantToOrder;
}
set {
this.m_fInvariantToOrder = value;
}
}
public bool IsNullIfEmpty {
get {
return this.m_fNullIfEmpty;
}
set {
this.m_fNullIfEmpty = value;
}
}
// The on-disk format for this type.
public Format Format {
get {
return this.m_format;
}
}
public string Name {
get {
return m_fName;
}
set {
m_fName = value;
}
}
}
}

View File

@@ -0,0 +1,128 @@
//------------------------------------------------------------------------------
// <copyright file="SqlUserDefinedTypeAttribute.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">[....]</owner>
// <owner current="true" primary="false">vadimt</owner>
// <owner current="false" primary="false">venkar</owner>
// <owner current="false" primary="false">[....]</owner>
//------------------------------------------------------------------------------
namespace Microsoft.SqlServer.Server {
using System;
using System.Data.Common;
public enum Format { //: byte
Unknown = 0,
Native = 1,
UserDefined = 2,
}
// This custom attribute indicates that the given type is
// a SqlServer udt. The properties on the attribute reflect the
// physical attributes that will be used when the type is registered
// with SqlServer.
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple=false, Inherited=true)]
public sealed class SqlUserDefinedTypeAttribute: Attribute {
private int m_MaxByteSize;
private bool m_IsFixedLength;
private bool m_IsByteOrdered;
private Format m_format;
private string m_fName;
// The maximum value for the maxbytesize field, in bytes.
internal const int YukonMaxByteSizeValue = 8000;
private String m_ValidationMethodName = null;
// A required attribute on all udts, used to indicate that the
// given type is a udt, and its storage format.
public SqlUserDefinedTypeAttribute(Format format) {
switch(format) {
case Format.Unknown:
throw ADP.NotSupportedUserDefinedTypeSerializationFormat((Microsoft.SqlServer.Server.Format)format, "format");
case Format.Native:
case Format.UserDefined:
this.m_format = format;
break;
default:
throw ADP.InvalidUserDefinedTypeSerializationFormat((Microsoft.SqlServer.Server.Format)format);
}
}
// The maximum size of this instance, in bytes. Does not have to be
// specified for Native serialization. The maximum value
// for this property is specified by MaxByteSizeValue.
public int MaxByteSize {
get {
return this.m_MaxByteSize;
}
set {
if (value < -1) {
throw ADP.ArgumentOutOfRange("MaxByteSize");
}
this.m_MaxByteSize = value;
}
}
// Are all instances of this udt the same size on disk?
public bool IsFixedLength {
get {
return this.m_IsFixedLength;
}
set {
this.m_IsFixedLength = value;
}
}
// Is this type byte ordered, i.e. is the on disk representation
// consistent with the ordering semantics for this type?
// If true, the binary representation of the type will be used
// in comparison by SqlServer. This property enables indexing on the
// udt and faster comparisons.
public bool IsByteOrdered {
get {
return this.m_IsByteOrdered;
}
set {
this.m_IsByteOrdered = value;
}
}
// The on-disk format for this type.
public Format Format {
get {
return this.m_format;
}
}
// An Optional method used to validate this UDT
// Signature: bool &lt;ValidationMethodName&gt;();
public String ValidationMethodName {
get
{
return this.m_ValidationMethodName;
}
set
{
this.m_ValidationMethodName = value;
}
}
public string Name {
get {
return m_fName;
}
set {
m_fName = value;
}
}
}
}

View File

@@ -0,0 +1,196 @@
//------------------------------------------------------------------------------
// <copyright file="TriggerAction.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">alazela</owner>
// <owner current="true" primary="true">blained</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">stevesta</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">laled</owner>
// <owner current="true" primary="false">vadimt</owner>
//------------------------------------------------------------------------------
namespace Microsoft.SqlServer.Server {
internal enum EMDEventType {
x_eet_Invalid = 0, // Not actually a valid type: not persisted.
x_eet_Insert = 1, // Insert (eg. on table/view)
x_eet_Update = 2, // Update (eg. on table/view)
x_eet_Delete = 3, // Delete (eg. on table/view)
x_eet_Create_Table = 21,
x_eet_Alter_Table = 22,
x_eet_Drop_Table = 23,
x_eet_Create_Index = 24,
x_eet_Alter_Index = 25,
x_eet_Drop_Index = 26,
x_eet_Create_Stats = 27,
x_eet_Update_Stats = 28,
x_eet_Drop_Stats = 29,
x_eet_Create_Secexpr = 31,
x_eet_Drop_Secexpr = 33,
x_eet_Create_Synonym = 34,
x_eet_Drop_Synonym = 36,
x_eet_Create_View = 41,
x_eet_Alter_View = 42,
x_eet_Drop_View = 43,
x_eet_Create_Procedure = 51,
x_eet_Alter_Procedure = 52,
x_eet_Drop_Procedure = 53,
x_eet_Create_Function = 61,
x_eet_Alter_Function = 62,
x_eet_Drop_Function = 63,
x_eet_Create_Trigger = 71, // On database/server/table
x_eet_Alter_Trigger = 72,
x_eet_Drop_Trigger = 73,
x_eet_Create_Event_Notification = 74,
x_eet_Drop_Event_Notification = 76,
x_eet_Create_Type = 91,
// x_eet_Alter_Type = 92,
x_eet_Drop_Type = 93,
x_eet_Create_Assembly = 101,
x_eet_Alter_Assembly = 102,
x_eet_Drop_Assembly = 103,
x_eet_Create_User = 131,
x_eet_Alter_User = 132,
x_eet_Drop_User = 133,
x_eet_Create_Role = 134,
x_eet_Alter_Role = 135,
x_eet_Drop_Role = 136,
x_eet_Create_AppRole = 137,
x_eet_Alter_AppRole = 138,
x_eet_Drop_AppRole = 139,
x_eet_Create_Schema = 141,
x_eet_Alter_Schema = 142,
x_eet_Drop_Schema = 143,
x_eet_Create_Login = 144,
x_eet_Alter_Login = 145,
x_eet_Drop_Login = 146,
x_eet_Create_MsgType = 151,
x_eet_Alter_MsgType = 152,
x_eet_Drop_MsgType = 153,
x_eet_Create_Contract = 154,
x_eet_Alter_Contract = 155,
x_eet_Drop_Contract = 156,
x_eet_Create_Queue = 157,
x_eet_Alter_Queue = 158,
x_eet_Drop_Queue = 159,
x_eet_Create_Service = 161,
x_eet_Alter_Service = 162,
x_eet_Drop_Service = 163,
x_eet_Create_Route = 164,
x_eet_Alter_Route = 165,
x_eet_Drop_Route = 166,
x_eet_Grant_Statement = 167,
x_eet_Deny_Statement = 168,
x_eet_Revoke_Statement = 169,
x_eet_Grant_Object = 170,
x_eet_Deny_Object = 171,
x_eet_Revoke_Object = 172,
x_eet_Activation = 173,
x_eet_Create_Binding = 174,
x_eet_Alter_Binding = 175,
x_eet_Drop_Binding = 176,
x_eet_Create_XmlSchema = 177,
x_eet_Alter_XmlSchema = 178,
x_eet_Drop_XmlSchema = 179,
x_eet_Create_HttpEndpoint = 181,
x_eet_Alter_HttpEndpoint = 182,
x_eet_Drop_HttpEndpoint = 183,
x_eet_Create_Partition_Function = 191,
x_eet_Alter_Partition_Function = 192,
x_eet_Drop_Partition_Function = 193,
x_eet_Create_Partition_Scheme = 194,
x_eet_Alter_Partition_Scheme = 195,
x_eet_Drop_Partition_Scheme = 196,
x_eet_Create_Database = 201,
x_eet_Alter_Database = 202,
x_eet_Drop_Database = 203,
// 1000 - 1999 is reserved for SQLTrace.
x_eet_Trace_Start = 1000,
x_eet_Trace_End = 1999,
// WHEN ADDING, PLEASE CHECK WITH FILE-OWNER FOR WHICH NUMBERS TO USE. THANKS!
};
public enum TriggerAction {
Invalid = EMDEventType.x_eet_Invalid,
Insert = EMDEventType.x_eet_Insert,
Update = EMDEventType.x_eet_Update,
Delete = EMDEventType.x_eet_Delete,
CreateTable = EMDEventType.x_eet_Create_Table,
AlterTable = EMDEventType.x_eet_Alter_Table,
DropTable = EMDEventType.x_eet_Drop_Table,
CreateIndex = EMDEventType.x_eet_Create_Index,
AlterIndex = EMDEventType.x_eet_Alter_Index,
DropIndex = EMDEventType.x_eet_Drop_Index,
CreateSynonym = EMDEventType.x_eet_Create_Synonym,
DropSynonym = EMDEventType.x_eet_Drop_Synonym,
CreateSecurityExpression = EMDEventType.x_eet_Create_Secexpr,
DropSecurityExpression = EMDEventType.x_eet_Drop_Secexpr,
CreateView = EMDEventType.x_eet_Create_View,
AlterView = EMDEventType.x_eet_Alter_View,
DropView = EMDEventType.x_eet_Drop_View,
CreateProcedure = EMDEventType.x_eet_Create_Procedure,
AlterProcedure = EMDEventType.x_eet_Alter_Procedure,
DropProcedure = EMDEventType.x_eet_Drop_Procedure,
CreateFunction = EMDEventType.x_eet_Create_Function,
AlterFunction = EMDEventType.x_eet_Alter_Function,
DropFunction = EMDEventType.x_eet_Drop_Function,
CreateTrigger = EMDEventType.x_eet_Create_Trigger,
AlterTrigger = EMDEventType.x_eet_Alter_Trigger,
DropTrigger = EMDEventType.x_eet_Drop_Trigger,
CreateEventNotification = EMDEventType.x_eet_Create_Event_Notification,
DropEventNotification = EMDEventType.x_eet_Drop_Event_Notification,
CreateType = EMDEventType.x_eet_Create_Type,
// Alter_Type = EMDEventType.x_eet_Alter_Type,
DropType = EMDEventType.x_eet_Drop_Type,
CreateAssembly = EMDEventType.x_eet_Create_Assembly,
AlterAssembly = EMDEventType.x_eet_Alter_Assembly,
DropAssembly = EMDEventType.x_eet_Drop_Assembly,
CreateUser = EMDEventType.x_eet_Create_User,
AlterUser = EMDEventType.x_eet_Alter_User,
DropUser = EMDEventType.x_eet_Drop_User,
CreateRole = EMDEventType.x_eet_Create_Role,
AlterRole = EMDEventType.x_eet_Alter_Role,
DropRole = EMDEventType.x_eet_Drop_Role,
CreateAppRole = EMDEventType.x_eet_Create_AppRole,
AlterAppRole = EMDEventType.x_eet_Alter_AppRole,
DropAppRole = EMDEventType.x_eet_Drop_AppRole,
CreateSchema = EMDEventType.x_eet_Create_Schema,
AlterSchema = EMDEventType.x_eet_Alter_Schema,
DropSchema = EMDEventType.x_eet_Drop_Schema,
CreateLogin = EMDEventType.x_eet_Create_Login,
AlterLogin = EMDEventType.x_eet_Alter_Login,
DropLogin = EMDEventType.x_eet_Drop_Login,
CreateMsgType = EMDEventType.x_eet_Create_MsgType,
DropMsgType = EMDEventType.x_eet_Drop_MsgType,
CreateContract = EMDEventType.x_eet_Create_Contract,
DropContract = EMDEventType.x_eet_Drop_Contract,
CreateQueue = EMDEventType.x_eet_Create_Queue,
AlterQueue = EMDEventType.x_eet_Alter_Queue,
DropQueue = EMDEventType.x_eet_Drop_Queue,
CreateService = EMDEventType.x_eet_Create_Service,
AlterService = EMDEventType.x_eet_Alter_Service,
DropService = EMDEventType.x_eet_Drop_Service,
CreateRoute = EMDEventType.x_eet_Create_Route,
AlterRoute = EMDEventType.x_eet_Alter_Route,
DropRoute = EMDEventType.x_eet_Drop_Route,
GrantStatement = EMDEventType.x_eet_Grant_Statement,
DenyStatement = EMDEventType.x_eet_Deny_Statement,
RevokeStatement = EMDEventType.x_eet_Revoke_Statement,
GrantObject = EMDEventType.x_eet_Grant_Object,
DenyObject = EMDEventType.x_eet_Deny_Object,
RevokeObject = EMDEventType.x_eet_Revoke_Object,
CreateBinding = EMDEventType.x_eet_Create_Binding,
AlterBinding = EMDEventType.x_eet_Alter_Binding,
DropBinding = EMDEventType.x_eet_Drop_Binding,
CreatePartitionFunction = EMDEventType.x_eet_Create_Partition_Function,
AlterPartitionFunction = EMDEventType.x_eet_Alter_Partition_Function,
DropPartitionFunction = EMDEventType.x_eet_Drop_Partition_Function,
CreatePartitionScheme = EMDEventType.x_eet_Create_Partition_Scheme,
AlterPartitionScheme = EMDEventType.x_eet_Alter_Partition_Scheme,
DropPartitionScheme = EMDEventType.x_eet_Drop_Partition_Scheme,
}
}

View File

@@ -0,0 +1,47 @@
//------------------------------------------------------------------------------
// <copyright file="InvalidUdtException.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">[....]</owner>
//------------------------------------------------------------------------------
using System;
using System.Data;
using System.Data.Common;
using System.Runtime.Serialization;
namespace Microsoft.SqlServer.Server {
[Serializable]
public sealed class InvalidUdtException : SystemException {
internal InvalidUdtException() : base() {
HResult = HResults.InvalidUdt;
}
internal InvalidUdtException(String message) : base(message) {
HResult = HResults.InvalidUdt;
}
internal InvalidUdtException(String message, Exception innerException) : base(message, innerException) {
HResult = HResults.InvalidUdt;
}
private InvalidUdtException(SerializationInfo si, StreamingContext sc) : base(si, sc) {
}
[System.Security.Permissions.SecurityPermissionAttribute(System.Security.Permissions.SecurityAction.LinkDemand, Flags=System.Security.Permissions.SecurityPermissionFlag.SerializationFormatter)]
public override void GetObjectData(SerializationInfo si, StreamingContext context) {
base.GetObjectData(si, context);
}
internal static InvalidUdtException Create(Type udtType, string resourceReason) {
string reason = Res.GetString(resourceReason);
string message = Res.GetString(Res.SqlUdt_InvalidUdtMessage, udtType.FullName, reason);
InvalidUdtException e = new InvalidUdtException(message);
ADP.TraceExceptionAsReturnValue(e);
return e;
}
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,258 @@
//------------------------------------------------------------------------------
// <copyright file="SqlSer.cs" company="Microsoft Corporation">
// Copyright (c) Microsoft Corporation. All Rights Reserved.
// Information Contained Herein is Proprietary and Confidential.
// </copyright>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="true">daltudov</owner>
// <owner current="true" primary="true">[....]</owner>
// <owner current="true" primary="false">beysims</owner>
// <owner current="true" primary="false">[....]</owner>
// <owner current="true" primary="false">vadimt</owner>
// <owner current="false" primary="false">venkar</owner>
// <owner current="false" primary="false">[....]</owner>
//------------------------------------------------------------------------------
using System;
using System.Collections;
using System.Data;
using System.Data.Common;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.InteropServices;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Runtime.CompilerServices;
namespace Microsoft.SqlServer.Server {
internal class SerializationHelperSql9 {
// Don't let anyone create an instance of this class.
private SerializationHelperSql9() {}
// Get the m_size of the serialized stream for this type, in bytes.
// This method creates an instance of the type using the public
// no-argument constructor, serializes it, and returns the m_size
// in bytes.
// Prevent inlining so that reflection calls are not moved to caller that may be in a different assembly that may have a different grant set.
[MethodImpl(MethodImplOptions.NoInlining)]
internal static int SizeInBytes(Type t) {
return SizeInBytes(Activator.CreateInstance(t));
}
// Get the m_size of the serialized stream for this type, in bytes.
internal static int SizeInBytes(object instance) {
Type t = instance.GetType();
Format k = GetFormat(t);
DummyStream stream = new DummyStream();
Serializer ser = GetSerializer(instance.GetType());
ser.Serialize(stream, instance);
return (int) stream.Length;
}
internal static void Serialize(Stream s, object instance) {
GetSerializer(instance.GetType()).Serialize(s, instance);
}
internal static object Deserialize(Stream s, Type resultType) {
return GetSerializer(resultType).Deserialize(s);
}
private static Format GetFormat(Type t) {
return GetUdtAttribute(t).Format;
}
//cache the relationship between a type and its serializer
//this is expensive to compute since it involves traversing the
//custom attributes of the type using reflection.
//
//use a per-thread cache, so that there are no synchronization
//issues when accessing cache entries from multiple threads.
[ThreadStatic]
private static Hashtable m_types2Serializers;
private static Serializer GetSerializer(Type t) {
if (m_types2Serializers == null)
m_types2Serializers = new Hashtable();
Serializer s = (Serializer) m_types2Serializers[t];
if (s == null) {
s = (Serializer) GetNewSerializer(t);
m_types2Serializers[t] = s;
}
return s;
}
internal static int GetUdtMaxLength(Type t) {
SqlUdtInfo udtInfo = SqlUdtInfo.GetFromType(t);
if (Format.Native == udtInfo.SerializationFormat) {
//In the native format, the user does not specify the
//max byte size, it is computed from the type definition
return SerializationHelperSql9.SizeInBytes(t);
}
else {
//In all other formats, the user specifies the maximum size in bytes.
return udtInfo.MaxByteSize;
}
}
private static object[] GetCustomAttributes (Type t) {
return t.GetCustomAttributes(typeof(SqlUserDefinedTypeAttribute), false);
}
internal static SqlUserDefinedTypeAttribute GetUdtAttribute(Type t) {
SqlUserDefinedTypeAttribute udtAttr = null;
object[] attr = GetCustomAttributes (t);
if (attr != null && attr.Length == 1) {
udtAttr = (SqlUserDefinedTypeAttribute) attr[0];
}
else {
throw InvalidUdtException.Create(t, Res.SqlUdtReason_NoUdtAttribute);
}
return udtAttr;
}
// Create a new serializer for the given type.
private static Serializer GetNewSerializer(Type t) {
SqlUserDefinedTypeAttribute udtAttr = GetUdtAttribute(t);
Format k = GetFormat(t);
switch (k) {
case Format.Native:
return new NormalizedSerializer(t);
case Format.UserDefined:
return new BinarySerializeSerializer(t);
case Format.Unknown: // should never happen, but fall through
default:
throw ADP.InvalidUserDefinedTypeSerializationFormat(k);
}
}
}
// The base serializer class.
internal abstract class Serializer {
public abstract object Deserialize(Stream s);
public abstract void Serialize(Stream s, object o);
protected Type m_type;
protected Serializer(Type t) {
this.m_type = t;
}
}
internal sealed class NormalizedSerializer: Serializer {
BinaryOrderedUdtNormalizer m_normalizer;
bool m_isFixedSize;
int m_maxSize;
internal NormalizedSerializer(Type t): base(t) {
SqlUserDefinedTypeAttribute udtAttr = SerializationHelperSql9.GetUdtAttribute(t);
this.m_normalizer = new BinaryOrderedUdtNormalizer(t, true);
this.m_isFixedSize = udtAttr.IsFixedLength;
this.m_maxSize = this.m_normalizer.Size;
}
public override void Serialize(Stream s, object o) {
m_normalizer.NormalizeTopObject(o, s);
}
public override object Deserialize(Stream s) {
object result = m_normalizer.DeNormalizeTopObject(this.m_type, s);
return result;
}
}
internal sealed class BinarySerializeSerializer: Serializer {
internal BinarySerializeSerializer(Type t): base(t) {
}
public override void Serialize(Stream s, object o) {
BinaryWriter w = new BinaryWriter(s);
((IBinarySerialize)o).Write(w);
}
// Prevent inlining so that reflection calls are not moved to caller that may be in a different assembly that may have a different grant set.
[MethodImpl(MethodImplOptions.NoInlining)]
public override object Deserialize(Stream s) {
object instance = Activator.CreateInstance(m_type);
BinaryReader r = new BinaryReader(s);
((IBinarySerialize)instance).Read(r);
return instance;
}
}
// A dummy stream class, used to get the number of bytes written
// to the stream.
internal sealed class DummyStream: Stream {
private long m_size;
public DummyStream() {
}
private void DontDoIt() {
throw new Exception(Res.GetString(Res.Sql_InternalError));
}
public override bool CanRead {
get {
return false;
}
}
public override bool CanWrite {
get {
return true;
}
}
public override bool CanSeek {
get {
return false;
}
}
public override long Position {
get {
return this.m_size;
}
set {
this.m_size = value;
}
}
public override long Length {
get {
return this.m_size;
}
}
public override void SetLength(long value) {
this.m_size = value;
}
public override long Seek(long value, SeekOrigin loc) {
DontDoIt();
return -1;
}
public override void Flush() {
}
public override int Read(byte[] buffer, int offset, int count) {
DontDoIt();
return -1;
}
public override void Write(byte[] buffer, int offset, int count) {
this.m_size += count;
}
}
}