You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
FIX: Improvement to parameter type inference and handling (#215)
### 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 -->
>
[AB#38383](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/38383)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #<ISSUE_NUMBER>
-------------------------------------------------------------------
### Summary
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->
This pull request refactors the logic for inferring SQL types from
Python parameters in the `mssql_python/cursor.py` module, especially for
batch operations using `executemany`. The main improvements are more
accurate type detection for integer columns by considering the minimum
and maximum values in the data, and a cleaner separation of concerns in
the codebase.
**Improvements to type inference and parameter handling:**
* Refactored the type mapping logic in `_map_sql_type` to use `min_val`
and `max_val` for integer columns, allowing for more accurate type
selection based on the actual range of values in the data.
* Updated `_create_parameter_types_list` to accept and forward `min_val`
and `max_val`, supporting the improved type inference for batch
operations.
* Replaced the static method `_select_best_sample_value` with a new
`_compute_column_type` method, which determines a representative sample
value and computes min/max for integer columns, enhancing how types are
inferred for each parameter column in `executemany`.
[[1]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280L827-L855)
[[2]](diffhunk://#diff-deceea46ae01082ce8400e14fa02f4b7585afb7b5ed9885338b66494f5f38280R848-R873)
* Modified the `executemany` method to use `_compute_column_type` for
each parameter column, passing the computed min/max values to
`_create_parameter_types_list` for better type assignment.
**Code cleanup:**
* Removed the now-unnecessary `_select_best_sample_value` static method,
consolidating logic and reducing code duplication.
<!--
### 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
-->
0 commit comments