FEAT: varbinarymax streaming support in execute() by gargsaumya · Pull Request #231 · microsoft/mssql-python

Work Item / Issue Reference

AB#33395

GitHub Issue: #<ISSUE_NUMBER>


Summary

This pull request adds support for streaming large binary parameters (bytes and bytearray) to SQL Server using VARBINARY(MAX), removing the previous limitation that prevented inserting binary data larger than 8192 bytes. The changes update both the Python and C++ layers to detect large binary parameters, use deferred execution (DAE) for streaming, and add new tests to verify correct handling of both small and large binary data.

Binary parameter streaming support:

  • Updated _map_sql_type in cursor.py to detect large bytes/bytearray parameters (>8000 bytes) and mark them for VARBINARY(MAX) streaming, while still handling small binaries directly.
  • Modified parameter binding in ddbc_bindings.cpp to use deferred execution for large binaries, and to allocate/bind buffers correctly for both small and large binary parameters.
  • Enhanced SQLExecute_wrap in ddbc_bindings.cpp to stream large binary data using SQLPutData in chunks during execution.

Testing improvements:

  • Refactored and expanded tests in test_004_cursor.py to separately verify small/medium binary inserts and to add a new test for inserting large binary data (>8000 bytes) using streaming. [1] [2]