Conversation
When retrieving unbound SQL_C_BINARY data, drivers may set the length indicator to SQL_NO_TOTAL (-4) on intermediate SQL_SUCCESS_WITH_INFO calls when the remaining data length is unknown. The retrieval loop in get_ref_impl<std::vector<std::uint8_t>> only appended chunks when the indicator was positive, so every full 1024-byte chunk was silently dropped and only the final chunk was kept, returning n mod 1024 bytes. Handle SQL_NO_TOTAL by appending the full buffer, mirroring the existing SQL_C_CHAR and SQL_C_WCHAR blob paths. Fixes #1024. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Member
Author
|
Upstreamed to nanodbc as nanodbc/nanodbc#475. |
|
Removing the comment. I meant to post this in #1024 |
simonpcouch
approved these changes
Aug 22, 2026
simonpcouch
left a comment
Collaborator
There was a problem hiding this comment.
Yup, looks good. Thank you!
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.
Fixes #1024.
Problem
When retrieving unbound
SQL_C_BINARYcolumns, nanodbc reads the value in 1024-byte chunks via repeatedSQLGetDatacalls. The loop inget_ref_impl<std::vector<std::uint8_t>>only appended a chunk when the length indicator was positive:Per the ODBC spec, a driver may instead set the indicator to
SQL_NO_TOTAL(−4) on intermediateSQL_SUCCESS_WITH_INFOcalls when it does not know the remaining data length — which is what the Databricks/Simba Spark driver does. Since −4 fails the> 0test, every full 1024-byte chunk was silently discarded, and only the final chunk (returned withSQL_SUCCESSand a real length) was kept. That yields exactly the behavior reported in #1024:n mod 1024bytes returned, with exact multiples of 1024 surviving intact.(One note on the issue's analysis: the returned bytes are the last chunk, not a prefix — the reporter's prefix check used a period-256 payload with a length that is a multiple of 1024, where the two are byte-identical.)
Fix
Handle
SQL_NO_TOTALby appending the full buffer, exactly mirroring the existingSQL_C_CHARandSQL_C_WCHARblob paths a few lines above (which already have this branch). OnSQL_SUCCESS_WITH_INFO/01004 withSQL_C_BINARYthe driver fills the entire buffer, so appendingbuffer_sizeis correct.Testing
There is no regression test because reproducing this requires a driver that reports
SQL_NO_TOTALfor binary chunks (the Simba Spark driver does; the drivers in CI report actual remaining lengths, which take the already-correctValueLenOrInd > 0path). Verification against a Databricks warehouse per the repro in #1024 would be welcome.Upstream nanodbc
mainhas the identical gap in the binary path; I'd suggest upstreaming this patch as well.🤖 Generated with Claude Code