Skip to content

Commit dc0e162

Browse files
FIX: Remove unused decimal separator code and add regression tests (#384)
### Work Item / Issue Reference <!-- IMPORTANT: Please follow the PR template guidelines below. For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452) For external contributors: Insert Github Issue number below (e.g. #149) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- mssql-python maintainers: ADO Work Item --> <!-- External contributors: GitHub Issue --> GitHub Issue: #295 ------------------------------------------------------------------- ### Summary Removes misleading unused decimal-separator code from the bulk fetch path and adds a regression test to ensure DECIMAL values are parsed correctly regardless of setDecimalSeparator(). <!-- ### PR Title Guide > For feature requests FEAT: (short-description) > For non-feature requests like test case updates, config updates , dependency updates etc CHORE: (short-description) > For Fix requests FIX: (short-description) > For doc update requests DOC: (short-description) > For Formatting, indentation, or styling update STYLE: (short-description) > For Refactor, without any feature changes REFACTOR: (short-description) > For release related changes, without any feature changes RELEASE: #<RELEASE_VERSION> (short-description) ### Contribution Guidelines External contributors: - Create a GitHub issue first: https://github.com/microsoft/mssql-python/issues/new - Link the GitHub issue in the "GitHub Issue" section above - Follow the PR title format and provide a meaningful summary mssql-python maintainers: - Create an ADO Work Item following internal processes - Link the ADO Work Item in the "ADO Work Item" section above - Follow the PR title format and provide a meaningful summary --> --------- Co-authored-by: Gaurav Sharma <sharmag@microsoft.com>
1 parent 95e0836 commit dc0e162

10 files changed

+481
-866
lines changed

mssql_python/logging.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import atexit
1818
from typing import Optional
1919

20-
2120
# Single DEBUG level - all or nothing philosophy
2221
# If you need logging, you need to see everything
2322
DEBUG = logging.DEBUG # 10

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,7 +2892,7 @@ SQLRETURN SQLGetData_wrap(SqlHandlePtr StatementHandle, SQLUSMALLINT colCount, p
28922892
SQLHSTMT hStmt = StatementHandle->get();
28932893

28942894
// Cache decimal separator to avoid repeated system calls
2895-
std::string decimalSeparator = GetDecimalSeparator();
2895+
28962896

28972897
for (SQLSMALLINT i = 1; i <= colCount; ++i) {
28982898
SQLWCHAR columnName[256];
@@ -3615,7 +3615,7 @@ SQLRETURN FetchBatchData(SQLHSTMT hStmt, ColumnBuffers& buffers, py::list& colum
36153615
columnInfos[col].processedColumnSize + 1; // +1 for null terminator
36163616
}
36173617

3618-
std::string decimalSeparator = GetDecimalSeparator(); // Cache decimal separator
3618+
36193619

36203620
// Performance: Build function pointer dispatch table (once per batch)
36213621
// This eliminates the switch statement from the hot loop - 10,000 rows × 10

tests/test_001_globals.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -388,8 +388,7 @@ def test_decimal_separator_with_db_operations(db_connection):
388388
try:
389389
# Create a test table with decimal values
390390
cursor = db_connection.cursor()
391-
cursor.execute(
392-
"""
391+
cursor.execute("""
393392
DROP TABLE IF EXISTS #decimal_separator_test;
394393
CREATE TABLE #decimal_separator_test (
395394
id INT,
@@ -400,8 +399,7 @@ def test_decimal_separator_with_db_operations(db_connection):
400399
(2, 678.90),
401400
(3, 0.01),
402401
(4, 999.99);
403-
"""
404-
)
402+
""")
405403
cursor.close()
406404

407405
# Test 1: Fetch with default separator
@@ -469,8 +467,7 @@ def test_decimal_separator_batch_operations(db_connection):
469467
try:
470468
# Create test data
471469
cursor = db_connection.cursor()
472-
cursor.execute(
473-
"""
470+
cursor.execute("""
474471
DROP TABLE IF EXISTS #decimal_batch_test;
475472
CREATE TABLE #decimal_batch_test (
476473
id INT,
@@ -481,8 +478,7 @@ def test_decimal_separator_batch_operations(db_connection):
481478
(1, 123.456, 12345.67890),
482479
(2, 0.001, 0.00001),
483480
(3, 999.999, 9999.99999);
484-
"""
485-
)
481+
""")
486482
cursor.close()
487483

488484
# Test 1: Fetch results with default separator

tests/test_003_connection.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -992,16 +992,14 @@ def test_execute_with_large_parameters(db_connection, conn_str):
992992
pytest.skip("Skipping for Azure SQL - large parameter tests may cause timeouts")
993993

994994
# Test with a temporary table for large data
995-
cursor = db_connection.execute(
996-
"""
995+
cursor = db_connection.execute("""
997996
DROP TABLE IF EXISTS #large_params_test;
998997
CREATE TABLE #large_params_test (
999998
id INT,
1000999
large_text NVARCHAR(MAX),
10011000
large_binary VARBINARY(MAX)
10021001
)
1003-
"""
1004-
)
1002+
""")
10051003
cursor.close()
10061004

10071005
try:
@@ -2126,12 +2124,10 @@ def test_timeout_long_query(db_connection):
21262124
while retry_count < max_retries:
21272125
start_time = time.perf_counter()
21282126
try:
2129-
cursor.execute(
2130-
"""
2127+
cursor.execute("""
21312128
SELECT COUNT(*) FROM sys.objects a, sys.objects b, sys.objects c
21322129
WHERE a.object_id = b.object_id * c.object_id
2133-
"""
2134-
)
2130+
""")
21352131
cursor.fetchall()
21362132
elapsed_time = time.perf_counter() - start_time
21372133
break # Success, exit retry loop

0 commit comments

Comments
 (0)