@@ -2451,13 +2451,9 @@ def nextset(self) -> Union[bool, None]:
24512451 )
24522452 return True
24532453
2454- def _bulkcopy (self , table_name : str , data , ** kwargs ):
2454+ def _bulkcopy (self , table_name : str , data , ** kwargs ): # pragma: no cover
24552455 """
2456- Perform bulk copy operation using Rust-based implementation.
2457-
2458- This method uses a separate connection to the database via the Rust library
2459- (mssql_py_core) for optimized bulk data transfer. The connection parameters
2460- are extracted from the current Python connection's connection string.
2456+ Perform bulk copy operation for high-performance data loading.
24612457
24622458 Important: Transaction Isolation
24632459 The bulk copy operation creates its own connection and does NOT participate
@@ -2509,9 +2505,27 @@ def generate_data():
25092505 for i in range(1000000):
25102506 yield (i, f'Name_{i}', datetime.date.today())
25112507
2512- **kwargs: Additional options passed to the Rust bulkcopy method
2513- - column_mappings: List of tuples mapping source column index to
2514- target column name, e.g., [(0, 'id'), (1, 'name')]
2508+ **kwargs: Additional bulk copy options.
2509+
2510+ column_mappings (List[Tuple[int, str]], optional):
2511+ Maps source data column indices to target table column names.
2512+ Each tuple is (source_index, target_column_name) where:
2513+ - source_index: 0-based index of the column in the source data
2514+ - target_column_name: Name of the target column in the database table
2515+
2516+ When omitted: Columns are mapped by ordinal position (first data
2517+ column → first table column, second → second, etc.)
2518+
2519+ When specified: Only the mapped columns are inserted; unmapped
2520+ source columns are ignored, and unmapped target columns must
2521+ have default values or allow NULL.
2522+
2523+ Example:
2524+ # Source data has columns: [id, first_name, last_name, age]
2525+ # Target table has columns: [user_id, name, age]
2526+ # Map source index 0 to 'user_id', index 1 to 'name', index 3 to 'age'
2527+ column_mappings = [(0, 'user_id'), (1, 'name'), (3, 'age')]
2528+ result = cursor._bulkcopy('users', data, column_mappings=column_mappings)
25152529
25162530 Returns:
25172531 Dictionary with bulk copy results including:
@@ -2520,7 +2534,7 @@ def generate_data():
25202534 - elapsed_time: Time taken for the operation
25212535
25222536 Raises:
2523- ImportError: If mssql_py_core Rust library is not installed
2537+ ImportError: If mssql_py_core library is not installed
25242538 ValueError: If table_name is empty or parameters are invalid
25252539 RuntimeError: If connection string is not available
25262540
0 commit comments