Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Jun 25, 2025

ADO Work Item Reference

AB#34946


Summary

This pull request introduces significant updates to the mssql_python library, focusing on enhancing the BCPOptions and ColumnFormat classes, improving error handling, and adding comprehensive unit tests. The changes include refactoring the code for better maintainability, adding logging for debugging, and introducing new features and validations for bulk copy operations.

Enhancements to BCPOptions and ColumnFormat:

  • Added new fields to BCPOptions (query, row_terminator, bulk_mode) and ColumnFormat (user_data_type, terminator_len) to support additional BCP features. Updated default values for some fields. [1] [2] [3]
  • Introduced stricter validation for fields in both classes, including checks for non-negative integers, valid enumerations, and mutually exclusive options (e.g., columns vs. format_file). Logging has been added for detailed error messages. [1] [2]

Refactoring and Code Simplification:

  • Removed unused imports and fields (e.g., row_terminator from ColumnFormat and write_format_file from BCPOptions) to streamline the codebase. [1] [2]
  • Centralized allowed values for direction and bulk_mode into constants for better maintainability. [1] [2]

New Constants for BCP Options:

  • Introduced a new BCPControlOptions enum in constants.py to define string representations of BCP control options, improving clarity and consistency.

Unit Tests for Bulk Copy Operations:

  • Added a new test suite (tests/test_007_bulkOptions.py) with unit tests for BCPOptions and ColumnFormat. Tests cover valid instantiations, invalid values, and edge cases such as conflicts between columns and format_file.
  • Introduced fixtures for setting up temporary database tables and files, enabling integration tests for BCP operations.

Copilot AI review requested due to automatic review settings June 25, 2025 12:49
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances bulk copy capabilities in the mssql_python library by extending option classes, tightening validations, adding logging, and introducing comprehensive unit tests.

  • Extended BCPOptions and ColumnFormat with new fields (query, terminator_len, user_data_type, row_terminator) and default values.
  • Added stricter validation with detailed log messages and extracted constants for allowed directions and modes.
  • Introduced a new BCPControlOptions enum and a full test suite covering valid/invalid cases for bulk copy operations.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
tests/test_007_bulkOptions.py New tests for BCPOptions and ColumnFormat, covering invalid and edge cases.
mssql_python/constants.py Added BCPControlOptions enum for BCP control string constants.
mssql_python/bcp_options.py Refactored classes with new fields, logging, validation logic, and constants.
Comments suppressed due to low confidence (3)

mssql_python/bcp_options.py:14

  • [nitpick] The constant name ALLOWED_FILE_MODES may be misleading since it controls bulk_mode. Consider renaming it to ALLOWED_BULK_MODES for clarity.
ALLOWED_FILE_MODES = ("native", "char", "unicode")

mssql_python/bcp_options.py:1

  • The module and class docstrings should be updated to document the new fields (terminator_len, user_data_type, query, row_terminator) and their purpose for better API clarity.
"""

tests/test_007_bulkOptions.py:297

  • Add tests for the 'queryout' direction to verify that supplying a query is enforced and that other options behave correctly. Also consider tests for row_terminator behavior.
            )

@github-actions github-actions bot added the pr-size: large Substantial code update label Jul 1, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Jul 4, 2025
@jahnvi480 jahnvi480 marked this pull request as draft September 18, 2025 20:40
@jahnvi480 jahnvi480 closed this Sep 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: large Substantial code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants