From 0fae0a3784a5f85e907ddc6bb4fecda2521159ad Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Fri, 19 Jun 2020 13:26:17 +0100 Subject: [PATCH 1/4] shared more files and combine SqlBuffer changes where possible --- .../src/Microsoft.Data.SqlClient.csproj | 40 ++- .../Data/SqlClient/ApplicationIntent.cs | 16 -- .../Data/SqlClient/PoolBlockingPeriod.cs | 19 -- .../src/Microsoft/Data/SqlClient/SortOrder.cs | 20 -- .../SqlClient/SqlClientEncryptionAlgorithm.cs | 29 --- .../netfx/src/Microsoft.Data.SqlClient.csproj | 40 ++- .../Data/SqlClient/ApplicationIntent.cs | 21 -- .../Data/SqlClient/ParameterPeekAheadValue.cs | 29 --- .../Data/SqlClient/PoolBlockingPeriod.cs | 23 -- .../Data/SqlClient/RowsCopiedEventArgs.cs | 42 ---- .../Data/SqlClient/RowsCopiedEventHandler.cs | 9 - .../src/Microsoft/Data/SqlClient/SortOrder.cs | 19 -- .../Data/SqlClient/SqlAuthenticationToken.cs | 66 ----- .../src/Microsoft/Data/SqlClient/SqlBuffer.cs | 238 ++++++++++-------- ...SqlClientEncryptionAlgorithmFactoryList.cs | 85 ------- .../Data/SqlClient/ApplicationIntent.cs | 19 ++ .../Data/SqlClient/ParameterPeekAheadValue.cs | 0 .../Data/SqlClient/PoolBlockingPeriod.cs | 22 ++ .../Data/SqlClient/RowsCopiedEventArgs.cs | 8 +- .../Data/SqlClient/RowsCopiedEventHandler.cs | 2 +- .../src/Microsoft/Data/SqlClient/SortOrder.cs | 20 ++ .../Data/SqlClient/SqlAuthenticationToken.cs | 8 +- .../SqlClient/SqlBulkCopyColumnMapping.cs | 22 +- .../SqlClient/SqlClientEncryptionAlgorithm.cs | 0 ...SqlClientEncryptionAlgorithmFactoryList.cs | 0 25 files changed, 267 insertions(+), 530 deletions(-) delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SortOrder.cs delete mode 100644 src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithm.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ApplicationIntent.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ParameterPeekAheadValue.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SortOrder.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs delete mode 100644 src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ApplicationIntent.cs rename src/Microsoft.Data.SqlClient/{netcore => }/src/Microsoft/Data/SqlClient/ParameterPeekAheadValue.cs (100%) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs rename src/Microsoft.Data.SqlClient/{netcore => }/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs (53%) rename src/Microsoft.Data.SqlClient/{netcore => }/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs (62%) create mode 100644 src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SortOrder.cs rename src/Microsoft.Data.SqlClient/{netcore => }/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs (72%) rename src/Microsoft.Data.SqlClient/{netcore => }/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs (61%) rename src/Microsoft.Data.SqlClient/{netfx => }/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithm.cs (100%) rename src/Microsoft.Data.SqlClient/{netcore => }/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs (100%) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj index 4328cfeebc..b83ca8a3ec 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -60,6 +60,9 @@ Microsoft\Data\SqlClient\ActiveDirectoryAuthenticationTimeoutRetryHelper.cs + + Microsoft\Data\SqlClient\ApplicationIntent.cs + Microsoft\Data\SqlClient\ActiveDirectoryAuthenticationProvider.cs @@ -72,6 +75,24 @@ Microsoft\Data\SqlClient\OnChangedEventHandler.cs + + Microsoft\Data\SqlClient\ParameterPeekAheadValue.cs + + + Microsoft\Data\SqlClient\PoolBlockingPeriod.cs + + + Microsoft\Data\SqlClient\RowsCopiedEventArgs.cs + + + Microsoft\Data\SqlClient\RowsCopiedEventHandler.cs + + + Microsoft\Data\SqlClient\SortOrder.cs + + + Microsoft\Data\SqlClient\SqlAuthenticationToken.cs + Microsoft\Data\SqlClient\SqlAeadAes256CbcHmac256Algorithm.cs @@ -93,6 +114,9 @@ Microsoft\Data\SqlClient\SqlAuthenticationProvider.cs + + Microsoft\Data\SqlClient\SqlBulkCopyColumnMapping.cs + Microsoft\Data\SqlClient\SqlBulkCopyOptions.cs @@ -102,9 +126,15 @@ Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs + + Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs + Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithmFactory.cs + + Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithmFactoryList.cs + Microsoft\Data\SqlClient\SqlClientEncryptionType.cs @@ -166,7 +196,6 @@ - @@ -266,7 +295,6 @@ - @@ -275,15 +303,9 @@ - - - - - - @@ -366,10 +388,8 @@ - - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs deleted file mode 100644 index f8582d59e8..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ApplicationIntent.cs +++ /dev/null @@ -1,16 +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 -{ - /// - public enum ApplicationIntent - { - /// - ReadWrite = 0, - - /// - ReadOnly = 1, - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs deleted file mode 100644 index 4bfedeb1e9..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs +++ /dev/null @@ -1,19 +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 -{ - /// - public enum PoolBlockingPeriod - { - /// - Auto = 0, // Blocking period OFF for Azure SQL servers, but ON for all other SQL servers. - - /// - AlwaysBlock = 1, // Blocking period ON for all SQL servers including Azure SQL servers. - - /// - NeverBlock = 2, // Blocking period OFF for all SQL servers including Azure SQL servers. - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SortOrder.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SortOrder.cs deleted file mode 100644 index 4ce62535ef..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SortOrder.cs +++ /dev/null @@ -1,20 +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 -{ - /// - public enum SortOrder - { - /// - Unspecified = -1, - - /// - Ascending = 0, - - /// - Descending = 1 - } -} - diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithm.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithm.cs deleted file mode 100644 index 2f2b944cf7..0000000000 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithm.cs +++ /dev/null @@ -1,29 +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 -{ - - /// - /// Abstract base class for all TCE encryption algorithms. It exposes two functions - /// 1. Encrypt - This function is used by SqlClient under the covers to transparently encrypt TCE enabled column data. - /// 2. Decrypt - This function is used by SqlClient under the covers to transparently decrypt TCE enabled column data. - /// - internal abstract class SqlClientEncryptionAlgorithm - { - /// - /// Encrypts the plainText with a column encryption key - /// - /// Plain text value to be encrypted - /// - internal abstract byte[] EncryptData(byte[] plainText); - - /// - /// Decrypts the cipherText with a column encryption key - /// - /// Ciphertext value to be decrypted - /// - internal abstract byte[] DecryptData(byte[] cipherText); - } -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index f90f36784d..eabf4493c7 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -114,6 +114,9 @@ Microsoft\Data\SqlClient\ActiveDirectoryAuthenticationTimeoutRetryHelper.cs + + Microsoft\Data\SqlClient\ApplicationIntent.cs + Microsoft\Data\SqlClient\ActiveDirectoryAuthenticationProvider.cs @@ -126,6 +129,24 @@ Microsoft\Data\SqlClient\OnChangedEventHandler.cs + + Microsoft\Data\SqlClient\ParameterPeekAheadValue.cs + + + Microsoft\Data\SqlClient\PoolBlockingPeriod.cs + + + Microsoft\Data\SqlClient\RowsCopiedEventArgs.cs + + + Microsoft\Data\SqlClient\RowsCopiedEventHandler.cs + + + Microsoft\Data\SqlClient\SortOrder.cs + + + Microsoft\Data\SqlClient\SqlAuthenticationToken.cs + Microsoft\Data\SqlClient\SqlAeadAes256CbcHmac256Algorithm.cs @@ -147,6 +168,9 @@ Microsoft\Data\SqlClient\SqlAuthenticationProvider.cs + + Microsoft\Data\SqlClient\SqlBulkCopyColumnMapping.cs + Microsoft\Data\SqlClient\SqlBulkCopyOptions.cs @@ -156,9 +180,15 @@ Microsoft\Data\SqlClient\SqlBulkCopyColumnOrderHintCollection.cs + + Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithm.cs + Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithmFactory.cs + + Microsoft\Data\SqlClient\SqlClientEncryptionAlgorithmFactoryList.cs + Microsoft\Data\SqlClient\SqlClientEncryptionType.cs @@ -212,7 +242,6 @@ - @@ -221,8 +250,6 @@ - - @@ -232,26 +259,19 @@ - - - - - - - diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ApplicationIntent.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ApplicationIntent.cs deleted file mode 100644 index 792d738f55..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ApplicationIntent.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. - -using System; - -namespace Microsoft.Data.SqlClient -{ - - - /// - [Serializable] - public enum ApplicationIntent - { - /// - ReadWrite = 0, - - /// - ReadOnly = 1, - } -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ParameterPeekAheadValue.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ParameterPeekAheadValue.cs deleted file mode 100644 index 5da62e1106..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/ParameterPeekAheadValue.cs +++ /dev/null @@ -1,29 +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 Microsoft.Data.SqlClient.Server; - -namespace Microsoft.Data.SqlClient -{ - - // simple storage to contain objects that must be generated prior to sending data, but - // that we cannot re-generate at the time of sending the data. The entire purpose is - // to avoid long, complicated parameter lists that take every possible set of values. - // Instead, a single peekahead object is passed in, encapsulating whatever sets are needed. - // - // Example: - // When processing IEnumerable, we need to obtain the enumerator and - // the first record during metadata generation (metadata is stored in the first record), - // but to properly stream the value, we can't ask the IEnumerable for these objects again - // when it's time to send the actual values. - - internal class ParameterPeekAheadValue - { - // Peekahead for IEnumerable - internal IEnumerator Enumerator; - internal SqlDataRecord FirstRecord; - } - -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs deleted file mode 100644 index 35a2c5fb00..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs +++ /dev/null @@ -1,23 +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; - -namespace Microsoft.Data.SqlClient -{ - - /// - [Serializable] - public enum PoolBlockingPeriod - { - /// - Auto = 0, - - /// - AlwaysBlock = 1, - - /// - NeverBlock = 2, - } -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs deleted file mode 100644 index 434ba18d3a..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs +++ /dev/null @@ -1,42 +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 -{ - /// - public class SqlRowsCopiedEventArgs : System.EventArgs - { - private bool _abort; - private long _rowsCopied; - - /// - public SqlRowsCopiedEventArgs(long rowsCopied) - { - _rowsCopied = rowsCopied; - } - - /// - public bool Abort - { - get - { - return _abort; - } - set - { - _abort = value; - } - - } - - /// - public long RowsCopied - { - get - { - return _rowsCopied; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs deleted file mode 100644 index bf52260361..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs +++ /dev/null @@ -1,9 +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 -{ - /// - public delegate void SqlRowsCopiedEventHandler(object sender, SqlRowsCopiedEventArgs e); -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SortOrder.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SortOrder.cs deleted file mode 100644 index d07d406464..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SortOrder.cs +++ /dev/null @@ -1,19 +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 -{ - /// - public enum SortOrder - { - /// - Unspecified = -1, - - /// - Ascending = 0, - - /// - Descending = 1 - } -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs deleted file mode 100644 index 140e7c3b93..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs +++ /dev/null @@ -1,66 +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.Text; - -namespace Microsoft.Data.SqlClient -{ - - /// - public class SqlAuthenticationToken - { - /// - public DateTimeOffset ExpiresOn { get; } - - /// - public string AccessToken { get; } - - /// - public SqlAuthenticationToken(string accessToken, DateTimeOffset expiresOn) - { - if (string.IsNullOrEmpty(accessToken)) - throw SQL.ParameterCannotBeEmpty("AccessToken"); - - AccessToken = accessToken; - ExpiresOn = expiresOn; - } - - /// - /// Constructor. - /// - internal SqlAuthenticationToken(byte[] accessToken, DateTimeOffset expiresOn) - : this(AccessTokenStringFromBytes(accessToken), expiresOn) { } - - /// - /// Convert to driver's internal token class. - /// - internal SqlFedAuthToken ToSqlFedAuthToken() - { - var tokenBytes = AccessTokenBytesFromString(AccessToken); - return new SqlFedAuthToken - { - accessToken = tokenBytes, - dataLen = (uint)tokenBytes.Length, - expirationFileTime = ExpiresOn.ToFileTime() - }; - } - - /// - /// Convert token bytes to string. - /// - internal static string AccessTokenStringFromBytes(byte[] bytes) - { - return Encoding.Unicode.GetString(bytes); - } - - /// - /// Convert token string to bytes. - /// - internal static byte[] AccessTokenBytesFromString(string token) - { - return Encoding.Unicode.GetBytes(token); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBuffer.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBuffer.cs index c395c3cc2d..5f9575b1ec 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBuffer.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBuffer.cs @@ -14,7 +14,6 @@ namespace Microsoft.Data.SqlClient internal sealed class SqlBuffer { - internal enum StorageType { Empty = 0, @@ -42,55 +41,67 @@ internal enum StorageType internal struct DateTimeInfo { // This is used to store DateTime - internal Int32 daypart; - internal Int32 timepart; + internal int daypart; + internal int timepart; } internal struct NumericInfo { // This is used to store Decimal data - internal Int32 data1; - internal Int32 data2; - internal Int32 data3; - internal Int32 data4; - internal Byte precision; - internal Byte scale; - internal Boolean positive; + internal int data1; + internal int data2; + internal int data3; + internal int data4; + internal byte precision; + internal byte scale; + internal bool positive; } internal struct TimeInfo { - internal Int64 ticks; + internal long ticks; internal byte scale; } internal struct DateTime2Info { - internal Int32 date; + internal int date; internal TimeInfo timeInfo; } internal struct DateTimeOffsetInfo { internal DateTime2Info dateTime2Info; - internal Int16 offset; + internal short offset; } [StructLayout(LayoutKind.Explicit)] internal struct Storage { - [FieldOffset(0)] internal Boolean _boolean; - [FieldOffset(0)] internal Byte _byte; - [FieldOffset(0)] internal DateTimeInfo _dateTimeInfo; - [FieldOffset(0)] internal Double _double; - [FieldOffset(0)] internal NumericInfo _numericInfo; - [FieldOffset(0)] internal Int16 _int16; - [FieldOffset(0)] internal Int32 _int32; - [FieldOffset(0)] internal Int64 _int64; // also used to store Money, UtcDateTime, Date , and Time - [FieldOffset(0)] internal Single _single; - [FieldOffset(0)] internal TimeInfo _timeInfo; - [FieldOffset(0)] internal DateTime2Info _dateTime2Info; - [FieldOffset(0)] internal DateTimeOffsetInfo _dateTimeOffsetInfo; + [FieldOffset(0)] + internal bool _boolean; + [FieldOffset(0)] + internal byte _byte; + [FieldOffset(0)] + internal DateTimeInfo _dateTimeInfo; + [FieldOffset(0)] + internal double _double; + [FieldOffset(0)] + internal NumericInfo _numericInfo; + [FieldOffset(0)] + internal short _int16; + [FieldOffset(0)] + internal int _int32; + [FieldOffset(0)] + internal long _int64; // also used to store Money, UtcDateTime, Date , and Time + [FieldOffset(0)] + internal float _single; + [FieldOffset(0)] + internal TimeInfo _timeInfo; + [FieldOffset(0)] + internal DateTime2Info _dateTime2Info; + [FieldOffset(0)] + internal DateTimeOffsetInfo _dateTimeOffsetInfo; } private bool _isNull; @@ -134,7 +145,7 @@ internal StorageType VariantInternalStorageType get { return _type; } } - internal Boolean Boolean + internal bool Boolean { get { @@ -144,7 +155,7 @@ internal Boolean Boolean { return _value._boolean; } - return (Boolean)this.Value; // anything else we haven't thought of goes through boxing. + return (bool)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -155,7 +166,7 @@ internal Boolean Boolean } } - internal Byte Byte + internal byte Byte { get { @@ -165,7 +176,7 @@ internal Byte Byte { return _value._byte; } - return (Byte)this.Value; // anything else we haven't thought of goes through boxing. + return (byte)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -176,7 +187,7 @@ internal Byte Byte } } - internal Byte[] ByteArray + internal byte[] ByteArray { get { @@ -201,13 +212,13 @@ internal DateTime DateTime } if (StorageType.DateTime == _type) { - return SqlTypes.SqlTypeWorkarounds.SqlDateTimeToDateTime(_value._dateTimeInfo.daypart, _value._dateTimeInfo.timepart); + return SqlTypeWorkarounds.SqlDateTimeToDateTime(_value._dateTimeInfo.daypart, _value._dateTimeInfo.timepart); } return (DateTime)this.Value; // anything else we haven't thought of goes through boxing. } } - internal Decimal Decimal + internal decimal Decimal { get { @@ -219,7 +230,7 @@ internal Decimal Decimal { throw new OverflowException(SQLResource.ConversionOverflowMessage); } - return new Decimal(_value._numericInfo.data1, _value._numericInfo.data2, _value._numericInfo.data3, !_value._numericInfo.positive, _value._numericInfo.scale); + return new decimal(_value._numericInfo.data1, _value._numericInfo.data2, _value._numericInfo.data3, !_value._numericInfo.positive, _value._numericInfo.scale); } if (StorageType.Money == _type) { @@ -230,13 +241,13 @@ internal Decimal Decimal isNegative = true; l = -l; } - return new Decimal((int)(l & 0xffffffff), (int)(l >> 32), 0, isNegative, 4); + return new decimal((int)(l & 0xffffffff), (int)(l >> 32), 0, isNegative, 4); } - return (Decimal)this.Value; // anything else we haven't thought of goes through boxing. + return (decimal)this.Value; // anything else we haven't thought of goes through boxing. } } - internal Double Double + internal double Double { get { @@ -246,7 +257,7 @@ internal Double Double { return _value._double; } - return (Double)this.Value; // anything else we haven't thought of goes through boxing. + return (double)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -267,7 +278,7 @@ internal Guid Guid } } - internal Int16 Int16 + internal short Int16 { get { @@ -277,7 +288,7 @@ internal Int16 Int16 { return _value._int16; } - return (Int16)this.Value; // anything else we haven't thought of goes through boxing. + return (short)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -288,7 +299,7 @@ internal Int16 Int16 } } - internal Int32 Int32 + internal int Int32 { get { @@ -298,7 +309,7 @@ internal Int32 Int32 { return _value._int32; } - return (Int32)this.Value; // anything else we haven't thought of goes through boxing. + return (int)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -309,7 +320,7 @@ internal Int32 Int32 } } - internal Int64 Int64 + internal long Int64 { get { @@ -319,7 +330,7 @@ internal Int64 Int64 { return _value._int64; } - return (Int64)this.Value; // anything else we haven't thought of goes through boxing. + return (long)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -330,7 +341,7 @@ internal Int64 Int64 } } - internal Single Single + internal float Single { get { @@ -340,7 +351,7 @@ internal Single Single { return _value._single; } - return (Single)this.Value; // anything else we haven't thought of goes through boxing. + return (float)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -351,7 +362,7 @@ internal Single Single } } - internal String String + internal string String { get { @@ -359,18 +370,18 @@ internal String String if (StorageType.String == _type) { - return (String)_object; + return (string)_object; } else if (StorageType.SqlCachedBuffer == _type) { return ((SqlCachedBuffer)(_object)).ToString(); } - return (String)this.Value; // anything else we haven't thought of goes through boxing. + return (string)this.Value; // anything else we haven't thought of goes through boxing. } } - // use static list of format strings indexed by scale for perf! - private static string[] __katmaiDateTimeOffsetFormatByScale = new string[] { + // use static list of format strings indexed by scale for perf + private static string[] s_katmaiDateTimeOffsetFormatByScale = new string[] { "yyyy-MM-dd HH:mm:ss zzz", "yyyy-MM-dd HH:mm:ss.f zzz", "yyyy-MM-dd HH:mm:ss.ff zzz", @@ -381,7 +392,7 @@ internal String String "yyyy-MM-dd HH:mm:ss.fffffff zzz", }; - private static string[] __katmaiDateTime2FormatByScale = new string[] { + private static string[] s_katmaiDateTime2FormatByScale = new string[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss.f", "yyyy-MM-dd HH:mm:ss.ff", @@ -392,7 +403,7 @@ internal String String "yyyy-MM-dd HH:mm:ss.fffffff", }; - private static string[] __katmaiTimeFormatByScale = new string[] { + private static string[] s_katmaiTimeFormatByScale = new string[] { "HH:mm:ss", "HH:mm:ss.f", "HH:mm:ss.ff", @@ -416,20 +427,20 @@ internal string KatmaiDateTimeString if (StorageType.Time == _type) { byte scale = _value._timeInfo.scale; - return new DateTime(_value._timeInfo.ticks).ToString(__katmaiTimeFormatByScale[scale], DateTimeFormatInfo.InvariantInfo); + return new DateTime(_value._timeInfo.ticks).ToString(s_katmaiTimeFormatByScale[scale], DateTimeFormatInfo.InvariantInfo); } if (StorageType.DateTime2 == _type) { byte scale = _value._dateTime2Info.timeInfo.scale; - return this.DateTime.ToString(__katmaiDateTime2FormatByScale[scale], DateTimeFormatInfo.InvariantInfo); + return this.DateTime.ToString(s_katmaiDateTime2FormatByScale[scale], DateTimeFormatInfo.InvariantInfo); } if (StorageType.DateTimeOffset == _type) { DateTimeOffset dto = this.DateTimeOffset; byte scale = _value._dateTimeOffsetInfo.dateTime2Info.timeInfo.scale; - return dto.ToString(__katmaiDateTimeOffsetFormatByScale[scale], DateTimeFormatInfo.InvariantInfo); + return dto.ToString(s_katmaiDateTimeOffsetFormatByScale[scale], DateTimeFormatInfo.InvariantInfo); } - return (String)this.Value; // anything else we haven't thought of goes through boxing. + return (string)this.Value; // anything else we haven't thought of goes through boxing. } } @@ -750,8 +761,7 @@ internal SqlString SqlString { return SqlString.Null; } - return new SqlString((String)_object); - + return new SqlString((string)_object); } else if (StorageType.SqlCachedBuffer == _type) { @@ -796,6 +806,7 @@ internal object SqlValue return SqlSingle; case StorageType.String: return SqlString; + case StorageType.SqlCachedBuffer: { SqlCachedBuffer data = (SqlCachedBuffer)(_object); @@ -811,14 +822,13 @@ internal object SqlValue return _object; case StorageType.SqlXml: + if (_isNull) { - if (_isNull) - { - return SqlXml.Null; - } - Debug.Assert(null != _object); - return (SqlXml)_object; + return SqlXml.Null; } + Debug.Assert(null != _object); + return (SqlXml)_object; + case StorageType.Date: case StorageType.DateTime2: if (_isNull) @@ -826,12 +836,14 @@ internal object SqlValue return DBNull.Value; } return DateTime; + case StorageType.DateTimeOffset: if (_isNull) { return DBNull.Value; } return DateTimeOffset; + case StorageType.Time: if (_isNull) { @@ -843,6 +855,9 @@ internal object SqlValue } } + private static readonly object s_cachedTrueObject = true; + private static readonly object s_cachedFalseObject = false; + internal object Value { get @@ -856,7 +871,7 @@ internal object Value case StorageType.Empty: return DBNull.Value; case StorageType.Boolean: - return Boolean; + return Boolean ? s_cachedTrueObject : s_cachedFalseObject; case StorageType.Byte: return Byte; case StorageType.DateTime: @@ -914,75 +929,76 @@ internal Type GetTypeFromStorageType(bool isSqlType) { switch (_type) { - case SqlBuffer.StorageType.Empty: + case StorageType.Empty: return null; - case SqlBuffer.StorageType.Boolean: + case StorageType.Boolean: return typeof(SqlBoolean); - case SqlBuffer.StorageType.Byte: + case StorageType.Byte: return typeof(SqlByte); - case SqlBuffer.StorageType.DateTime: + case StorageType.DateTime: return typeof(SqlDateTime); - case SqlBuffer.StorageType.Decimal: + case StorageType.Decimal: return typeof(SqlDecimal); - case SqlBuffer.StorageType.Double: + case StorageType.Double: return typeof(SqlDouble); - case SqlBuffer.StorageType.Int16: + case StorageType.Int16: return typeof(SqlInt16); - case SqlBuffer.StorageType.Int32: + case StorageType.Int32: return typeof(SqlInt32); - case SqlBuffer.StorageType.Int64: + case StorageType.Int64: return typeof(SqlInt64); - case SqlBuffer.StorageType.Money: + case StorageType.Money: return typeof(SqlMoney); - case SqlBuffer.StorageType.Single: + case StorageType.Single: return typeof(SqlSingle); - case SqlBuffer.StorageType.String: + case StorageType.String: return typeof(SqlString); - case SqlBuffer.StorageType.SqlCachedBuffer: + case StorageType.SqlCachedBuffer: return typeof(SqlString); - case SqlBuffer.StorageType.SqlBinary: - return typeof(object); - case SqlBuffer.StorageType.SqlGuid: + case StorageType.SqlBinary: return typeof(object); - case SqlBuffer.StorageType.SqlXml: + case StorageType.SqlGuid: + return typeof(SqlGuid); + case StorageType.SqlXml: return typeof(SqlXml); + // Date DateTime2 and DateTimeOffset have no direct Sql type to contain them } } else { //Is CLR Type switch (_type) { - case SqlBuffer.StorageType.Empty: + case StorageType.Empty: return null; - case SqlBuffer.StorageType.Boolean: - return typeof(Boolean); - case SqlBuffer.StorageType.Byte: - return typeof(Byte); - case SqlBuffer.StorageType.DateTime: + case StorageType.Boolean: + return typeof(bool); + case StorageType.Byte: + return typeof(byte); + case StorageType.DateTime: return typeof(DateTime); - case SqlBuffer.StorageType.Decimal: - return typeof(Decimal); - case SqlBuffer.StorageType.Double: - return typeof(Double); - case SqlBuffer.StorageType.Int16: - return typeof(Int16); - case SqlBuffer.StorageType.Int32: - return typeof(Int32); - case SqlBuffer.StorageType.Int64: - return typeof(Int64); - case SqlBuffer.StorageType.Money: - return typeof(Decimal); - case SqlBuffer.StorageType.Single: - return typeof(Single); - case SqlBuffer.StorageType.String: - return typeof(String); - case SqlBuffer.StorageType.SqlBinary: - return typeof(Byte[]); - case SqlBuffer.StorageType.SqlCachedBuffer: + case StorageType.Decimal: + return typeof(decimal); + case StorageType.Double: + return typeof(double); + case StorageType.Int16: + return typeof(short); + case StorageType.Int32: + return typeof(int); + case StorageType.Int64: + return typeof(long); + case StorageType.Money: + return typeof(decimal); + case StorageType.Single: + return typeof(float); + case StorageType.String: return typeof(string); - case SqlBuffer.StorageType.SqlGuid: + case StorageType.SqlBinary: + return typeof(byte[]); + case StorageType.SqlCachedBuffer: + return typeof(string); + case StorageType.SqlGuid: return typeof(Guid); - case SqlBuffer.StorageType.SqlXml: + case StorageType.SqlXml: return typeof(string); } } @@ -1153,7 +1169,7 @@ internal void SetToDateTimeOffset(DateTimeOffset dateTimeOffset, byte scale) _value._dateTimeOffsetInfo.dateTime2Info.timeInfo.ticks = utcDateTime.TimeOfDay.Ticks; _value._dateTimeOffsetInfo.dateTime2Info.timeInfo.scale = scale; _value._dateTimeOffsetInfo.dateTime2Info.date = utcDateTime.Subtract(DateTime.MinValue).Days; - _value._dateTimeOffsetInfo.offset = (Int16)dateTimeOffset.Offset.TotalMinutes; + _value._dateTimeOffsetInfo.offset = (short)dateTimeOffset.Offset.TotalMinutes; _isNull = false; } @@ -1180,7 +1196,7 @@ private static void FillInTimeInfo(ref TimeInfo timeInfo, byte[] timeBytes, int timeInfo.scale = denormalizedScale; } - private static Int32 GetDateFromByteArray(byte[] buf, int offset) + private static int GetDateFromByteArray(byte[] buf, int offset) { return buf[offset] + (buf[offset + 1] << 8) + (buf[offset + 2] << 16); } diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs deleted file mode 100644 index 17da75c381..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs +++ /dev/null @@ -1,85 +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.Collections.Concurrent; -using System.Diagnostics; -using System.Text; - -namespace Microsoft.Data.SqlClient -{ - /// - /// Implements a global directory of all the encryption algorithms registered with client. - /// - sealed internal class SqlClientEncryptionAlgorithmFactoryList - { - private readonly ConcurrentDictionary _encryptionAlgoFactoryList; - private static readonly SqlClientEncryptionAlgorithmFactoryList _singletonInstance = new SqlClientEncryptionAlgorithmFactoryList(); - - private SqlClientEncryptionAlgorithmFactoryList() - { - _encryptionAlgoFactoryList = new ConcurrentDictionary(concurrencyLevel: 4 * Environment.ProcessorCount /* default value in ConcurrentDictionary*/, capacity: 2); - - // Add wellknown algorithms - _encryptionAlgoFactoryList.TryAdd(SqlAeadAes256CbcHmac256Algorithm.AlgorithmName, new SqlAeadAes256CbcHmac256Factory()); - _encryptionAlgoFactoryList.TryAdd(SqlAes256CbcAlgorithm.AlgorithmName, new SqlAes256CbcFactory()); - } - - internal static SqlClientEncryptionAlgorithmFactoryList GetInstance() - { - return _singletonInstance; - } - - /// - /// - /// - /// - internal string GetRegisteredCipherAlgorithmNames() - { - StringBuilder builder = new StringBuilder(); - bool firstElem = true; - foreach (string key in _encryptionAlgoFactoryList.Keys) - { - if (firstElem) - { - builder.Append("'"); - firstElem = false; - } - else - { - builder.Append(", '"); - } - builder.Append(key); - builder.Append("'"); - } - - return builder.ToString(); - } - - /// - /// Gets the algorithm handle instance for a given algorithm and instantiates it using the provided key and the encryption type. - /// - /// - /// - /// - /// - internal void GetAlgorithm(SqlClientSymmetricKey key, byte type, string algorithmName, out SqlClientEncryptionAlgorithm encryptionAlgorithm) - { - encryptionAlgorithm = null; - - SqlClientEncryptionAlgorithmFactory factory = null; - if (!_encryptionAlgoFactoryList.TryGetValue(algorithmName, out factory)) - { - throw SQL.UnknownColumnEncryptionAlgorithm(algorithmName, - SqlClientEncryptionAlgorithmFactoryList.GetInstance().GetRegisteredCipherAlgorithmNames()); - } - - Debug.Assert(null != factory, "Null Algorithm Factory class detected"); - - // If the factory exists, following method will Create an algorithm object. If this fails, - // it will raise an exception. - encryptionAlgorithm = factory.Create(key, (SqlClientEncryptionType)type, algorithmName); - } - } -} diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ApplicationIntent.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ApplicationIntent.cs new file mode 100644 index 0000000000..4e8bf1afa5 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ApplicationIntent.cs @@ -0,0 +1,19 @@ +// 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 +{ + /// +#if NETFRAMEWORK + [System.Serializable] +#endif + public enum ApplicationIntent + { + /// + ReadWrite = 0, + + /// + ReadOnly = 1, + } +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ParameterPeekAheadValue.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ParameterPeekAheadValue.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/ParameterPeekAheadValue.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/ParameterPeekAheadValue.cs diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs new file mode 100644 index 0000000000..7d4f02f906 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs @@ -0,0 +1,22 @@ +// 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 +{ +#if NETFRAMEWORK + [System.Serializable] +#endif + /// + public enum PoolBlockingPeriod + { + /// + Auto = 0, // Blocking period OFF for Azure SQL servers, but ON for all other SQL servers. + + /// + AlwaysBlock = 1, // Blocking period ON for all SQL servers including Azure SQL servers. + + /// + NeverBlock = 2, // Blocking period OFF for all SQL servers including Azure SQL servers. + } +} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs similarity index 53% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs index b58b6460ec..8527b49115 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs @@ -4,19 +4,19 @@ namespace Microsoft.Data.SqlClient { - /// + /// public class SqlRowsCopiedEventArgs : System.EventArgs { private bool _abort; private long _rowsCopied; - /// + /// public SqlRowsCopiedEventArgs(long rowsCopied) { _rowsCopied = rowsCopied; } - /// + /// public bool Abort { get @@ -29,7 +29,7 @@ public bool Abort } } - /// + /// public long RowsCopied { get diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs similarity index 62% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs index d32023d762..9a2571d9d8 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventHandler.cs @@ -4,7 +4,7 @@ namespace Microsoft.Data.SqlClient { - /// + /// public delegate void SqlRowsCopiedEventHandler(object sender, SqlRowsCopiedEventArgs e); } diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SortOrder.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SortOrder.cs new file mode 100644 index 0000000000..4e79b63799 --- /dev/null +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SortOrder.cs @@ -0,0 +1,20 @@ +// 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 +{ + /// + public enum SortOrder + { + /// + Unspecified = -1, + + /// + Ascending = 0, + + /// + Descending = 1 + } +} + diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs similarity index 72% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs index bbe46a3f45..018440c743 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlAuthenticationToken.cs @@ -7,16 +7,16 @@ namespace Microsoft.Data.SqlClient { - /// + /// public class SqlAuthenticationToken { - /// + /// public DateTimeOffset ExpiresOn { get; } - /// + /// public string AccessToken { get; } - /// + /// public SqlAuthenticationToken(string accessToken, DateTimeOffset expiresOn) { if (string.IsNullOrEmpty(accessToken)) diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs similarity index 61% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs index 69a99f6e5e..2f6ef5c532 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlBulkCopyColumnMapping.cs @@ -6,9 +6,7 @@ namespace Microsoft.Data.SqlClient { - // ------------------------------------------------------------------------------------------------- - // this class helps allows the user to create association between source and target columns - /// + /// public sealed class SqlBulkCopyColumnMapping { internal string _destinationColumnName; @@ -21,7 +19,7 @@ public sealed class SqlBulkCopyColumnMapping internal int _internalDestinationColumnOrdinal; internal int _internalSourceColumnOrdinal; // -1 indicates an undetermined value - /// + /// public string DestinationColumn { get @@ -39,7 +37,7 @@ public string DestinationColumn } } - /// + /// public int DestinationOrdinal { get @@ -60,7 +58,7 @@ public int DestinationOrdinal } } - /// + /// public string SourceColumn { get @@ -78,7 +76,7 @@ public string SourceColumn } } - /// + /// public int SourceOrdinal { get @@ -99,34 +97,34 @@ public int SourceOrdinal } } - /// + /// public SqlBulkCopyColumnMapping() { _internalSourceColumnOrdinal = -1; } - /// + /// public SqlBulkCopyColumnMapping(string sourceColumn, string destinationColumn) { SourceColumn = sourceColumn; DestinationColumn = destinationColumn; } - /// + /// public SqlBulkCopyColumnMapping(int sourceColumnOrdinal, string destinationColumn) { SourceOrdinal = sourceColumnOrdinal; DestinationColumn = destinationColumn; } - /// + /// public SqlBulkCopyColumnMapping(string sourceColumn, int destinationOrdinal) { SourceColumn = sourceColumn; DestinationOrdinal = destinationOrdinal; } - /// + /// public SqlBulkCopyColumnMapping(int sourceColumnOrdinal, int destinationOrdinal) { SourceOrdinal = sourceColumnOrdinal; diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithm.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithm.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithm.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithm.cs diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs similarity index 100% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlClientEncryptionAlgorithmFactoryList.cs From e345039ed1ad14fcae69d8938556df0a49bde323 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Tue, 23 Jun 2020 16:52:59 +0100 Subject: [PATCH 2/4] revent SqlBuffer to previous version --- .../src/Microsoft/Data/SqlClient/SqlBuffer.cs | 238 ++++++++---------- 1 file changed, 111 insertions(+), 127 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBuffer.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBuffer.cs index 5f9575b1ec..c395c3cc2d 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBuffer.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBuffer.cs @@ -14,6 +14,7 @@ namespace Microsoft.Data.SqlClient internal sealed class SqlBuffer { + internal enum StorageType { Empty = 0, @@ -41,67 +42,55 @@ internal enum StorageType internal struct DateTimeInfo { // This is used to store DateTime - internal int daypart; - internal int timepart; + internal Int32 daypart; + internal Int32 timepart; } internal struct NumericInfo { // This is used to store Decimal data - internal int data1; - internal int data2; - internal int data3; - internal int data4; - internal byte precision; - internal byte scale; - internal bool positive; + internal Int32 data1; + internal Int32 data2; + internal Int32 data3; + internal Int32 data4; + internal Byte precision; + internal Byte scale; + internal Boolean positive; } internal struct TimeInfo { - internal long ticks; + internal Int64 ticks; internal byte scale; } internal struct DateTime2Info { - internal int date; + internal Int32 date; internal TimeInfo timeInfo; } internal struct DateTimeOffsetInfo { internal DateTime2Info dateTime2Info; - internal short offset; + internal Int16 offset; } [StructLayout(LayoutKind.Explicit)] internal struct Storage { - [FieldOffset(0)] - internal bool _boolean; - [FieldOffset(0)] - internal byte _byte; - [FieldOffset(0)] - internal DateTimeInfo _dateTimeInfo; - [FieldOffset(0)] - internal double _double; - [FieldOffset(0)] - internal NumericInfo _numericInfo; - [FieldOffset(0)] - internal short _int16; - [FieldOffset(0)] - internal int _int32; - [FieldOffset(0)] - internal long _int64; // also used to store Money, UtcDateTime, Date , and Time - [FieldOffset(0)] - internal float _single; - [FieldOffset(0)] - internal TimeInfo _timeInfo; - [FieldOffset(0)] - internal DateTime2Info _dateTime2Info; - [FieldOffset(0)] - internal DateTimeOffsetInfo _dateTimeOffsetInfo; + [FieldOffset(0)] internal Boolean _boolean; + [FieldOffset(0)] internal Byte _byte; + [FieldOffset(0)] internal DateTimeInfo _dateTimeInfo; + [FieldOffset(0)] internal Double _double; + [FieldOffset(0)] internal NumericInfo _numericInfo; + [FieldOffset(0)] internal Int16 _int16; + [FieldOffset(0)] internal Int32 _int32; + [FieldOffset(0)] internal Int64 _int64; // also used to store Money, UtcDateTime, Date , and Time + [FieldOffset(0)] internal Single _single; + [FieldOffset(0)] internal TimeInfo _timeInfo; + [FieldOffset(0)] internal DateTime2Info _dateTime2Info; + [FieldOffset(0)] internal DateTimeOffsetInfo _dateTimeOffsetInfo; } private bool _isNull; @@ -145,7 +134,7 @@ internal StorageType VariantInternalStorageType get { return _type; } } - internal bool Boolean + internal Boolean Boolean { get { @@ -155,7 +144,7 @@ internal bool Boolean { return _value._boolean; } - return (bool)this.Value; // anything else we haven't thought of goes through boxing. + return (Boolean)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -166,7 +155,7 @@ internal bool Boolean } } - internal byte Byte + internal Byte Byte { get { @@ -176,7 +165,7 @@ internal byte Byte { return _value._byte; } - return (byte)this.Value; // anything else we haven't thought of goes through boxing. + return (Byte)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -187,7 +176,7 @@ internal byte Byte } } - internal byte[] ByteArray + internal Byte[] ByteArray { get { @@ -212,13 +201,13 @@ internal DateTime DateTime } if (StorageType.DateTime == _type) { - return SqlTypeWorkarounds.SqlDateTimeToDateTime(_value._dateTimeInfo.daypart, _value._dateTimeInfo.timepart); + return SqlTypes.SqlTypeWorkarounds.SqlDateTimeToDateTime(_value._dateTimeInfo.daypart, _value._dateTimeInfo.timepart); } return (DateTime)this.Value; // anything else we haven't thought of goes through boxing. } } - internal decimal Decimal + internal Decimal Decimal { get { @@ -230,7 +219,7 @@ internal decimal Decimal { throw new OverflowException(SQLResource.ConversionOverflowMessage); } - return new decimal(_value._numericInfo.data1, _value._numericInfo.data2, _value._numericInfo.data3, !_value._numericInfo.positive, _value._numericInfo.scale); + return new Decimal(_value._numericInfo.data1, _value._numericInfo.data2, _value._numericInfo.data3, !_value._numericInfo.positive, _value._numericInfo.scale); } if (StorageType.Money == _type) { @@ -241,13 +230,13 @@ internal decimal Decimal isNegative = true; l = -l; } - return new decimal((int)(l & 0xffffffff), (int)(l >> 32), 0, isNegative, 4); + return new Decimal((int)(l & 0xffffffff), (int)(l >> 32), 0, isNegative, 4); } - return (decimal)this.Value; // anything else we haven't thought of goes through boxing. + return (Decimal)this.Value; // anything else we haven't thought of goes through boxing. } } - internal double Double + internal Double Double { get { @@ -257,7 +246,7 @@ internal double Double { return _value._double; } - return (double)this.Value; // anything else we haven't thought of goes through boxing. + return (Double)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -278,7 +267,7 @@ internal Guid Guid } } - internal short Int16 + internal Int16 Int16 { get { @@ -288,7 +277,7 @@ internal short Int16 { return _value._int16; } - return (short)this.Value; // anything else we haven't thought of goes through boxing. + return (Int16)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -299,7 +288,7 @@ internal short Int16 } } - internal int Int32 + internal Int32 Int32 { get { @@ -309,7 +298,7 @@ internal int Int32 { return _value._int32; } - return (int)this.Value; // anything else we haven't thought of goes through boxing. + return (Int32)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -320,7 +309,7 @@ internal int Int32 } } - internal long Int64 + internal Int64 Int64 { get { @@ -330,7 +319,7 @@ internal long Int64 { return _value._int64; } - return (long)this.Value; // anything else we haven't thought of goes through boxing. + return (Int64)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -341,7 +330,7 @@ internal long Int64 } } - internal float Single + internal Single Single { get { @@ -351,7 +340,7 @@ internal float Single { return _value._single; } - return (float)this.Value; // anything else we haven't thought of goes through boxing. + return (Single)this.Value; // anything else we haven't thought of goes through boxing. } set { @@ -362,7 +351,7 @@ internal float Single } } - internal string String + internal String String { get { @@ -370,18 +359,18 @@ internal string String if (StorageType.String == _type) { - return (string)_object; + return (String)_object; } else if (StorageType.SqlCachedBuffer == _type) { return ((SqlCachedBuffer)(_object)).ToString(); } - return (string)this.Value; // anything else we haven't thought of goes through boxing. + return (String)this.Value; // anything else we haven't thought of goes through boxing. } } - // use static list of format strings indexed by scale for perf - private static string[] s_katmaiDateTimeOffsetFormatByScale = new string[] { + // use static list of format strings indexed by scale for perf! + private static string[] __katmaiDateTimeOffsetFormatByScale = new string[] { "yyyy-MM-dd HH:mm:ss zzz", "yyyy-MM-dd HH:mm:ss.f zzz", "yyyy-MM-dd HH:mm:ss.ff zzz", @@ -392,7 +381,7 @@ internal string String "yyyy-MM-dd HH:mm:ss.fffffff zzz", }; - private static string[] s_katmaiDateTime2FormatByScale = new string[] { + private static string[] __katmaiDateTime2FormatByScale = new string[] { "yyyy-MM-dd HH:mm:ss", "yyyy-MM-dd HH:mm:ss.f", "yyyy-MM-dd HH:mm:ss.ff", @@ -403,7 +392,7 @@ internal string String "yyyy-MM-dd HH:mm:ss.fffffff", }; - private static string[] s_katmaiTimeFormatByScale = new string[] { + private static string[] __katmaiTimeFormatByScale = new string[] { "HH:mm:ss", "HH:mm:ss.f", "HH:mm:ss.ff", @@ -427,20 +416,20 @@ internal string KatmaiDateTimeString if (StorageType.Time == _type) { byte scale = _value._timeInfo.scale; - return new DateTime(_value._timeInfo.ticks).ToString(s_katmaiTimeFormatByScale[scale], DateTimeFormatInfo.InvariantInfo); + return new DateTime(_value._timeInfo.ticks).ToString(__katmaiTimeFormatByScale[scale], DateTimeFormatInfo.InvariantInfo); } if (StorageType.DateTime2 == _type) { byte scale = _value._dateTime2Info.timeInfo.scale; - return this.DateTime.ToString(s_katmaiDateTime2FormatByScale[scale], DateTimeFormatInfo.InvariantInfo); + return this.DateTime.ToString(__katmaiDateTime2FormatByScale[scale], DateTimeFormatInfo.InvariantInfo); } if (StorageType.DateTimeOffset == _type) { DateTimeOffset dto = this.DateTimeOffset; byte scale = _value._dateTimeOffsetInfo.dateTime2Info.timeInfo.scale; - return dto.ToString(s_katmaiDateTimeOffsetFormatByScale[scale], DateTimeFormatInfo.InvariantInfo); + return dto.ToString(__katmaiDateTimeOffsetFormatByScale[scale], DateTimeFormatInfo.InvariantInfo); } - return (string)this.Value; // anything else we haven't thought of goes through boxing. + return (String)this.Value; // anything else we haven't thought of goes through boxing. } } @@ -761,7 +750,8 @@ internal SqlString SqlString { return SqlString.Null; } - return new SqlString((string)_object); + return new SqlString((String)_object); + } else if (StorageType.SqlCachedBuffer == _type) { @@ -806,7 +796,6 @@ internal object SqlValue return SqlSingle; case StorageType.String: return SqlString; - case StorageType.SqlCachedBuffer: { SqlCachedBuffer data = (SqlCachedBuffer)(_object); @@ -822,13 +811,14 @@ internal object SqlValue return _object; case StorageType.SqlXml: - if (_isNull) { - return SqlXml.Null; + if (_isNull) + { + return SqlXml.Null; + } + Debug.Assert(null != _object); + return (SqlXml)_object; } - Debug.Assert(null != _object); - return (SqlXml)_object; - case StorageType.Date: case StorageType.DateTime2: if (_isNull) @@ -836,14 +826,12 @@ internal object SqlValue return DBNull.Value; } return DateTime; - case StorageType.DateTimeOffset: if (_isNull) { return DBNull.Value; } return DateTimeOffset; - case StorageType.Time: if (_isNull) { @@ -855,9 +843,6 @@ internal object SqlValue } } - private static readonly object s_cachedTrueObject = true; - private static readonly object s_cachedFalseObject = false; - internal object Value { get @@ -871,7 +856,7 @@ internal object Value case StorageType.Empty: return DBNull.Value; case StorageType.Boolean: - return Boolean ? s_cachedTrueObject : s_cachedFalseObject; + return Boolean; case StorageType.Byte: return Byte; case StorageType.DateTime: @@ -929,76 +914,75 @@ internal Type GetTypeFromStorageType(bool isSqlType) { switch (_type) { - case StorageType.Empty: + case SqlBuffer.StorageType.Empty: return null; - case StorageType.Boolean: + case SqlBuffer.StorageType.Boolean: return typeof(SqlBoolean); - case StorageType.Byte: + case SqlBuffer.StorageType.Byte: return typeof(SqlByte); - case StorageType.DateTime: + case SqlBuffer.StorageType.DateTime: return typeof(SqlDateTime); - case StorageType.Decimal: + case SqlBuffer.StorageType.Decimal: return typeof(SqlDecimal); - case StorageType.Double: + case SqlBuffer.StorageType.Double: return typeof(SqlDouble); - case StorageType.Int16: + case SqlBuffer.StorageType.Int16: return typeof(SqlInt16); - case StorageType.Int32: + case SqlBuffer.StorageType.Int32: return typeof(SqlInt32); - case StorageType.Int64: + case SqlBuffer.StorageType.Int64: return typeof(SqlInt64); - case StorageType.Money: + case SqlBuffer.StorageType.Money: return typeof(SqlMoney); - case StorageType.Single: + case SqlBuffer.StorageType.Single: return typeof(SqlSingle); - case StorageType.String: + case SqlBuffer.StorageType.String: return typeof(SqlString); - case StorageType.SqlCachedBuffer: + case SqlBuffer.StorageType.SqlCachedBuffer: return typeof(SqlString); - case StorageType.SqlBinary: + case SqlBuffer.StorageType.SqlBinary: return typeof(object); - case StorageType.SqlGuid: - return typeof(SqlGuid); - case StorageType.SqlXml: + case SqlBuffer.StorageType.SqlGuid: + return typeof(object); + case SqlBuffer.StorageType.SqlXml: return typeof(SqlXml); - // Date DateTime2 and DateTimeOffset have no direct Sql type to contain them } } else { //Is CLR Type switch (_type) { - case StorageType.Empty: + case SqlBuffer.StorageType.Empty: return null; - case StorageType.Boolean: - return typeof(bool); - case StorageType.Byte: - return typeof(byte); - case StorageType.DateTime: + case SqlBuffer.StorageType.Boolean: + return typeof(Boolean); + case SqlBuffer.StorageType.Byte: + return typeof(Byte); + case SqlBuffer.StorageType.DateTime: return typeof(DateTime); - case StorageType.Decimal: - return typeof(decimal); - case StorageType.Double: - return typeof(double); - case StorageType.Int16: - return typeof(short); - case StorageType.Int32: - return typeof(int); - case StorageType.Int64: - return typeof(long); - case StorageType.Money: - return typeof(decimal); - case StorageType.Single: - return typeof(float); - case StorageType.String: + case SqlBuffer.StorageType.Decimal: + return typeof(Decimal); + case SqlBuffer.StorageType.Double: + return typeof(Double); + case SqlBuffer.StorageType.Int16: + return typeof(Int16); + case SqlBuffer.StorageType.Int32: + return typeof(Int32); + case SqlBuffer.StorageType.Int64: + return typeof(Int64); + case SqlBuffer.StorageType.Money: + return typeof(Decimal); + case SqlBuffer.StorageType.Single: + return typeof(Single); + case SqlBuffer.StorageType.String: + return typeof(String); + case SqlBuffer.StorageType.SqlBinary: + return typeof(Byte[]); + case SqlBuffer.StorageType.SqlCachedBuffer: return typeof(string); - case StorageType.SqlBinary: - return typeof(byte[]); - case StorageType.SqlCachedBuffer: - return typeof(string); - case StorageType.SqlGuid: + case SqlBuffer.StorageType.SqlGuid: return typeof(Guid); - case StorageType.SqlXml: + case SqlBuffer.StorageType.SqlXml: return typeof(string); } } @@ -1169,7 +1153,7 @@ internal void SetToDateTimeOffset(DateTimeOffset dateTimeOffset, byte scale) _value._dateTimeOffsetInfo.dateTime2Info.timeInfo.ticks = utcDateTime.TimeOfDay.Ticks; _value._dateTimeOffsetInfo.dateTime2Info.timeInfo.scale = scale; _value._dateTimeOffsetInfo.dateTime2Info.date = utcDateTime.Subtract(DateTime.MinValue).Days; - _value._dateTimeOffsetInfo.offset = (short)dateTimeOffset.Offset.TotalMinutes; + _value._dateTimeOffsetInfo.offset = (Int16)dateTimeOffset.Offset.TotalMinutes; _isNull = false; } @@ -1196,7 +1180,7 @@ private static void FillInTimeInfo(ref TimeInfo timeInfo, byte[] timeBytes, int timeInfo.scale = denormalizedScale; } - private static int GetDateFromByteArray(byte[] buf, int offset) + private static Int32 GetDateFromByteArray(byte[] buf, int offset) { return buf[offset] + (buf[offset + 1] << 8) + (buf[offset + 2] << 16); } From 20e67602370818a8d2f0f07446330cc75c284f6c Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Tue, 23 Jun 2020 18:23:23 +0100 Subject: [PATCH 3/4] add netfrmework define to netfx project --- .../netfx/src/Microsoft.Data.SqlClient.csproj | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj index eabf4493c7..a1c099b526 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -71,6 +71,9 @@ Pdbonly True + + $(DefineConstants);NETFRAMEWORK; + From 33058552cd4d44949d046bd74dd0463f9e1aeedc Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Tue, 23 Jun 2020 19:50:36 +0100 Subject: [PATCH 4/4] address feedback --- .../src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs index 7d4f02f906..fbdeb20e33 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/PoolBlockingPeriod.cs @@ -4,10 +4,10 @@ namespace Microsoft.Data.SqlClient { + /// #if NETFRAMEWORK [System.Serializable] -#endif - /// +#endif public enum PoolBlockingPeriod { ///