Commit 590af57
authored
FEAT: Support for Complex Data Type- sql_variant (#446)
### Work Item / Issue Reference
<!--
IMPORTANT: Please follow the PR template guidelines below.
For mssql-python maintainers: Insert your ADO Work Item ID below
For external contributors: Insert Github Issue number below
Only one reference is required - either GitHub issue OR ADO Work Item.
-->
<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#42724](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/42724)
<!-- External contributors: GitHub Issue -->
> GitHub Issue: #<ISSUE_NUMBER>
-------------------------------------------------------------------
### Summary
<!-- Insert your summary of changes below. Minimum 10 characters
required. -->
This pull request adds support for the `sql_variant` SQL Server type to
the Python MSSQL driver, ensuring that `sql_variant` columns are fetched
and mapped correctly to their underlying types. The changes introduce
new constants, update type mappings, and enhance the fetch logic to
detect and process `sql_variant` columns using their native types,
improving compatibility and correctness when handling complex data.
**Support for sql_variant type**
* Added the `SQL_SS_VARIANT` constant and related attribute constants in
both `mssql_python/constants.py` and the C++ binding layer to enable
recognition and handling of the `sql_variant` type.
[[1]](diffhunk://#diff-e6d80f1000af6fd5afca05f435b11fd82df7f5c3e75ecf5763f85d3aacdbe758R120)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R30-R34)
* Included `SQL_SS_VARIANT` in the set of valid types for type
validation logic.
**Type mapping and fetch logic**
* Updated the C type mapping in `cursor.py` so that `SQL_SS_VARIANT` is
mapped to `SQL_C_BINARY`, allowing binary transfer of the variant data.
* Implemented a helper function in the C++ layer to map a
`sql_variant`'s underlying C type to the appropriate SQL data type,
enabling the fetch logic to reuse existing code for each possible
underlying type.
* Enhanced the fetch routines (`SQLGetData_wrap`, `FetchMany_wrap`, and
`FetchAll_wrap`) to detect `sql_variant` columns, determine their true
data types at runtime, and handle them with the correct logic. This
includes always using the streaming fetch path for `sql_variant` columns
to preserve native type fidelity.
[[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2932-R3020)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L4044-R4144)
[[3]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R4229-R4274)
**Other improvements**
* Improved error logging and debug output for easier troubleshooting and
visibility into how `sql_variant` columns are processed.
[[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L1156-R1162)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L2932-R3020)
[[3]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L4044-R4144)
[[4]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R4229-R4274)
These changes collectively ensure that the driver can now fully support
reading `sql_variant` columns, mapping them to their actual types, and
handling them efficiently.
<!--
### 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
-->1 parent 78ddbbb commit 590af57
4 files changed
Lines changed: 755 additions & 39 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
376 | 377 | | |
377 | 378 | | |
378 | 379 | | |
| 380 | + | |
379 | 381 | | |
380 | 382 | | |
381 | 383 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
883 | 883 | | |
884 | 884 | | |
885 | 885 | | |
| 886 | + | |
886 | 887 | | |
887 | 888 | | |
888 | 889 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
31 | 44 | | |
32 | 45 | | |
33 | 46 | | |
| |||
2914 | 2927 | | |
2915 | 2928 | | |
2916 | 2929 | | |
| 2930 | + | |
| 2931 | + | |
| 2932 | + | |
| 2933 | + | |
| 2934 | + | |
| 2935 | + | |
| 2936 | + | |
| 2937 | + | |
| 2938 | + | |
| 2939 | + | |
| 2940 | + | |
| 2941 | + | |
| 2942 | + | |
| 2943 | + | |
| 2944 | + | |
| 2945 | + | |
| 2946 | + | |
| 2947 | + | |
| 2948 | + | |
| 2949 | + | |
| 2950 | + | |
| 2951 | + | |
| 2952 | + | |
| 2953 | + | |
| 2954 | + | |
| 2955 | + | |
| 2956 | + | |
| 2957 | + | |
| 2958 | + | |
| 2959 | + | |
| 2960 | + | |
| 2961 | + | |
| 2962 | + | |
| 2963 | + | |
| 2964 | + | |
| 2965 | + | |
| 2966 | + | |
| 2967 | + | |
| 2968 | + | |
| 2969 | + | |
| 2970 | + | |
| 2971 | + | |
| 2972 | + | |
| 2973 | + | |
| 2974 | + | |
| 2975 | + | |
| 2976 | + | |
| 2977 | + | |
| 2978 | + | |
| 2979 | + | |
| 2980 | + | |
| 2981 | + | |
| 2982 | + | |
| 2983 | + | |
| 2984 | + | |
| 2985 | + | |
| 2986 | + | |
| 2987 | + | |
| 2988 | + | |
| 2989 | + | |
| 2990 | + | |
2917 | 2991 | | |
2918 | 2992 | | |
2919 | 2993 | | |
| |||
2952 | 3026 | | |
2953 | 3027 | | |
2954 | 3028 | | |
2955 | | - | |
| 3029 | + | |
| 3030 | + | |
| 3031 | + | |
| 3032 | + | |
| 3033 | + | |
| 3034 | + | |
| 3035 | + | |
| 3036 | + | |
| 3037 | + | |
| 3038 | + | |
| 3039 | + | |
| 3040 | + | |
| 3041 | + | |
| 3042 | + | |
| 3043 | + | |
| 3044 | + | |
| 3045 | + | |
| 3046 | + | |
| 3047 | + | |
| 3048 | + | |
| 3049 | + | |
| 3050 | + | |
| 3051 | + | |
| 3052 | + | |
| 3053 | + | |
| 3054 | + | |
| 3055 | + | |
| 3056 | + | |
| 3057 | + | |
| 3058 | + | |
| 3059 | + | |
| 3060 | + | |
| 3061 | + | |
| 3062 | + | |
| 3063 | + | |
| 3064 | + | |
2956 | 3065 | | |
2957 | 3066 | | |
2958 | 3067 | | |
| |||
4118 | 4227 | | |
4119 | 4228 | | |
4120 | 4229 | | |
4121 | | - | |
4122 | | - | |
4123 | | - | |
4124 | | - | |
| 4230 | + | |
4125 | 4231 | | |
4126 | 4232 | | |
4127 | 4233 | | |
| |||
4211 | 4317 | | |
4212 | 4318 | | |
4213 | 4319 | | |
| 4320 | + | |
| 4321 | + | |
| 4322 | + | |
| 4323 | + | |
| 4324 | + | |
| 4325 | + | |
| 4326 | + | |
| 4327 | + | |
| 4328 | + | |
| 4329 | + | |
| 4330 | + | |
| 4331 | + | |
| 4332 | + | |
| 4333 | + | |
| 4334 | + | |
| 4335 | + | |
| 4336 | + | |
| 4337 | + | |
| 4338 | + | |
| 4339 | + | |
| 4340 | + | |
| 4341 | + | |
| 4342 | + | |
| 4343 | + | |
| 4344 | + | |
| 4345 | + | |
| 4346 | + | |
| 4347 | + | |
| 4348 | + | |
| 4349 | + | |
| 4350 | + | |
| 4351 | + | |
| 4352 | + | |
| 4353 | + | |
4214 | 4354 | | |
4215 | 4355 | | |
4216 | 4356 | | |
| |||
4251 | 4391 | | |
4252 | 4392 | | |
4253 | 4393 | | |
4254 | | - | |
4255 | | - | |
4256 | | - | |
4257 | | - | |
4258 | | - | |
4259 | | - | |
4260 | | - | |
4261 | | - | |
4262 | | - | |
4263 | | - | |
4264 | | - | |
4265 | | - | |
4266 | | - | |
4267 | | - | |
4268 | | - | |
4269 | | - | |
4270 | | - | |
4271 | | - | |
4272 | | - | |
4273 | | - | |
4274 | | - | |
4275 | | - | |
4276 | | - | |
4277 | | - | |
4278 | | - | |
4279 | | - | |
4280 | | - | |
4281 | | - | |
4282 | | - | |
4283 | | - | |
4284 | | - | |
4285 | | - | |
4286 | | - | |
4287 | | - | |
4288 | 4394 | | |
4289 | 4395 | | |
4290 | 4396 | | |
| |||
0 commit comments