-
Notifications
You must be signed in to change notification settings - Fork 27
FIX: Invalid data type for None #332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request fixes an issue with the data type mapping for NULL parameters in the _map_sql_type function. The change updates the C type for NULL parameters from SQL_C_DEFAULT (99) to SQL_C_CHAR (-8), which aligns with the SQL type SQL_VARCHAR that's also returned for NULL parameters.
Key changes:
- Updated the C type for NULL parameters in
_map_sql_typefromSQL_C_DEFAULTtoSQL_C_CHARto match theSQL_VARCHARSQL type being used
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
📊 Code Coverage Report
Diff CoverageDiff: main...HEAD, staged and unstaged changes
Summary
mssql_python/pybind/ddbc_bindings.cppLines 2189-2199 2189
2190 // Verify all values are indeed NULL
2191 for (size_t i = 0; i < paramSetSize; ++i) {
2192 if (!columnValues[i].is_none()) {
! 2193 LOG("BindParameterArray: SQL_C_DEFAULT non-NULL value detected - param_index=%d, row=%zu", paramIndex, i);
! 2194 ThrowStdException("SQL_C_DEFAULT (99) should only be used for NULL parameters at index " + std::to_string(paramIndex));
! 2195 }
2196 }
2197
2198 // For NULL parameters, we need to allocate a minimal buffer and set all indicators to SQL_NULL_DATA
2199 // Use SQL_C_CHAR as a safe default C type for NULL valuesLines 2208-2216 2208 dataPtr = nullBuffer;
2209 bufferLength = 1;
2210 LOG("BindParameterArray: SQL_C_DEFAULT bound - param_index=%d, all_null=true", paramIndex);
2211 break;
! 2212 }
2213 default: {
2214 LOG("BindParameterArray: Unsupported C type - param_index=%d, C_type=%d", paramIndex, info.paramCType);
2215 ThrowStdException("BindParameterArray: Unsupported C type: " + std::to_string(info.paramCType));
2216 }📋 Files Needing Attention📉 Files with overall lowest coverage (click to expand)mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.helpers.py: 66.6%
mssql_python.row.py: 67.4%
mssql_python.pybind.ddbc_bindings.cpp: 70.4%
mssql_python.pybind.connection.connection.cpp: 76.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.pybind.ddbc_bindings.h: 79.7%
mssql_python.connection.py: 82.5%
mssql_python.cursor.py: 83.7%🔗 Quick Links
|
Summary
This pull request adds support for binding arrays of NULL parameters in SQL statements and introduces a corresponding test to ensure correct behavior when executing multiple inserts with only NULL values. The main focus is on handling the
SQL_C_DEFAULTtype for parameter arrays, ensuring all values are NULL, and verifying this functionality through unit testing.Parameter binding improvements:
BindParameterArrayinddbc_bindings.cppto handle theSQL_C_DEFAULTtype, ensuring that arrays of NULL values are properly bound and validated. If any non-NULL value is detected, an exception is thrown.Testing enhancements:
test_executemany_NONE_parameter_listintest_004_cursor.pyto verify thatexecutemanycorrectly inserts rows with all NULL values and that the count matches the expected number of inserts.