I am trying to configure ODBC on Ubuntu 14.04 with Python 3.4.3. I am able to successfully make a connection, but an getting this error on execution:
>>> cursor.execute("SELECT * FROM xxx.yyy.zzz LIMIT 100;")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
pyodbc.ProgrammingError: ('42000', '[42000] ERROR: \'S\'\nerror ^ found "S" (at char 1) expecting a keyword (27) (SQLExecDirectW)')The same code to execute the query is working fine on Python 2.7. I am also able to make a connection from the UNIX shell using strace isql, which makes me think that my ODBC connection is working fine. Is it?
There is not much information available online regarding this. Below are the few things I have done based on a few blogs I found. Is my understanding correct?
As is mentioned in PyODBC ticket:
In my case the ODBC driver (NetezzaSQL) was set to use UTF8. I first though the issue was either a UC2 or UC4 build of Python. Both made no difference. Switching the driver to UTF16 (UnicodeTranslationOption=utf16) fixed the issue for me.
I have UnicodeTranslationOption=utf16 set in all my obdc*.ini files. Since my code is running on Python 2.7, does that mean this parameter is set correctly?
It is mentioned in document to configure PyODBC that I should build Python with UCS2version. But on my machine, both Python2.7 and Python3.4 says they have UCS4 version, and since code is running on Python 2.x, that means UCS4 is not the issue here.
I checked UCF version using below commands:
user@host:~$ python -c "import sys;print(sys.maxunicode<66000 and'UCS2'or'UCS4')"
UCS4
user@host:~$ python3 -c "import sys;print(sys.maxunicode<66000 and'UCS2'or'UCS4')"
UCS4