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

Connection errors give wrong message string on big-endian systems #563

Closed
kadler opened this issue Apr 26, 2019 · 0 comments · Fixed by #564
Closed

Connection errors give wrong message string on big-endian systems #563

kadler opened this issue Apr 26, 2019 · 0 comments · Fixed by #564

Comments

@kadler
Copy link
Contributor

kadler commented Apr 26, 2019

Environment

To diagnose, we usually need to know the following, including version numbers. On Windows, be
sure to specify 32-bit Python or 64-bit:

  • Python: 3.6.8 64-bit
  • pyodbc: 4.0.27b1
  • OS: IBM i 7.2
  • DB: N/A
  • driver: N/A

Issue

Connection errors gives mojibake on big-endian systems:

>>> pyodbc.connect('DSN=doesnotexist')
pyodbc.InterfaceError: ('IM002', '[IM002] 嬀甀渀椀砀伀䐀䈀䌀崀嬀䐀爀椀瘀攀爀\u2000䴀愀渀愀最攀爀崀䐀愀琀愀\u2000猀漀甀爀挀攀\u2000渀愀洀攀\u2000渀漀琀\u2000昀漀甀渀搀Ⰰ\u2000愀渀搀\u2000渀漀\u2000搀攀昀愀甀氀琀\u2000搀爀椀瘀攀爀\u2000猀瀀攀挀椀昀椀攀搀 (0) (SQLDriverConnect)')

This is due to hardcoding the encoding to "utf-16-le" when a connection is NULL: https://github.com/mkleehammer/pyodbc/blob/master/src/errors.cpp#L294

If I change the encoding to "utf-16-be", I get the correct error message:

>>> pyodbc.connect('DSN=doesnotexist')
pyodbc.InterfaceError: ('IM002', '[IM002] [unixODBC][Driver Manager]Data source name not found, and no default driver specified (0) (SQLDriverConnect)')

Looks like this should use ENCSTR_UTF16NE which seems to have been missed from #255.

kadler added a commit to kadler/pyodbc that referenced this issue Apr 26, 2019
system, but when a connection failure occurs the encoding was still
hard-coded to utf-16-le which causes mojibake on big endian systems.

Instead use ENCSTR_UTF16NE, which will be either utf-16-le or
utf-16-be, depending on the native endian for the system.

Fixes mkleehammer#563
kadler added a commit to kadler/pyodbc that referenced this issue Apr 26, 2019
In mkleehammer#255, the code was changed to use the native endianness of the
system, but when a connection failure occurs the encoding was still
hard-coded to utf-16-le which causes mojibake on big endian systems.

Instead use ENCSTR_UTF16NE, which will be either utf-16-le or
utf-16-be, depending on the native endian for the system.

Fixes mkleehammer#563
mkleehammer pushed a commit that referenced this issue Jul 31, 2019
In #255, the code was changed to use the native endianness of the
system, but when a connection failure occurs the encoding was still
hard-coded to utf-16-le which causes mojibake on big endian systems.

Instead use ENCSTR_UTF16NE, which will be either utf-16-le or
utf-16-be, depending on the native endian for the system.

Fixes #563
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 a pull request may close this issue.

1 participant