From de6ecdeeffd3b1f0b26aef8bfa11887106356d9d Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Tue, 18 Apr 2023 01:15:13 +0100 Subject: [PATCH 1/3] add RowsCopied64 property, refs, and docs --- .../Microsoft.Data.SqlClient/SqlBulkCopy.xml | 21 ++++++++++++++++ .../netcore/ref/Microsoft.Data.SqlClient.cs | 2 ++ .../Microsoft/Data/SqlClient/SqlBulkCopy.cs | 11 +++++--- .../netfx/ref/Microsoft.Data.SqlClient.cs | 2 ++ .../Microsoft/Data/SqlClient/SqlBulkCopy.cs | 11 +++++--- .../Data/SqlClient/RowsCopiedEventArgs.cs | 25 ++++--------------- 6 files changed, 44 insertions(+), 28 deletions(-) diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml index d7299c5e80..87f7cc5e99 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml @@ -509,9 +509,30 @@ and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. This value is incremented during the event and does not imply that this number of rows has been sent to the server or committed. This value can be accessed during or after the execution of a bulk copy operation. + +This value can become negative if the number of rows exceelds int.MaxValue. If this may happen use the RowsCopied64 property. ]]> + + + The number of rows processed in the ongoing bulk copy operation. + + + The long value of the property. + + + + event and does not imply that this number of rows has been sent to the server or committed. + +This value can be accessed during or after the execution of a bulk copy operation. +]]> + + + Releases all resources used by the current instance of the diff --git a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs index 58dfd74e1e..f10c66b386 100644 --- a/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs @@ -259,6 +259,8 @@ public sealed partial class SqlBulkCopy : System.IDisposable public int NotifyAfter { get { throw null; } set { } } /// public int RowsCopied { get { throw null; } } + /// + public long RowsCopied64 { get { throw null; } } /// public event Microsoft.Data.SqlClient.SqlRowsCopiedEventHandler SqlRowsCopied { add { } remove { } } /// diff --git a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs index d469427274..273394395a 100644 --- a/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs +++ b/src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs @@ -171,7 +171,7 @@ public SourceColumnMetadata(ValueMethod method, bool isSqlType, bool isDataFeed) private readonly SqlBulkCopyOptions _copyOptions; private int _timeout = DefaultCommandTimeout; private string _destinationTableName; - private int _rowsCopied; + private long _rowsCopied; private int _notifyAfter; private int _rowsUntilNotification; private bool _insideRowsCopiedEvent; @@ -222,8 +222,8 @@ private int RowNumber private TdsParserStateObject _stateObj; private List<_ColumnMapping> _sortedColumnMappings; - 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); // Newly added member variables for Async modification, m = member variable to bcp. private int _savedBatchSize = 0; // Save the batchsize so that changes are not affected unexpectedly. @@ -376,7 +376,10 @@ public int NotifyAfter internal int ObjectID => _objectID; /// - public int RowsCopied => _rowsCopied; + public int RowsCopied => unchecked((int)_rowsCopied); + + /// + public long RowsCopied64 => _rowsCopied; internal SqlStatistics Statistics { diff --git a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs index 2a8197448c..ca229487be 100644 --- a/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs +++ b/src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs @@ -215,6 +215,8 @@ public sealed partial class SqlBulkCopy : System.IDisposable public int NotifyAfter { get { throw null; } set { } } /// public int RowsCopied { get { throw null; } } + /// + public long RowsCopied64 { get { throw null; } } /// public event Microsoft.Data.SqlClient.SqlRowsCopiedEventHandler SqlRowsCopied { add { } remove { } } /// diff --git a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs index 81ccfb570a..4ae02c29d6 100644 --- a/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs +++ b/src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs @@ -186,7 +186,7 @@ public SourceColumnMetadata(ValueMethod method, bool isSqlType, bool isDataFeed) private readonly SqlBulkCopyOptions _copyOptions; private int _timeout = DefaultCommandTimeout; private string _destinationTableName; - private int _rowsCopied; + private long _rowsCopied; private int _notifyAfter; private int _rowsUntilNotification; private bool _insideRowsCopiedEvent; @@ -238,8 +238,8 @@ private int RowNumber private TdsParserStateObject _stateObj; private List<_ColumnMapping> _sortedColumnMappings; - 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); // Newly added member variables for Async modification, m = member variable to bcp. private int _savedBatchSize = 0; // Save the batchsize so that changes are not affected unexpectedly. @@ -392,7 +392,10 @@ public int NotifyAfter internal int ObjectID => _objectID; /// - public int RowsCopied => _rowsCopied; + public int RowsCopied => unchecked((int)_rowsCopied); + + /// + public long RowsCopied64 => _rowsCopied; internal SqlStatistics Statistics { diff --git a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs index 8527b49115..88931ad5fe 100644 --- a/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs +++ b/src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs @@ -8,34 +8,19 @@ namespace Microsoft.Data.SqlClient public class SqlRowsCopiedEventArgs : System.EventArgs { private bool _abort; - private long _rowsCopied; + private readonly long _rowsCopied; /// - public SqlRowsCopiedEventArgs(long rowsCopied) - { - _rowsCopied = rowsCopied; - } + public SqlRowsCopiedEventArgs(long rowsCopied) => _rowsCopied = rowsCopied; /// public bool Abort { - get - { - return _abort; - } - set - { - _abort = value; - } + get => _abort; + set => _abort = value; } /// - public long RowsCopied - { - get - { - return _rowsCopied; - } - } + public long RowsCopied => unchecked((int)_rowsCopied); } } From c065dbb563bd127f7f07a3c73accee5d36844f06 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Thu, 20 Apr 2023 00:15:34 +0100 Subject: [PATCH 2/3] docs change --- doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml index 87f7cc5e99..06fdf1b5b6 100644 --- a/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml +++ b/doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml @@ -503,14 +503,15 @@ and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data. property. - + event and does not imply that this number of rows has been sent to the server or committed. This value can be accessed during or after the execution of a bulk copy operation. -This value can become negative if the number of rows exceelds int.MaxValue. If this may happen use the RowsCopied64 property. +This value will wrap around and become negative if the number of rows exceeds int.MaxValue. Consider using the property. ]]> From 171112be5cfe4b70d560d139465454579c774fc7 Mon Sep 17 00:00:00 2001 From: Wraith2 Date: Wed, 3 May 2023 22:52:30 +0100 Subject: [PATCH 3/3] add test coverage --- .../tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs | 1 + .../ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs | 1 + 2 files changed, 2 insertions(+) diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs index 2e43147789..9dea10c9e4 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs @@ -36,6 +36,7 @@ public static void Test(string srcConstr, string dstConstr, string dstTable) bulkcopy.WriteToServer(reader); DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 5, "Unexpected number of rows."); + DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied64, (long)5, "Unexpected number of rows."); } Helpers.VerifyResults(dstConn, dstTable, 3, 5); } diff --git a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs index 8f55cb1710..cdeffa2e89 100644 --- a/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs +++ b/src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs @@ -52,6 +52,7 @@ private static async Task TestAsync(string srcConstr, string dstConstr, string d await outputSemaphore.WaitAsync(); DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 5, "Unexpected number of rows."); + DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied64, (long)5, "Unexpected number of rows."); } Helpers.VerifyResults(dstConn, dstTable, 3, 5); }