Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Dec 22, 2025

Work Item / Issue Reference

AB#40995

GitHub Issue: #20


Summary

This pull request introduces support for both qmark (?) and pyformat (%(name)s) parameter styles in SQL queries, improving compatibility and usability for users of the mssql_python package. The default paramstyle is now set to pyformat, and both execute and executemany methods 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:

  • Changed the global paramstyle in mssql_python/__init__.py from "qmark" to "pyformat", making pyformat the default parameter style.
  • Added a new module mssql_python/parameter_helper.py containing 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:

  • Updated the execute method in mssql_python/cursor.py to auto-detect and convert parameter styles, supporting both single values and various parameter formats, and to use the new helper functions for conversion.
  • Refactored parameter flattening logic in execute to rely on the new auto-detection and conversion, removing the old manual flattening.
  • Enhanced the executemany method in mssql_python/cursor.py to auto-detect parameter style, convert pyformat to qmark for all rows if needed, and wrap single parameters for backward compatibility.

Tests and validation:

  • Updated the test_paramstyle test in tests/test_001_globals.py to expect the new default paramstyle value of "pyformat".

Copilot AI review requested due to automatic review settings December 22, 2025 05:57
@github-actions github-actions bot added the pr-size: large Substantial code update label Dec 22, 2025
@jahnvi480 jahnvi480 marked this pull request as draft December 22, 2025 06:00
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 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.

@github-actions
Copy link

github-actions bot commented Dec 22, 2025

📊 Code Coverage Report

🔥 Diff Coverage

98%


🎯 Overall Coverage

76%


📈 Total Lines Covered: 5435 out of 7116
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

  • mssql_python/init.py (100%)
  • mssql_python/cursor.py (96.3%): Missing lines 1263
  • mssql_python/parameter_helper.py (100%)

Summary

  • Total: 82 lines
  • Missing: 1 line
  • Coverage: 98%

mssql_python/cursor.py

Lines 1259-1267

  1259 
  1260             # Convert back to list format expected by the binding code
  1261             # detect_and_convert_parameters always returns None, tuple, or list
  1262             if converted_params is None:
! 1263                 parameters = []
  1264             else:
  1265                 parameters = list(converted_params)
  1266         else:
  1267             parameters = []


📋 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

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

@jahnvi480 jahnvi480 marked this pull request as ready for review December 22, 2025 07:50
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