How does pyodbc determine the encoding?

I have been fighting Sybase SQL Anywhere 12 along with Python (and Twisted) for several weeks, and I even got my work done.

There is only one annoyance left: if I run my script on CentOS 5 using custom Python 2.7.1, which is the deployment platform, I get my results as UTF-8 .

If I run it in my Ubuntu field (Natty Narwhal), I get them in latin1 .

Needless to say, I would rather get all my data in Unicode, but that is not a question of this question. :)

Both are 64-bit, both have their own Python 2.7.1. with UCS4 and custom unixODBC 2.3.0.

I don’t get it here. I can not find documentation about this. What does pyodbc or unixODBC do differently in two blocks?

Hard facts:

  • Python: 2.7.1
  • DB: SQL Anywhere 12
  • unixODBC: 2.3.0 (2.2.14 did the same), compiled with identical flags itself
  • ODBC driver: original from Sybase.
  • CentOS 5 gives me UTF-8, Ubuntu Natty Narwhal gives me latin1.

My odbc.ini looks like this:

[sybase]
Uid             = user
Pwd             = password
Driver          = /opt/sqlanywhere/lib64/libdbodbc12_r.so
Threading       = True
ServerName      = dbname
CommLinks       = tcpip(host=the-host;DoBroadcast=None)

I only connect using DNS = 'sybase'.

TIA!

+3
source share
2 answers

I cannot tell you why this is different, but if you add “Charset = utf-8” to your DSN, you should get the results you want on both machines.

Disclaimer: I am working on Sybase in SQL Anywhere development.

+4
source

pyodbc ODBC, 2 . ODBC, "W", - , SQLWCHAR. ODBC UCS2, UCS4. SQLCHAR (?) ANSI/ASCII.

ODBC , UTF8. ODBC , . UTF8, ANSI UCS2 . , ODBC .

pyodbc ANSI, 'str' UCS2/UCS4 ( , SQLWCHAR ), 'unicode'. , SQLCHAR SQLWCHAR , pyodbc . SQLCHAR, 'str', SQLWCHAR 'unicode'.

3.x, SQLCHAR SQLWCHAR Unicode.

+4

All Articles