Conversation
There was a problem hiding this comment.
Pull request overview
This pull request introduces dual parameter style support to the mssql_python package, enabling both qmark (?) and pyformat (%(name)s) parameter styles for SQL queries. The default paramstyle is changed from "qmark" to "pyformat" to align with common Python database patterns, while maintaining full backward compatibility with existing qmark-style code.
Key Changes:
- Added comprehensive parameter style detection and conversion logic with automatic fallback between qmark and pyformat styles
- Implemented robust parameter handling for single values, tuples, lists, and dictionaries across execute(), executemany(), and batch_execute() methods
- Created extensive test suite with 100+ test cases covering edge cases, error handling, and real-world usage scenarios
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| mssql_python/init.py | Changes default paramstyle from "qmark" to "pyformat" |
| mssql_python/parameter_helper.py | Adds new utility module with parse_pyformat_params(), convert_pyformat_to_qmark(), and detect_and_convert_parameters() functions |
| mssql_python/cursor.py | Updates execute() and executemany() methods to support automatic parameter style detection and conversion with single parameter wrapping |
| tests/test_001_globals.py | Updates paramstyle assertion to expect "pyformat" instead of "qmark" |
| tests/test_015_pyformat_parameters.py | Adds comprehensive test suite covering parsing, conversion, detection, edge cases, real-world scenarios, backward compatibility, and error handling |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.logger_bridge.hpp: 58.8%
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.row.py: 66.2%
mssql_python.helpers.py: 67.5%
mssql_python.pybind.ddbc_bindings.cpp: 69.3%
mssql_python.pybind.ddbc_bindings.h: 71.7%
mssql_python.pybind.connection.connection.cpp: 73.6%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.connection.py: 83.9%🔗 Quick Links
|
bewithgaurav
left a comment
There was a problem hiding this comment.
things lgtm, please make a priority to change wikis/docs accordingly ✅
Work Item / Issue Reference
Summary
This pull request introduces support for both
qmark(?) andpyformat(%(name)s) parameter styles in SQL queries, improving compatibility and usability for users of themssql_pythonpackage. The defaultparamstyleis now set topyformat, and bothexecuteandexecutemanymethods have been updated to automatically detect and convert parameter styles as needed. A new utility module,parameter_helper.py, has been added to handle parameter style parsing and conversion.Parameter style support and conversion:
paramstyleinmssql_python/__init__.pyfrom"qmark"to"pyformat", makingpyformatthe default parameter style.mssql_python/parameter_helper.pycontaining helper functions to parse pyformat parameters, convert pyformat SQL to qmark style, and auto-detect/convert parameter styles in queries.Enhancements to parameter handling in cursor methods:
executemethod inmssql_python/cursor.pyto auto-detect and convert parameter styles, supporting both single values and various parameter formats, and to use the new helper functions for conversion.executeto rely on the new auto-detection and conversion, removing the old manual flattening.executemanymethod inmssql_python/cursor.pyto auto-detect parameter style, convert pyformat to qmark for all rows if needed, and wrap single parameters for backward compatibility.Tests and validation:
test_paramstyletest intests/test_001_globals.pyto expect the new defaultparamstylevalue of"pyformat".