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 7e64b8fd9e..e907d63e5a 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft.Data.SqlClient.csproj @@ -223,6 +223,9 @@ Microsoft\Data\SqlClient\SqlCredential.cs + + Microsoft\Data\SqlClient\SqlDataAdapter.cs + Microsoft\Data\SqlClient\SqlInfoMessageEventHandler.cs @@ -497,7 +500,6 @@ Microsoft\Data\SqlClient\SqlConnectionTimeoutErrorInternal.cs - 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 ae61c39607..234be22ed3 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft.Data.SqlClient.csproj @@ -291,6 +291,9 @@ Microsoft\Data\SqlClient\SqlConnectionPoolProviderInfo.cs + + Microsoft\Data\SqlClient\SqlDataAdapter.cs + Microsoft\Data\SqlClient\SqlEnclaveAttestationParameters.Crypto.cs @@ -464,7 +467,6 @@ Microsoft\Data\SqlClient\SqlCredential.cs - diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataAdapter.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataAdapter.cs deleted file mode 100644 index 57138fdaf6..0000000000 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlDataAdapter.cs +++ /dev/null @@ -1,329 +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.ComponentModel; -using System.Data; -using System.Data.Common; -using System.Diagnostics; -using Microsoft.Data.Common; - -// NOTE: The current Microsoft.VSDesigner editor attributes are implemented for System.Data.SqlClient, and are not publicly available. -// New attributes that are designed to work with Microsoft.Data.SqlClient and are publicly documented should be included in future. -namespace Microsoft.Data.SqlClient -{ - /// - [ - DefaultEvent("RowUpdated"), - DesignerCategory("") - // TODO: Add designer and toolbox attribute when Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner uses Microsoft.Data.SqlClient - ] - public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter, ICloneable - { - - static private readonly object EventRowUpdated = new object(); - static private readonly object EventRowUpdating = new object(); - - private SqlCommand _deleteCommand, _insertCommand, _selectCommand, _updateCommand; - - private SqlCommandSet _commandSet; - private int _updateBatchSize = 1; - - private static int _objectTypeCount; // EventSource Counter - internal readonly int _objectID = System.Threading.Interlocked.Increment(ref _objectTypeCount); - - internal int ObjectID - { - get - { - return _objectID; - } - } - /// - public SqlDataAdapter() : base() - { - GC.SuppressFinalize(this); - } - - /// - public SqlDataAdapter(SqlCommand selectCommand) : this() - { - SelectCommand = selectCommand; - } - - /// - public SqlDataAdapter(string selectCommandText, string selectConnectionString) : this() - { - SqlConnection connection = new SqlConnection(selectConnectionString); - SelectCommand = new SqlCommand(selectCommandText, connection); - } - - /// - public SqlDataAdapter(string selectCommandText, SqlConnection selectConnection) : this() - { - SelectCommand = new SqlCommand(selectCommandText, selectConnection); - } - - private SqlDataAdapter(SqlDataAdapter from) : base(from) - { // Clone - GC.SuppressFinalize(this); - } - - /// - [ - DefaultValue(null), - ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update), - ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_DeleteCommand), - ] - new public SqlCommand DeleteCommand - { - get { return _deleteCommand; } - set { _deleteCommand = value; } - } - - /// - IDbCommand IDbDataAdapter.DeleteCommand - { - get { return _deleteCommand; } - set { _deleteCommand = (SqlCommand)value; } - } - - /// - [ - DefaultValue(null), - ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update), - ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_InsertCommand), - ] - new public SqlCommand InsertCommand - { - get { return _insertCommand; } - set { _insertCommand = value; } - } - - /// - IDbCommand IDbDataAdapter.InsertCommand - { - get { return _insertCommand; } - set { _insertCommand = (SqlCommand)value; } - } - - /// - [ - DefaultValue(null), - ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Fill), - ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_SelectCommand), - ] - new public SqlCommand SelectCommand - { - get { return _selectCommand; } - set { _selectCommand = value; } - } - - /// - IDbCommand IDbDataAdapter.SelectCommand - { - get { return _selectCommand; } - set { _selectCommand = (SqlCommand)value; } - } - - /// - override public int UpdateBatchSize - { - get - { - return _updateBatchSize; - } - set - { - if (0 > value) - { // WebData 98157 - throw ADP.ArgumentOutOfRange("UpdateBatchSize"); - } - _updateBatchSize = value; - SqlClientEventSource.Log.TryTraceEvent(" {0}, {1}", ObjectID, value); - } - } - - /// - [ - DefaultValue(null), - ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update), - ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_UpdateCommand), - ] - new public SqlCommand UpdateCommand - { - get { return _updateCommand; } - set { _updateCommand = value; } - } - - /// - IDbCommand IDbDataAdapter.UpdateCommand - { - get { return _updateCommand; } - set { _updateCommand = (SqlCommand)value; } - } - - /// - [ - ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update), - ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_RowUpdated), - ] - public event SqlRowUpdatedEventHandler RowUpdated - { - add - { - Events.AddHandler(EventRowUpdated, value); - } - remove - { - Events.RemoveHandler(EventRowUpdated, value); - } - } - - /// - [ - ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update), - ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_RowUpdating), - ] - public event SqlRowUpdatingEventHandler RowUpdating - { - add - { - SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler)Events[EventRowUpdating]; - - // MDAC 58177, 64513 - // prevent someone from registering two different command builders on the adapter by - // silently removing the old one - if ((null != handler) && (value.Target is DbCommandBuilder)) - { - SqlRowUpdatingEventHandler d = (SqlRowUpdatingEventHandler)ADP.FindBuilder(handler); - if (null != d) - { - Events.RemoveHandler(EventRowUpdating, d); - } - } - Events.AddHandler(EventRowUpdating, value); - } - remove - { - Events.RemoveHandler(EventRowUpdating, value); - } - } - - /// - override protected int AddToBatch(IDbCommand command) - { - int commandIdentifier = _commandSet.CommandCount; - _commandSet.Append((SqlCommand)command); - return commandIdentifier; - } - - /// - override protected void ClearBatch() - { - _commandSet.Clear(); - } - - /// - object ICloneable.Clone() - { - return new SqlDataAdapter(this); - } - - /// - override protected RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) - { - return new SqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping); - } - - /// - override protected RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) - { - return new SqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping); - } - - /// - override protected int ExecuteBatch() - { - Debug.Assert(null != _commandSet && (0 < _commandSet.CommandCount), "no commands"); - SqlClientEventSource.Log.TryCorrelationTraceEvent(" ObjectID {0}, ActivityID {1}", ObjectID, ActivityCorrelator.Current); - - return _commandSet.ExecuteNonQuery(); - } - - /// - override protected IDataParameter GetBatchedParameter(int commandIdentifier, int parameterIndex) - { - Debug.Assert(commandIdentifier < _commandSet.CommandCount, "commandIdentifier out of range"); - Debug.Assert(parameterIndex < _commandSet.GetParameterCount(commandIdentifier), "parameter out of range"); - IDataParameter parameter = _commandSet.GetParameter(commandIdentifier, parameterIndex); - return parameter; - } - - /// - override protected bool GetBatchedRecordsAffected(int commandIdentifier, out int recordsAffected, out Exception error) - { - Debug.Assert(commandIdentifier < _commandSet.CommandCount, "commandIdentifier out of range"); - return _commandSet.GetBatchedAffected(commandIdentifier, out recordsAffected, out error); - } - - /// - override protected void InitializeBatching() - { - SqlClientEventSource.Log.TryTraceEvent(" {0}", ObjectID); - _commandSet = new SqlCommandSet(); - SqlCommand command = SelectCommand; - if (null == command) - { - command = InsertCommand; - if (null == command) - { - command = UpdateCommand; - if (null == command) - { - command = DeleteCommand; - } - } - } - if (null != command) - { - _commandSet.Connection = command.Connection; - _commandSet.Transaction = command.Transaction; - _commandSet.CommandTimeout = command.CommandTimeout; - } - } - - /// - override protected void OnRowUpdated(RowUpdatedEventArgs value) - { - SqlRowUpdatedEventHandler handler = (SqlRowUpdatedEventHandler)Events[EventRowUpdated]; - if ((null != handler) && (value is SqlRowUpdatedEventArgs)) - { - handler(this, (SqlRowUpdatedEventArgs)value); - } - base.OnRowUpdated(value); - } - - /// - override protected void OnRowUpdating(RowUpdatingEventArgs value) - { - SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler)Events[EventRowUpdating]; - if ((null != handler) && (value is SqlRowUpdatingEventArgs)) - { - handler(this, (SqlRowUpdatingEventArgs)value); - } - base.OnRowUpdating(value); - } - - /// - override protected void TerminateBatching() - { - if (null != _commandSet) - { - _commandSet.Dispose(); - _commandSet = null; - } - } - } -} diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataAdapter.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDataAdapter.cs similarity index 62% rename from src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataAdapter.cs rename to src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDataAdapter.cs index 20b28303b5..bf1b67093a 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlDataAdapter.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/SqlDataAdapter.cs @@ -14,45 +14,45 @@ // New attributes that are designed to work with Microsoft.Data.SqlClient and are publicly documented should be included in future. namespace Microsoft.Data.SqlClient { - /// + /// [DefaultEvent("RowUpdated")] [DesignerCategory("")] // TODO: Add designer and toolbox attribute when Microsoft.VSDesigner.Data.VS.SqlDataAdapterDesigner uses Microsoft.Data.SqlClient public sealed class SqlDataAdapter : DbDataAdapter, IDbDataAdapter, ICloneable { - private static readonly object EventRowUpdated = new object(); - private static readonly object EventRowUpdating = new object(); + private static readonly object s_eventRowUpdated = new(); + private static readonly object s_eventRowUpdating = new(); private SqlCommand _deleteCommand, _insertCommand, _selectCommand, _updateCommand; private SqlCommandSet _commandSet; private int _updateBatchSize = 1; - private static int _objectTypeCount; // EventSource Counter - internal readonly int _objectID = Interlocked.Increment(ref _objectTypeCount); + private static int s_objectTypeCount; // EventSource Counter + internal readonly int _objectID = Interlocked.Increment(ref s_objectTypeCount); internal int ObjectID => _objectID; - /// + /// public SqlDataAdapter() : base() { GC.SuppressFinalize(this); } - /// + /// public SqlDataAdapter(SqlCommand selectCommand) : this() { SelectCommand = selectCommand; } - /// + /// public SqlDataAdapter(string selectCommandText, string selectConnectionString) : this() { - SqlConnection connection = new SqlConnection(selectConnectionString); + SqlConnection connection = new(selectConnectionString); SelectCommand = new SqlCommand(selectCommandText, connection); } - /// + /// public SqlDataAdapter(string selectCommandText, SqlConnection selectConnection) : this() { SelectCommand = new SqlCommand(selectCommandText, selectConnection); @@ -63,7 +63,7 @@ private SqlDataAdapter(SqlDataAdapter from) : base(from) GC.SuppressFinalize(this); } - /// + /// [DefaultValue(null)] [ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update)] [ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_DeleteCommand)] @@ -73,14 +73,14 @@ private SqlDataAdapter(SqlDataAdapter from) : base(from) set { _deleteCommand = value; } } - /// + /// IDbCommand IDbDataAdapter.DeleteCommand { get { return _deleteCommand; } set { _deleteCommand = (SqlCommand)value; } } - /// + /// [DefaultValue(null)] [ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update)] [ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_InsertCommand)] @@ -90,14 +90,14 @@ IDbCommand IDbDataAdapter.DeleteCommand set { _insertCommand = value; } } - /// + /// IDbCommand IDbDataAdapter.InsertCommand { get { return _insertCommand; } set { _insertCommand = (SqlCommand)value; } } - /// + /// [DefaultValue(null)] [ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Fill)] [ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_SelectCommand)] @@ -107,14 +107,14 @@ IDbCommand IDbDataAdapter.InsertCommand set { _selectCommand = value; } } - /// + /// IDbCommand IDbDataAdapter.SelectCommand { get { return _selectCommand; } set { _selectCommand = (SqlCommand)value; } } - /// + /// [DefaultValue(null)] [ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update)] [ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_UpdateCommand)] @@ -124,14 +124,14 @@ IDbCommand IDbDataAdapter.SelectCommand set { _updateCommand = value; } } - /// + /// IDbCommand IDbDataAdapter.UpdateCommand { get { return _updateCommand; } set { _updateCommand = (SqlCommand)value; } } - /// + /// public override int UpdateBatchSize { get @@ -149,7 +149,7 @@ public override int UpdateBatchSize } } - /// + /// protected override int AddToBatch(IDbCommand command) { int commandIdentifier = _commandSet.CommandCount; @@ -157,13 +157,13 @@ protected override int AddToBatch(IDbCommand command) return commandIdentifier; } - /// + /// protected override void ClearBatch() { _commandSet.Clear(); } - /// + /// protected override int ExecuteBatch() { Debug.Assert(null != _commandSet && (0 < _commandSet.CommandCount), "no commands"); @@ -171,7 +171,7 @@ protected override int ExecuteBatch() return _commandSet.ExecuteNonQuery(); } - /// + /// protected override IDataParameter GetBatchedParameter(int commandIdentifier, int parameterIndex) { Debug.Assert(commandIdentifier < _commandSet.CommandCount, "commandIdentifier out of range"); @@ -180,14 +180,14 @@ protected override IDataParameter GetBatchedParameter(int commandIdentifier, int return parameter; } - /// + /// protected override bool GetBatchedRecordsAffected(int commandIdentifier, out int recordsAffected, out Exception error) { Debug.Assert(commandIdentifier < _commandSet.CommandCount, "commandIdentifier out of range"); return _commandSet.GetBatchedAffected(commandIdentifier, out recordsAffected, out error); } - /// + /// protected override void InitializeBatching() { SqlClientEventSource.Log.TryTraceEvent("SqlDataAdapter.InitializeBatching | API | Object Id {0}", ObjectID); @@ -213,7 +213,7 @@ protected override void InitializeBatching() } } - /// + /// protected override void TerminateBatching() { if (null != _commandSet) @@ -223,47 +223,47 @@ protected override void TerminateBatching() } } - /// + /// object ICloneable.Clone() { return new SqlDataAdapter(this); } - /// + /// protected override RowUpdatedEventArgs CreateRowUpdatedEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) { return new SqlRowUpdatedEventArgs(dataRow, command, statementType, tableMapping); } - /// + /// protected override RowUpdatingEventArgs CreateRowUpdatingEvent(DataRow dataRow, IDbCommand command, StatementType statementType, DataTableMapping tableMapping) { return new SqlRowUpdatingEventArgs(dataRow, command, statementType, tableMapping); } - /// + /// [ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update)] [ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_RowUpdated)] public event SqlRowUpdatedEventHandler RowUpdated { add { - Events.AddHandler(EventRowUpdated, value); + Events.AddHandler(s_eventRowUpdated, value); } remove { - Events.RemoveHandler(EventRowUpdated, value); + Events.RemoveHandler(s_eventRowUpdated, value); } } - /// + /// [ResCategoryAttribute(StringsHelper.ResourceNames.DataCategory_Update)] [ResDescriptionAttribute(StringsHelper.ResourceNames.DbDataAdapter_RowUpdating)] public event SqlRowUpdatingEventHandler RowUpdating { add { - SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler)Events[EventRowUpdating]; + SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler)Events[s_eventRowUpdating]; // Prevent someone from registering two different command builders on the adapter by // silently removing the old one. @@ -272,35 +272,35 @@ public event SqlRowUpdatingEventHandler RowUpdating SqlRowUpdatingEventHandler d = (SqlRowUpdatingEventHandler)ADP.FindBuilder(handler); if (null != d) { - Events.RemoveHandler(EventRowUpdating, d); + Events.RemoveHandler(s_eventRowUpdating, d); } } - Events.AddHandler(EventRowUpdating, value); + Events.AddHandler(s_eventRowUpdating, value); } remove { - Events.RemoveHandler(EventRowUpdating, value); + Events.RemoveHandler(s_eventRowUpdating, value); } } - /// + /// override protected void OnRowUpdated(RowUpdatedEventArgs value) { - SqlRowUpdatedEventHandler handler = (SqlRowUpdatedEventHandler)Events[EventRowUpdated]; - if ((null != handler) && (value is SqlRowUpdatedEventArgs)) + SqlRowUpdatedEventHandler handler = (SqlRowUpdatedEventHandler)Events[s_eventRowUpdated]; + if ((null != handler) && (value is SqlRowUpdatedEventArgs args)) { - handler(this, (SqlRowUpdatedEventArgs)value); + handler(this, args); } base.OnRowUpdated(value); } - /// + /// override protected void OnRowUpdating(RowUpdatingEventArgs value) { - SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler)Events[EventRowUpdating]; - if ((null != handler) && (value is SqlRowUpdatingEventArgs)) + SqlRowUpdatingEventHandler handler = (SqlRowUpdatingEventHandler)Events[s_eventRowUpdating]; + if ((null != handler) && (value is SqlRowUpdatingEventArgs args)) { - handler(this, (SqlRowUpdatingEventArgs)value); + handler(this, args); } base.OnRowUpdating(value); }