Commit 73e5a03
authored
FEAT: Adding set_attr in connection class (microsoft#177)
### 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. microsoft#149)
Only one reference is required - either GitHub issue OR ADO Work Item.
-->
<!-- mssql-python maintainers: ADO Work Item -->
>
[AB#39058](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/39058)
-------------------------------------------------------------------
### Summary
This pull request introduces comprehensive support for setting ODBC
connection attributes in the `mssql_python` library, aligning its
functionality with pyodbc's `set_attr` API. The changes include new
constants for connection attributes, transaction isolation levels, and
related options, as well as robust error handling and input validation
in both Python and C++ layers. This enables users to configure
connection behavior (e.g., autocommit, isolation level, timeouts) in a
standardized and secure manner.
### Connection Attribute Support
* Added a wide set of ODBC connection attribute constants, transaction
isolation level constants, access mode constants, and related enums to
`mssql_python/__init__.py` and `mssql_python/constants.py`, making them
available for use in Python code.
* Implemented the `set_attr` method in the `Connection` Python class,
providing pyodbc-compatible functionality for setting connection
attributes with detailed input validation and error handling.
### C++ Backend Enhancements
* Exposed `setAttribute` as a public method in the C++ `Connection`
class, and added a new `setAttr` method in `ConnectionHandle`, with
improved error reporting and range validation for SQLUINTEGER values.
* Registered the new `set_attr` method with the Python bindings, making
it accessible from Python code.
### Code Cleanup and Refactoring
* Moved and consolidated connection attribute constants in
`ConstantsDDBC` to improve maintainability, and removed legacy/unused
constants.
These changes provide a robust interface for configuring ODBC connection
attributes, improve compatibility with pyodbc, and enhance error
handling for attribute operations.1 parent 10a8815 commit 73e5a03
File tree
8 files changed
+2154
-48
lines changed- mssql_python
- pybind
- connection
- tests
8 files changed
+2154
-48
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
150 | 172 | | |
151 | 173 | | |
152 | 174 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
109 | 109 | | |
110 | 110 | | |
111 | 111 | | |
| 112 | + | |
112 | 113 | | |
113 | 114 | | |
114 | 115 | | |
| |||
129 | 130 | | |
130 | 131 | | |
131 | 132 | | |
132 | | - | |
133 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
134 | 142 | | |
135 | | - | |
136 | 143 | | |
137 | 144 | | |
138 | 145 | | |
| |||
143 | 150 | | |
144 | 151 | | |
145 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
146 | 159 | | |
147 | 160 | | |
148 | 161 | | |
| |||
546 | 559 | | |
547 | 560 | | |
548 | 561 | | |
| 562 | + | |
| 563 | + | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
| 573 | + | |
| 574 | + | |
| 575 | + | |
| 576 | + | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
| 615 | + | |
| 616 | + | |
| 617 | + | |
| 618 | + | |
| 619 | + | |
| 620 | + | |
| 621 | + | |
| 622 | + | |
| 623 | + | |
| 624 | + | |
| 625 | + | |
| 626 | + | |
549 | 627 | | |
550 | 628 | | |
551 | 629 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
23 | | - | |
24 | 23 | | |
25 | | - | |
26 | 24 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 25 | | |
31 | 26 | | |
32 | 27 | | |
33 | 28 | | |
34 | 29 | | |
35 | 30 | | |
36 | | - | |
37 | 31 | | |
38 | 32 | | |
39 | 33 | | |
| |||
94 | 88 | | |
95 | 89 | | |
96 | 90 | | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | 91 | | |
101 | 92 | | |
102 | 93 | | |
103 | | - | |
104 | 94 | | |
105 | 95 | | |
106 | 96 | | |
107 | 97 | | |
108 | 98 | | |
109 | 99 | | |
110 | | - | |
111 | 100 | | |
112 | 101 | | |
113 | 102 | | |
114 | 103 | | |
115 | 104 | | |
116 | 105 | | |
117 | 106 | | |
118 | | - | |
119 | 107 | | |
120 | 108 | | |
121 | 109 | | |
| |||
136 | 124 | | |
137 | 125 | | |
138 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
139 | 181 | | |
140 | 182 | | |
141 | 183 | | |
| |||
324 | 366 | | |
325 | 367 | | |
326 | 368 | | |
327 | | - | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
0 commit comments