Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 21, 2025

Work Item / Issue Reference

AB#34907
AB#34908


Summary

This pull request adds support for configuring the decimal separator used when parsing and displaying NUMERIC/DECIMAL values in the mssql_python package. It introduces new Python and C++ APIs to control the decimal separator, ensures the separator is respected in string representations, and includes comprehensive tests to verify the new functionality.

Decimal separator configuration and propagation:

  • Added setDecimalSeparator and getDecimalSeparator functions in mssql_python/__init__.py to allow users to set and retrieve the decimal separator character, with input validation and propagation to the C++ layer (DDBCSetDecimalSeparator).
  • Introduced a global g_decimalSeparator variable and the DDBCSetDecimalSeparator function in C++ (ddbc_bindings.cpp and ddbc_bindings.h) to store and update the separator, and exposed this setter to Python via pybind11.

Integration with data handling and display:

  • Updated the C++ data fetching logic to use the configured decimal separator when converting NUMERIC/DECIMAL database values to Python Decimal objects, ensuring correct parsing and formatting.
  • Modified the Python Row.__str__ method to use the current decimal separator when displaying decimal values, so string representations reflect user configuration.

Testing:

  • Added and expanded tests in tests/test_001_globals.py and tests/test_004_cursor.py to cover the new decimal separator functionality, including validation, database operations, string formatting, and ensuring calculations are unaffected by the separator setting.
    These changes make the decimal separator fully configurable and ensure consistent behavior across both parsing and display of decimal values.

@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 21, 2025
Copy link
Contributor

@sumitmsft sumitmsft left a comment

Choose a reason for hiding this comment

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

Global state in multi-threaded environment

The current implementation uses global state (g_decimalSeparator) without considering thread safety. Given that this library is likely to be used in multi-threaded applications (web servers, concurrent data processing), this could lead to:

Data corruption: Concurrent string operations on g_decimalSeparator
Inconsistent behavior: Different threads seeing different separator values
Race conditions: Database operations using incorrect separators
Suggested Solutions:

Use std::atomicstd::string for the global variable
Add mutex protection around read/write operations
Consider thread-local storage for separator configuration
Encapsulate separator in a thread-safe configuration object/context

@sumitmsft
Copy link
Contributor

@jahnvi480
Ensure edge cases are covered:
Setting an invalid separator (empty string, multiple characters, non-ASCII)
Changing the separator during active DB operations
Multi-threaded scenarios >> This can be todo as we do not anticipate multithreaded env without async.
Changing the separator back and forth and confirming correct parsing/display each time
What happens if the separator is set after fetching a result set but before display

@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: medium Moderate update size labels Sep 15, 2025
sumitmsft
sumitmsft previously approved these changes Sep 16, 2025
@jahnvi480 jahnvi480 changed the base branch from jahnvi/global_lowercase to main September 18, 2025 03:43
@jahnvi480 jahnvi480 dismissed sumitmsft’s stale review September 18, 2025 03:43

The base branch was changed.

Copilot AI review requested due to automatic review settings September 18, 2025 05:11
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
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 adds support for configuring the decimal separator used when parsing and displaying NUMERIC/DECIMAL values in the mssql_python package. It introduces new Python and C++ APIs to control the decimal separator, ensures the separator is respected in string representations, and includes comprehensive tests to verify the new functionality.

  • Added setDecimalSeparator and getDecimalSeparator functions with input validation and C++ layer integration
  • Updated data handling logic to use the configured decimal separator when converting NUMERIC/DECIMAL database values
  • Modified the Row.str method to apply the custom decimal separator for display formatting

Reviewed Changes

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

Show a summary per file
File Description
mssql_python/init.py Adds global decimal separator functions with validation and C++ integration
mssql_python/pybind/ddbc_bindings.h Defines thread-safe decimal separator accessor class and helper functions
mssql_python/pybind/ddbc_bindings.cpp Implements decimal separator functionality in C++ data fetching logic
mssql_python/row.py Updates Row.str method to use custom decimal separator for display
mssql_python/cursor.py Minor formatting change (extra blank line)
tests/test_001_globals.py Comprehensive tests for decimal separator functionality including thread safety
tests/test_004_cursor.py Database operation tests for decimal separator with string formatting validation
Comments suppressed due to low confidence (1)

mssql_python/pybind/ddbc_bindings.cpp:1

  • The NULL data check was removed but the try-catch block doesn't handle the SQL_NULL_DATA case. This could cause issues when the database returns NULL values for NUMERIC/DECIMAL columns.
// Copyright (c) Microsoft Corporation.

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
sumitmsft
sumitmsft previously approved these changes Sep 18, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
@github-actions github-actions bot removed the pr-size: large Substantial code update label Sep 18, 2025
@github-actions github-actions bot added the pr-size: large Substantial code update label Sep 18, 2025
@jahnvi480 jahnvi480 merged commit 2b7f886 into main Sep 18, 2025
18 checks passed
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.

4 participants