pyodbc icon indicating copy to clipboard operation
pyodbc copied to clipboard

pyodbc.Binary - Is it something a user would normally need to use?

Open gordthompson opened this issue 7 years ago • 1 comments

In the Stack Overflow question here the user is attempting to use a pyodbc.Binary object. My answer to the question shows that there is no need to use that object in their particular case (a simple bytes object will suffice), but it got me wondering when/if a pyodbc.Binary object would be used.

I searched for some documentation on the object but came up empty. I even did a "find in files" on the source tree to see if I could glean some information from that, but no luck. (Although my C++ is so rusty that I may have just missed something obvious.) Google Search offered me this page in the search results, suggesting that Django uses (or used) the object in a couple of places, but it's not clear why (to me, anyway).

So is pyodbc.Binary (still?) "a thing"?

gordthompson avatar Sep 25 '18 17:09 gordthompson

It's part of the DB API specification and is intended to allow the API to convert things to a type that will be recognized as binary when used as a parameter. It is currently an alias to bytearray, but in Python 3 should probably be changed to bytes. It should work in both 2 and 3 since we accept bytearray parameters, but someone could be confused if they examine it to determine the best type for binary data in Python 3.

I'll leave this open as a low priority item and convert.

mkleehammer avatar Sep 28 '18 19:09 mkleehammer

It looks like this has been resolved, based on what I see at

https://github.com/mkleehammer/pyodbc/blob/b85449727cc83ca46ecc66c054875e897df124a4/src/pyodbcmodule.cpp#L1205-L1210

gordthompson avatar Aug 29 '23 21:08 gordthompson

Then I'll close it. Thanks.

mkleehammer avatar Aug 29 '23 22:08 mkleehammer