Commit 247174e
authored
FIX: Fixing Level 3 and level 4 compiler warnings. (#72)
[AB#37476](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/37476)
This pull request focuses on improving type safety, enhancing error
handling, and adding utility functions in the `mssql_python/pybind`
module. The changes primarily involve the use of explicit type casting,
the introduction of a `WideToUTF8` utility function for string
conversion, and minor fixes to improve code clarity and correctness.
### Type Safety Improvements:
* Updated `std::make_shared<SqlHandle>` calls across multiple functions
in `connection.cpp` to use `static_cast<SQLSMALLINT>` for handle types
(`SQL_HANDLE_ENV`, `SQL_HANDLE_DBC`, `SQL_HANDLE_STMT`) to ensure
explicit type casting.
[[1]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL30-R30)
[[2]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL57-R57)
[[3]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL151-R151)
* Added explicit type casting for SQL date, time, and timestamp fields
in `BindParameters` to use `SQLSMALLINT` or `SQLUSMALLINT` instead of
`int`.
[[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L323-R325)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L336-R338)
[[3]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L349-R354)
* Updated various `SQLSetStmtAttr_ptr` and `SQLSetConnectAttr_ptr` calls
to use `reinterpret_cast` or `static_cast` for pointer conversions,
ensuring type correctness.
[[1]](diffhunk://#diff-eca696c13d997f510e5f9b16288ed1deb0ad132768c283eda1518f78edf9b6ecL125-R125)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L1705-R1714)
[[3]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L1793-R1802)
### Error Handling Enhancements:
* Replaced manual wide-to-narrow string conversion in
`LoadDriverOrThrowException` with the new `WideToUTF8` utility function
for better readability and consistency.
* Introduced the `WideToUTF8` function in `ddbc_bindings.cpp` and
declared it in `ddbc_bindings.h` to handle `std::wstring` to
`std::string` conversions.
[[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1R475-R482)
[[2]](diffhunk://#diff-85167a2d59779df18704284ab7ce46220c3619408fbf22c631ffdf29f794d635R180-R181)
* Enhanced error message handling in `Connection::checkError` by using
`WideToUTF8` for converting wide error messages to UTF-8.
### Code Fixes and Cleanup:
* Fixed a typo in `std::memset` in `BindParameters` to correct the
namespace usage.
* Corrected redundant semicolon in `SQLGetData_wrap` initialization.
* Improved comparison logic in `SQLGetData_wrap` and `FetchBatchData` to
use `static_cast<size_t>` for comparing `dataLen` with `columnSize`.
[[1]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L1140-R1149)
[[2]](diffhunk://#diff-dde2297345718ec449a14e7dff91b7bb2342b008ecc071f562233646d71144a1L1554-R1563)
These changes collectively enhance the robustness, maintainability, and
readability of the code.
### Checklist
- [ ] **Tests Passed** (if applicable) : All pytests passed.1 parent 0130211 commit 247174e
File tree
3 files changed
+40
-30
lines changed- mssql_python/pybind
- connection
3 files changed
+40
-30
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
57 | | - | |
| 57 | + | |
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| |||
91 | 91 | | |
92 | 92 | | |
93 | 93 | | |
94 | | - | |
| 94 | + | |
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
| |||
122 | 122 | | |
123 | 123 | | |
124 | 124 | | |
125 | | - | |
| 125 | + | |
126 | 126 | | |
127 | 127 | | |
128 | 128 | | |
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
151 | | - | |
| 151 | + | |
152 | 152 | | |
153 | 153 | | |
154 | 154 | | |
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
217 | | - | |
218 | 217 | | |
219 | 218 | | |
220 | 219 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
320 | 320 | | |
321 | 321 | | |
322 | 322 | | |
323 | | - | |
324 | | - | |
325 | | - | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
326 | 326 | | |
327 | 327 | | |
328 | 328 | | |
| |||
333 | 333 | | |
334 | 334 | | |
335 | 335 | | |
336 | | - | |
337 | | - | |
338 | | - | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
339 | 339 | | |
340 | 340 | | |
341 | 341 | | |
| |||
346 | 346 | | |
347 | 347 | | |
348 | 348 | | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
355 | 355 | | |
356 | 356 | | |
357 | 357 | | |
| |||
372 | 372 | | |
373 | 373 | | |
374 | 374 | | |
375 | | - | |
| 375 | + | |
376 | 376 | | |
377 | 377 | | |
378 | 378 | | |
| |||
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | | - | |
399 | | - | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
400 | 403 | | |
401 | 404 | | |
402 | 405 | | |
| |||
406 | 409 | | |
407 | 410 | | |
408 | 411 | | |
409 | | - | |
| 412 | + | |
410 | 413 | | |
411 | 414 | | |
412 | 415 | | |
| |||
469 | 472 | | |
470 | 473 | | |
471 | 474 | | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
472 | 483 | | |
473 | 484 | | |
474 | 485 | | |
| |||
523 | 534 | | |
524 | 535 | | |
525 | 536 | | |
526 | | - | |
527 | | - | |
| 537 | + | |
528 | 538 | | |
529 | 539 | | |
530 | 540 | | |
| |||
597 | 607 | | |
598 | 608 | | |
599 | 609 | | |
600 | | - | |
601 | 610 | | |
602 | 611 | | |
603 | 612 | | |
| |||
860 | 869 | | |
861 | 870 | | |
862 | 871 | | |
863 | | - | |
| 872 | + | |
864 | 873 | | |
865 | 874 | | |
866 | 875 | | |
| |||
1137 | 1146 | | |
1138 | 1147 | | |
1139 | 1148 | | |
1140 | | - | |
| 1149 | + | |
1141 | 1150 | | |
1142 | 1151 | | |
1143 | 1152 | | |
| |||
1551 | 1560 | | |
1552 | 1561 | | |
1553 | 1562 | | |
1554 | | - | |
| 1563 | + | |
1555 | 1564 | | |
1556 | 1565 | | |
1557 | 1566 | | |
| |||
1702 | 1711 | | |
1703 | 1712 | | |
1704 | 1713 | | |
1705 | | - | |
| 1714 | + | |
1706 | 1715 | | |
1707 | 1716 | | |
1708 | 1717 | | |
| |||
1790 | 1799 | | |
1791 | 1800 | | |
1792 | 1801 | | |
1793 | | - | |
| 1802 | + | |
1794 | 1803 | | |
1795 | 1804 | | |
1796 | 1805 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
0 commit comments