Pyodbc utf-8 binds param error with FreeTDS and unixODBC

FreeTDS Version 0.82

unixODBC version 2.3.0

pyodbc version 2.1.8

freetds.conf:

tds version = 7.0 client charset = UTF-8 

using Servername in odbc.ini (which for some crazy reason caused UnixODBC to recognize client encoding in freetds)

I can correctly output utf8 data and update inline line, i.e.

 UPDATE table SET col = N'私はトカイ大好き' WHERE id = 182333369 

But

 text = u'私はトカイ大好き' cursor.execute(""" UPDATE table SET column = ? WHERE id = 182333369 """, text) 

Failure:

 pyodbc.Error: ('HY004', '[HY004] [FreeTDS][SQL Server] Invalid data type (0) (SQLBindParameter)') 

If I add:

 text = text.encode('utf-8') 

I get the following error:

pyodbc.ProgrammingError: ('42000', '[42000] [FreeTDS] [SQL Server] Invalid Incoming Data Protocol (TDS) protocol stream. Stream terminated unexpectedly. (4002) (SQLExecDirectW)')

Any ideas on where things went astray?

+4
source share
1 answer

Unicode support has been redesigned in pyodbc 3.0.x. Try testing using the latest source (3.0.2-beta02, etc.).

+1
source

All Articles