Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does pyodbc determine the encoding?

I'm fighting Sybase SQL Anywhere 12 together with Python (and Twisted) for several weeks by now and I even got my stuff working.

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

If I run it on my Ubuntu box (Natty Narwhal) I get them in latin1.

Needless to say, that I would prefer to get all my data in Unicode but that's not the point of this question. :)

Both are 64bit boxes, both have a custom Python 2.7.1. with UCS4 and a custom built unixODBC 2.3.0.

I'm at a loss here. I can't find any documentation on that. What makes pyodbc or unixODBC behave differently on the two boxes?

Hard facts:

  • Python: 2.7.1
  • DB: SQL Anywhere 12
  • unixODBC: 2.3.0 (2.2.14 did behave the same), self compiled with identical flags
  • 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 connect just by using DNS='sybase'.

TIA!

like image 525
hynek Avatar asked Feb 16 '26 07:02

hynek


1 Answers

I can't tell you why it's different, but if you add "Charset=utf-8" to your DSN, you should get the results you want on both machines.

Disclaimer: I work for Sybase in SQL Anywhere engineering.

like image 174
Graeme Perrow Avatar answered Feb 18 '26 20:02

Graeme Perrow