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

MSSQL field 'uniqueidentifier' is returned as str formatted as byte str #85

Open
dryo opened this issue Jul 18, 2018 · 3 comments
Open

Comments

@dryo
Copy link

dryo commented Jul 18, 2018

When fetching a value from a column of type 'uniqueidentifier' a str is returned that includes the representation of a bytestr.

Example
The data in the column is E3A61520-F8C9-434F-A153-9B2E8C136430.

When fetched via pypyodbc with e.g. {ODBC Driver 13 for SQL Server} and stored in value this happens:

print(str(type(value)) + ', ' + repr(value))
<class 'str'>, "b'E3A61520-F8C9-434F-A153-9B2E8C136430'"

This looks different from this:

testvalue = b'E3A61520-F8C9-434F-A153-9B2E8C136430'
print(str(type(testvalue)) + ', ' + repr(testvalue))
<class 'bytes'>, b'E3A61520-F8C9-434F-A153-9B2E8C136430'

I'm using windows with python 3.6.5 and pypyodbc 1.3.4.

Possibly related: #54, #46, #25

@junctionapps
Copy link
Contributor

see #78
Does that help you out?

@junctionapps
Copy link
Contributor

summary from @braian87b
In pypyodbc.py:

change:
SQL_GUID : (str, str, SQL_C_CHAR, create_buffer, 2048 , False ),
to:
SQL_GUID : (str, lambda x: x, SQL_C_CHAR, create_buffer, 2048 , False ),

Like on the SQL_VARCHAR line.

@dryo
Copy link
Author

dryo commented Jul 19, 2018

Sorry, did not see #78 as I was only searching open issues.
This however did not do the trick or I forgot something. I changed the file "C:\Program Files\Python36\Lib\site-packages\pypyodbc.py". No difference. I renamed "C:\Program Files\Python36\Lib\site-packages_pycache_\pypyodbc.cpython-36.pyc.bak". No difference - and to my surprise the file was not recreated.

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

No branches or pull requests

2 participants