Skip to content
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

Fix case when SQLGetData data size exceeds column size #346

Merged
merged 2 commits into from
Aug 11, 2022
Merged

Fix case when SQLGetData data size exceeds column size #346

merged 2 commits into from
Aug 11, 2022

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Aug 11, 2022

Fixes #328. Ok, a bit nasty, but here's the rundown:

  • This is mostly outlined here
  • The issue is that for our result set, the cursor may be told that a give column has a certain size in bytes, particularly for variable-sized columns like VARCHAR
  • BUT, the driver then may have to "convert to the target type" and this conversion may result in the actual data size being larger than we orignally allocated for
  • But wait, you may ask, don't we already account for this case here by resizing the buffer and calling SQLGetData again to retrieve the rest of the data?
  • Why yes, we do, but only for "long" data types, which is the primary use case for the multiple SQLGetData calls
  • So basically this is another case where, totally depending on the db driver, we might end up with truncated data which will result in API.SQL_SUCCESS_WITH_INFO being returned from SQLGetData

Thankfully the fix is relatively easy: we just need to use our buffer-resizing branch if the data type is long OR SQLGetData returns this success with info status code.

Fixes #328. Ok, a bit nasty, but here's the rundown:
  * This is mostly outlined [here](https://docs.microsoft.com/en-us/sql/odbc/reference/syntax/sqlgetdata-function?view=sql-server-ver16#retrieving-data-with-sqlgetdata)
  * The issue is that for our result set, the cursor may be told that a give column has a certain size in bytes, particularly for variable-sized columns like VARCHAR
  * BUT, the driver then may have to "convert to the target type" and this conversion may result in the _actual_ data size being larger than we orignally allocated for
  * But wait, you may ask, don't we already account for this case [here](https://github.com/JuliaDatabases/ODBC.jl/blob/f38f771557a5763f777ed0f441c2cc5a72f41c70/src/utils.jl#L328) by resizing the buffer and calling SQLGetData again to retrieve the rest of the data?
  * Why yes, we do, but only for "long" data types, which is the primary use case for the multiple SQLGetData calls
  * So basically this is _another_ case where, totally depending on the db driver, we might end up with truncated data which will result in `API.SQL_SUCCESS_WITH_INFO` being returned from SQLGetData

Thankfully the fix is relatively easy: we just need to use our buffer-resizing branch if the data type is long OR SQLGetData returns this success with info status code.
@codecov
Copy link

codecov bot commented Aug 11, 2022

Codecov Report

Merging #346 (cff5a98) into main (f38f771) will increase coverage by 0.68%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main     #346      +/-   ##
==========================================
+ Coverage   74.97%   75.65%   +0.68%     
==========================================
  Files           6        6              
  Lines         855      834      -21     
==========================================
- Hits          641      631      -10     
+ Misses        214      203      -11     
Impacted Files Coverage Δ
src/utils.jl 79.45% <100.00%> (-0.16%) ⬇️
src/load.jl 86.88% <0.00%> (-0.42%) ⬇️
src/dbinterface.jl 94.08% <0.00%> (+1.30%) ⬆️
src/API.jl 58.94% <0.00%> (+1.46%) ⬆️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@quinnj quinnj merged commit a7ce136 into main Aug 11, 2022
@quinnj quinnj deleted the jq/328 branch August 11, 2022 12:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BoundsError Issue when converting to DataFrames regression #306
1 participant