[freetds] Python Unicode SQL Statements

Michael Trier mtrier at gmail.com
Mon May 4 21:03:25 EDT 2009


Hello,
I've wrestled with this for several days now and I'm at a loss for
understanding how to make this work.  I have the following test script:

import pyodbc
conn =
pyodbc.connect("Driver=FreeTDS;Servername=vm;UID=sprint;PWD=sprint;Database=sprint;")
cursor = conn.cursor()
sql = u"SELECT * FROM test_table;"
result = cursor.execute(sql)
print result.fetchall()

If I run it on pyodbc on Windows everything works just fine. Pyodbc seems to
just pass along the unicode string and MSSQL can deal with it fine.

If I run it on my Mac OSX 10.5.6 with the following chain of pyodbc ->
FreeTDS -> MSSQL, I get the following results:

Traceback (most recent call last):
  File "odbctest.py", line 5, in <module>
    result = cursor.execute(sql)
pyodbc.ProgrammingError: ('42000', "[42000] [FreeTDS][SQL Server]Could not
find stored procedure 'AUTO_INCREMEN'. (2812) (SQLExecDirectW)")

It is clearly not understanding the unicode string.  FreeTDS seems to want
byte codes. If I send it as UTF-8 (or remove the unicode string) then all
works fine.

Is there any way for me to get the above to work without the conversion to
byte codes? Such as a way to turn off any sort of conversion on the FreeTDS
side.

I have a log file if that would help as well.

-- 
Michael Trier
http://blog.michaeltrier.com/



More information about the FreeTDS mailing list