Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add | Add RowsCopied64 property, refs, and docs #2004

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -509,9 +509,30 @@ and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
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.

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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • exceelds -> exceeds (typo)
  • RowsCopied64 should have some kind of ref tag?
  • I feel like this language should be stronger: "This value will wrap around and become negative if... Applications should use RowsCopied64 instead".

Copy link
Contributor Author

@Wraith2 Wraith2 Apr 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to:
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.

If the tone needs to be stronger than that I'll leave the exact wording to the MS team.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like your rewording. As an app developer I would just always use RowsCopied64 now that it exists since there's no cost and real upside.

]]></format>
</remarks>
</RowsCopied>
<RowsCopied64>
<summary>
The number of rows processed in the ongoing bulk copy operation.
</summary>
<value>
The long value of the <see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.RowsCopied64" /> property.
</value>
<remarks>
<format type="text/markdown">
<![CDATA[

## Remarks
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.

This value can be accessed during or after the execution of a bulk copy operation.
]]>
</format>
</remarks>
</RowsCopied64>
<System.IDisposable.Dispose>
<summary>
Releases all resources used by the current instance of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ public SqlBulkCopy(string connectionString, Microsoft.Data.SqlClient.SqlBulkCopy
public int NotifyAfter { get { throw null; } set { } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied/*'/>
public int RowsCopied { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied64/*'/>
public long RowsCopied64 { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/SqlRowsCopied/*'/>
public event Microsoft.Data.SqlClient.SqlRowsCopiedEventHandler SqlRowsCopied { add { } remove { } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/Close/*'/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -376,7 +376,10 @@ public int NotifyAfter
internal int ObjectID => _objectID;

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied/*'/>
public int RowsCopied => _rowsCopied;
public int RowsCopied => unchecked((int)_rowsCopied);

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied64/*'/>
public long RowsCopied64 => _rowsCopied;

internal SqlStatistics Statistics
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ public SqlBulkCopy(string connectionString, Microsoft.Data.SqlClient.SqlBulkCopy
public int NotifyAfter { get { throw null; } set { } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied/*'/>
public int RowsCopied { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied64/*'/>
public long RowsCopied64 { get { throw null; } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/SqlRowsCopied/*'/>
public event Microsoft.Data.SqlClient.SqlRowsCopiedEventHandler SqlRowsCopied { add { } remove { } }
/// <include file='../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/Close/*'/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -392,7 +392,10 @@ public int NotifyAfter
internal int ObjectID => _objectID;

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied/*'/>
public int RowsCopied => _rowsCopied;
public int RowsCopied => unchecked((int)_rowsCopied);

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied64/*'/>
public long RowsCopied64 => _rowsCopied;

internal SqlStatistics Statistics
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,19 @@ namespace Microsoft.Data.SqlClient
public class SqlRowsCopiedEventArgs : System.EventArgs
{
private bool _abort;
private long _rowsCopied;
private readonly long _rowsCopied;

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

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlRowsCopiedEventArgs.xml' path='docs/members[@name="SqlRowsCopiedEventArgs"]/Abort/*' />
public bool Abort
{
get
{
return _abort;
}
set
{
_abort = value;
}
get => _abort;
set => _abort = value;
}

/// <include file='../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlRowsCopiedEventArgs.xml' path='docs/members[@name="SqlRowsCopiedEventArgs"]/RowsCopied/*' />
public long RowsCopied
{
get
{
return _rowsCopied;
}
}
public long RowsCopied => unchecked((int)_rowsCopied);
}
}