Skip to content

Commit c3d8fda

Browse files
Wraith2kant2002
authored andcommitted
Add RowsCopied64 property, refs, and docs (dotnet#2004)
1 parent cfc9171 commit c3d8fda

File tree

8 files changed

+48
-29
lines changed

8 files changed

+48
-29
lines changed

doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml

+23-1
Original file line numberDiff line numberDiff line change
@@ -503,15 +503,37 @@ and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
503503
property.
504504
</value>
505505
<remarks>
506-
<format type="text/markdown"><![CDATA[
506+
<format type="text/markdown">
507+
<![CDATA[
507508
508509
## Remarks
509510
This value is incremented during the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.SqlRowsCopied> event and does not imply that this number of rows has been sent to the server or committed.
510511
511512
This value can be accessed during or after the execution of a bulk copy operation.
513+
514+
This value will wrap around and become negative if the number of rows exceeds int.MaxValue. Consider using the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.RowsCopied64> property.
512515
]]></format>
513516
</remarks>
514517
</RowsCopied>
518+
<RowsCopied64>
519+
<summary>
520+
The number of rows processed in the ongoing bulk copy operation.
521+
</summary>
522+
<value>
523+
The long value of the <see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.RowsCopied64" /> property.
524+
</value>
525+
<remarks>
526+
<format type="text/markdown">
527+
<![CDATA[
528+
529+
## Remarks
530+
This value is incremented during the <xref:Microsoft.Data.SqlClient.SqlBulkCopy.SqlRowsCopied> event and does not imply that this number of rows has been sent to the server or committed.
531+
532+
This value can be accessed during or after the execution of a bulk copy operation.
533+
]]>
534+
</format>
535+
</remarks>
536+
</RowsCopied64>
515537
<System.IDisposable.Dispose>
516538
<summary>
517539
Releases all resources used by the current instance of the

src/Microsoft.Data.SqlClient/netcore/ref/Microsoft.Data.SqlClient.cs

+2
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,8 @@ public SqlBulkCopy(string connectionString, Microsoft.Data.SqlClient.SqlBulkCopy
259259
public int NotifyAfter { get { throw null; } set { } }
260260
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied/*'/>
261261
public int RowsCopied { get { throw null; } }
262+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied64/*'/>
263+
public long RowsCopied64 { get { throw null; } }
262264
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/SqlRowsCopied/*'/>
263265
public event Microsoft.Data.SqlClient.SqlRowsCopiedEventHandler SqlRowsCopied { add { } remove { } }
264266
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/Close/*'/>

src/Microsoft.Data.SqlClient/netcore/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ public SourceColumnMetadata(ValueMethod method, bool isSqlType, bool isDataFeed)
171171
private readonly SqlBulkCopyOptions _copyOptions;
172172
private int _timeout = DefaultCommandTimeout;
173173
private string _destinationTableName;
174-
private int _rowsCopied;
174+
private long _rowsCopied;
175175
private int _notifyAfter;
176176
private int _rowsUntilNotification;
177177
private bool _insideRowsCopiedEvent;
@@ -222,8 +222,8 @@ private int RowNumber
222222
private TdsParserStateObject _stateObj;
223223
private List<_ColumnMapping> _sortedColumnMappings;
224224

225-
private static int _objectTypeCount; // EventSource Counter
226-
internal readonly int _objectID = Interlocked.Increment(ref _objectTypeCount);
225+
private static int s_objectTypeCount; // EventSource Counter
226+
internal readonly int _objectID = Interlocked.Increment(ref s_objectTypeCount);
227227

228228
// Newly added member variables for Async modification, m = member variable to bcp.
229229
private int _savedBatchSize = 0; // Save the batchsize so that changes are not affected unexpectedly.
@@ -376,7 +376,10 @@ public int NotifyAfter
376376
internal int ObjectID => _objectID;
377377

378378
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied/*'/>
379-
public int RowsCopied => _rowsCopied;
379+
public int RowsCopied => unchecked((int)_rowsCopied);
380+
381+
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied64/*'/>
382+
public long RowsCopied64 => _rowsCopied;
380383

381384
internal SqlStatistics Statistics
382385
{

src/Microsoft.Data.SqlClient/netfx/ref/Microsoft.Data.SqlClient.cs

+2
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,8 @@ public SqlBulkCopy(string connectionString, Microsoft.Data.SqlClient.SqlBulkCopy
215215
public int NotifyAfter { get { throw null; } set { } }
216216
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied/*'/>
217217
public int RowsCopied { get { throw null; } }
218+
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied64/*'/>
219+
public long RowsCopied64 { get { throw null; } }
218220
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/SqlRowsCopied/*'/>
219221
public event Microsoft.Data.SqlClient.SqlRowsCopiedEventHandler SqlRowsCopied { add { } remove { } }
220222
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/Close/*'/>

src/Microsoft.Data.SqlClient/netfx/src/Microsoft/Data/SqlClient/SqlBulkCopy.cs

+7-4
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public SourceColumnMetadata(ValueMethod method, bool isSqlType, bool isDataFeed)
186186
private readonly SqlBulkCopyOptions _copyOptions;
187187
private int _timeout = DefaultCommandTimeout;
188188
private string _destinationTableName;
189-
private int _rowsCopied;
189+
private long _rowsCopied;
190190
private int _notifyAfter;
191191
private int _rowsUntilNotification;
192192
private bool _insideRowsCopiedEvent;
@@ -238,8 +238,8 @@ private int RowNumber
238238
private TdsParserStateObject _stateObj;
239239
private List<_ColumnMapping> _sortedColumnMappings;
240240

241-
private static int _objectTypeCount; // EventSource Counter
242-
internal readonly int _objectID = Interlocked.Increment(ref _objectTypeCount);
241+
private static int s_objectTypeCount; // EventSource Counter
242+
internal readonly int _objectID = Interlocked.Increment(ref s_objectTypeCount);
243243

244244
// Newly added member variables for Async modification, m = member variable to bcp.
245245
private int _savedBatchSize = 0; // Save the batchsize so that changes are not affected unexpectedly.
@@ -392,7 +392,10 @@ public int NotifyAfter
392392
internal int ObjectID => _objectID;
393393

394394
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied/*'/>
395-
public int RowsCopied => _rowsCopied;
395+
public int RowsCopied => unchecked((int)_rowsCopied);
396+
397+
/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied64/*'/>
398+
public long RowsCopied64 => _rowsCopied;
396399

397400
internal SqlStatistics Statistics
398401
{

src/Microsoft.Data.SqlClient/src/Microsoft/Data/SqlClient/RowsCopiedEventArgs.cs

+5-20
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,19 @@ namespace Microsoft.Data.SqlClient
88
public class SqlRowsCopiedEventArgs : System.EventArgs
99
{
1010
private bool _abort;
11-
private long _rowsCopied;
11+
private readonly long _rowsCopied;
1212

1313
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlRowsCopiedEventArgs.xml' path='docs/members[@name="SqlRowsCopiedEventArgs"]/ctor/*' />
14-
public SqlRowsCopiedEventArgs(long rowsCopied)
15-
{
16-
_rowsCopied = rowsCopied;
17-
}
14+
public SqlRowsCopiedEventArgs(long rowsCopied) => _rowsCopied = rowsCopied;
1815

1916
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlRowsCopiedEventArgs.xml' path='docs/members[@name="SqlRowsCopiedEventArgs"]/Abort/*' />
2017
public bool Abort
2118
{
22-
get
23-
{
24-
return _abort;
25-
}
26-
set
27-
{
28-
_abort = value;
29-
}
19+
get => _abort;
20+
set => _abort = value;
3021
}
3122

3223
/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlRowsCopiedEventArgs.xml' path='docs/members[@name="SqlRowsCopiedEventArgs"]/RowsCopied/*' />
33-
public long RowsCopied
34-
{
35-
get
36-
{
37-
return _rowsCopied;
38-
}
39-
}
24+
public long RowsCopied => unchecked((int)_rowsCopied);
4025
}
4126
}

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReader1.cs

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public static void Test(string srcConstr, string dstConstr, string dstTable)
3636
bulkcopy.WriteToServer(reader);
3737

3838
DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 5, "Unexpected number of rows.");
39+
DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied64, (long)5, "Unexpected number of rows.");
3940
}
4041
Helpers.VerifyResults(dstConn, dstTable, 3, 5);
4142
}

src/Microsoft.Data.SqlClient/tests/ManualTests/SQL/SqlBulkCopyTest/CopyAllFromReaderAsync.cs

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ private static async Task TestAsync(string srcConstr, string dstConstr, string d
5252
await outputSemaphore.WaitAsync();
5353

5454
DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 5, "Unexpected number of rows.");
55+
DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied64, (long)5, "Unexpected number of rows.");
5556
}
5657
Helpers.VerifyResults(dstConn, dstTable, 3, 5);
5758
}

0 commit comments

Comments
 (0)