FIX: Fixing Level 3 and level 4 compiler warnings.#72
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR addresses compiler warnings by adding explicit type casts for ODBC handles and parameters, introduces a utility for wide-to-UTF8 string conversion, and applies small cleanups for clarity.
- Added
WideToUTF8to centralize wstring→UTF-8 conversion and updated error/log messages to use it. - Applied
static_cast/reinterpret_castacross handle creation and parameter binding for strict type safety. - Fixed minor typos (e.g.,
std::memset, redundant semicolons) and improved length comparisons.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| mssql_python/pybind/ddbc_bindings.h | Declared new WideToUTF8 utility function |
| mssql_python/pybind/ddbc_bindings.cpp | Implemented WideToUTF8, casts in BindParameters, cleanup |
| mssql_python/pybind/connection/connection.cpp | Casted handle types, used WideToUTF8, removed unused var |
Comments suppressed due to low confidence (3)
mssql_python/pybind/ddbc_bindings.h:181
- [nitpick] Consider placing
WideToUTF8inside a dedicated namespace (e.g.,ddbc) to avoid global namespace pollution.
std::string WideToUTF8(const std::wstring& wstr);
mssql_python/pybind/ddbc_bindings.cpp:475
- Add unit tests for
WideToUTF8to verify conversion results and edge cases like empty or invalid wide strings.
std::string WideToUTF8(const std::wstring& wstr) {
mssql_python/pybind/connection/connection.cpp:125
- [nitpick] Add a brief comment explaining the cast chain (
static_castthenreinterpret_cast) forSQLSetConnectAttrto clarify why both are needed.
SQLRETURN ret = SQLSetConnectAttr_ptr(_dbcHandle->get(), SQL_ATTR_AUTOCOMMIT, reinterpret_cast<SQLPOINTER>(static_cast<SQLULEN>(value)), 0);
f772912 to
eb3b5db
Compare
sumitmsft
approved these changes
Jun 16, 2025
bewithgaurav
approved these changes
Jun 16, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AB#37476
This pull request focuses on improving type safety, enhancing error handling, and adding utility functions in the
mssql_python/pybindmodule. The changes primarily involve the use of explicit type casting, the introduction of aWideToUTF8utility function for string conversion, and minor fixes to improve code clarity and correctness.Type Safety Improvements:
std::make_shared<SqlHandle>calls across multiple functions inconnection.cppto usestatic_cast<SQLSMALLINT>for handle types (SQL_HANDLE_ENV,SQL_HANDLE_DBC,SQL_HANDLE_STMT) to ensure explicit type casting. [1] [2] [3]BindParametersto useSQLSMALLINTorSQLUSMALLINTinstead ofint. [1] [2] [3]SQLSetStmtAttr_ptrandSQLSetConnectAttr_ptrcalls to usereinterpret_castorstatic_castfor pointer conversions, ensuring type correctness. [1] [2] [3]Error Handling Enhancements:
LoadDriverOrThrowExceptionwith the newWideToUTF8utility function for better readability and consistency.WideToUTF8function inddbc_bindings.cppand declared it inddbc_bindings.hto handlestd::wstringtostd::stringconversions. [1] [2]Connection::checkErrorby usingWideToUTF8for converting wide error messages to UTF-8.Code Fixes and Cleanup:
std::memsetinBindParametersto correct the namespace usage.SQLGetData_wrapinitialization.SQLGetData_wrapandFetchBatchDatato usestatic_cast<size_t>for comparingdataLenwithcolumnSize. [1] [2]These changes collectively enhance the robustness, maintainability, and readability of the code.
Checklist