Skip to content

Conversation

gargsaumya
Copy link
Contributor

@gargsaumya gargsaumya commented Aug 28, 2025

Work Item / Issue Reference

AB#33395

GitHub Issue: #<ISSUE_NUMBER>


Summary

This pull request focuses on improving type safety and error handling for parameter binding and execution in the MSSQL Python driver, especially for string and binary types. The changes ensure that only supported Python types are bound to SQL parameters and that errors are raised for unsupported types, preventing silent failures. Additionally, the data-at-execution (DAE) streaming path for strings is now more robust and explicit.

Parameter type safety and error handling:

  • Changed _map_sql_type in cursor.py to raise a TypeError for unsupported parameter types instead of defaulting to SQL_VARCHAR, preventing silent type mismatches.
  • In ddbc_bindings.cpp, added explicit type checks for SQL_C_CHAR and SQL_C_BINARY bindings, raising an error if the Python object is not a string or bytes-like object.

DAE (Data At Execution) streaming improvements:

  • Enhanced the DAE streaming logic for SQL_C_CHAR in ddbc_bindings.cpp to handle string parameters more robustly, including chunked streaming via SQLPutData.
  • Added support for chunked DAE streaming of Python str objects mapped to SQL_C_CHAR, ensuring large strings are sent in manageable pieces.

Platform-specific encoding for wide strings:

  • Ensured that wide string (SQL_C_WCHAR) parameters are correctly converted to the platform-specific encoding before streaming.

@gargsaumya gargsaumya changed the title varcharmax streaming support in execute FEAT: varcharmax streaming support in execute Aug 28, 2025
@github-actions github-actions bot added the pr-size: small Minimal code update label Aug 28, 2025
@gargsaumya gargsaumya force-pushed the saumya/nvarcharmax-execute branch 2 times, most recently from 8e53235 to 48338d6 Compare August 28, 2025 16:32
@gargsaumya gargsaumya force-pushed the saumya/varcharmax-execute branch from 644c517 to 786ebef Compare August 29, 2025 04:30
@gargsaumya gargsaumya changed the base branch from saumya/nvarcharmax-execute to main August 29, 2025 04:31
@github-actions github-actions bot added pr-size: small Minimal code update and removed pr-size: small Minimal code update labels Aug 29, 2025
@Copilot Copilot AI review requested due to automatic review settings August 29, 2025 06:00
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: small Minimal code update labels Aug 29, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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 PR enhances the MSSQL Python driver by adding support for VARCHAR(MAX) streaming through data-at-execution (DAE) and improving type safety for parameter binding. The changes focus on robust handling of large string parameters and preventing silent type mismatches.

Key changes:

  • Added DAE streaming support for both SQL_C_CHAR and SQL_C_WCHAR parameter types with chunked data transmission
  • Enhanced type validation in parameter binding to raise explicit errors for unsupported types
  • Added comprehensive test coverage for VARCHAR(MAX) and NVARCHAR(MAX) operations in both LOB and non-LOB scenarios

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
mssql_python/pybind/ddbc_bindings.cpp Implements DAE streaming logic for string parameters and adds type validation for SQL_C_CHAR and SQL_C_BINARY bindings
tests/test_004_cursor.py Adds test cases for VARCHAR(MAX) and NVARCHAR(MAX) insert operations covering both small and large data scenarios

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Aug 29, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Aug 29, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Aug 29, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Aug 29, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 1, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 1, 2025
@gargsaumya gargsaumya force-pushed the saumya/varcharmax-execute branch from 581b297 to 72c6a18 Compare September 1, 2025 11:37
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 1, 2025
@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Sep 1, 2025
@gargsaumya gargsaumya merged commit 83ab8ea into main Sep 2, 2025
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-size: medium Moderate update size
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants