Skip to content

Comments

Add BCP bulk copy and streamed result set support for TDS 5.0#239

Open
Jakeharlan73 wants to merge 1 commit intoDataAction:masterfrom
Jakeharlan73:bcp-bulk-copy
Open

Add BCP bulk copy and streamed result set support for TDS 5.0#239
Jakeharlan73 wants to merge 1 commit intoDataAction:masterfrom
Jakeharlan73:bcp-bulk-copy

Conversation

@Jakeharlan73
Copy link

Summary

  • BCP IN/OUT (Bulk Copy Protocol): Implements high-performance bulk data loading and extraction using the native TDS 5.0 BCP wire protocol, following the SqlBulkCopy API pattern for familiarity
  • Streamed result sets: When CommandBehavior.SequentialAccess is requested, token processing runs on a background thread so the AseDataReader is returned as soon as the first result set arrives — enabling streaming consumption of large or multi-result-set queries

BCP Details

Public API:

  • AseBulkCopy.WriteToServer() — bulk insert from IDataReader or DataTable
  • AseBulkCopy.ReadFromServer() — bulk extraction to DataTable
  • Column mapping, batching, and row-copied notification support

Protocol:

  • Native BCP row format (no TDS_ROW token prefix)
  • APL and DOL (datarows-locked) offset table formats
  • REQ_BCP capability negotiation
  • All fixed and variable-length TDS data types (TEXT/IMAGE/UNITEXT deferred)

Streamed Result Sets

Small change to InternalConnection.ExecuteReaderTaskRunnable — when SequentialAccess is set, InternalExecuteQueryAsync runs via Task.Run() so the existing StreamingDataReaderTokenHandler can resolve the TaskCompletionSource<DbDataReader> after the first result set while the background thread continues receiving remaining data.

Test Plan

  • 972 lines of unit tests across 3 new test files (AseBulkCopyColumnMappingTests, BcpRowFormatterTests, BcpValueWriterTests)
  • All 1389 existing unit tests pass with no regressions
  • Verified 508-row round-trip (BCP OUT → BCP IN) with full data integrity

Implements bulk copy operations using the native TDS 5.0 BCP wire protocol,
enabling high-performance data loading (BCP IN) and extraction (BCP OUT)
for SAP ASE databases.

Public API follows the SqlBulkCopy pattern:
- AseBulkCopy.WriteToServer() for bulk insert from IDataReader/DataTable
- AseBulkCopy.ReadFromServer() for bulk extraction to DataTable
- Column mapping, batching, and row notification support

Protocol details:
- Native BCP row format (no TDS_ROW token prefix)
- APL and DOL (datarows-locked) offset table formats
- REQ_BCP capability negotiation
- Supports all fixed and variable-length TDS data types
  (TEXT/IMAGE/UNITEXT deferred)

Verified: 508-row round-trip (BCP OUT -> BCP IN) with full data integrity.
All 1389 existing unit tests pass with no regressions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant