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 "RowsCopied" property to SqlBulkCopy #409

Merged
merged 2 commits into from
Mar 10, 2020
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
19 changes: 19 additions & 0 deletions doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,25 @@ and faster to use a Transact-SQL `INSERT … SELECT` statement to copy the data.
]]></format>
</remarks>
</SqlRowsCopied>
<RowsCopied>
<summary>
The number of rows processed in the ongoing bulk copy operation.
</summary>
<value>
The integer value of the
<see cref="P:Microsoft.Data.SqlClient.SqlBulkCopy.RowsCopied" />
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 these many rows have been sent to the server or committed.
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved

During the execution of a bulk copy operation, this value can be accessed, but it cannot be changed. Any attempt to change it will throw an <xref:System.InvalidOperationException>.
]]></format>
</remarks>
</RowsCopied>
<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 @@ -395,6 +395,15 @@ public event SqlRowsCopiedEventHandler SqlRowsCopied
}
}

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

internal SqlStatistics Statistics
{
get
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,15 @@ public event SqlRowsCopiedEventHandler SqlRowsCopied

}

/// <include file='../../../../../../../doc/snippets/Microsoft.Data.SqlClient/SqlBulkCopy.xml' path='docs/members[@name="SqlBulkCopy"]/RowsCopied/*'/>
public int RowsCopied
cheenamalhotra marked this conversation as resolved.
Show resolved Hide resolved
{
get
{
return _rowsCopied;
}
}

internal SqlStatistics Statistics
{
get
Expand Down Expand Up @@ -2906,18 +2915,18 @@ private void CopyBatchesAsyncContinuedOnError(bool cleanupParser)
{
tdsReliabilitySection.Start();
#endif //DEBUG
if ((cleanupParser) && (_parser != null) && (_stateObj != null))
{
_parser._asyncWrite = false;
Task task = _parser.WriteBulkCopyDone(_stateObj);
Debug.Assert(task == null, "Write should not pend when error occurs");
RunParser();
}
if ((cleanupParser) && (_parser != null) && (_stateObj != null))
{
_parser._asyncWrite = false;
Task task = _parser.WriteBulkCopyDone(_stateObj);
Debug.Assert(task == null, "Write should not pend when error occurs");
RunParser();
}

if (_stateObj != null)
{
CleanUpStateObject();
}
if (_stateObj != null)
{
CleanUpStateObject();
}
#if DEBUG
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ public static void Test(string srcConstr, string dstConstr, string targettable)
ColumnMappings.Add("CustomerID", "CustomerID");

bulkcopy.WriteToServer(reader);
bulkcopy.Close();

DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 1, "Unexpected number of rows.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ public static void Test(string srcConstr, string dstConstr, string dstTable)
ColumnMappings.Add("ShipCountry", "ShipCountry");

bulkcopy.WriteToServer(reader);

DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 830, "Unexpected number of rows.");
}
Helpers.VerifyResults(dstConn, dstTable, 14, 830);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,9 @@ public static void Test(string constr, string dstTable)
ColumnMappings.Add("col 2", "[col 2]");

bulkcopy.WriteToServer(reader);

DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 1, "Unexpected number of rows.");
}

Helpers.VerifyResults(dstConn, dstTable, 2, 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public static void Test(string srcConstr, string dstConstr, string dstTable)
ColumnMappings.Add("FirstName", "col3");

bulkcopy.WriteToServer(reader);

DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 5, "Unexpected number of rows.");
}
Helpers.VerifyResults(dstConn, dstTable, 3, 5);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ private static async Task TestAsync(string srcConstr, string dstConstr, string d
bulkcopy.DestinationTableName = dstTable;

await bulkcopy.WriteToServerAsync(reader);
await outputSemaphore.WaitAsync();

DataTestUtility.AssertEqualsWithDescription(bulkcopy.RowsCopied, 5, "Unexpected number of rows.");
}
await outputSemaphore.WaitAsync();
Helpers.VerifyResults(dstConn, dstTable, 3, 5);
}
}
Expand Down