0

I try to execute a query in Python/Django, but eventually I end up with ProgrammingError. My script looks like this:

#--coding: utf-8
...
import pyodbc
...
def testquery(request):
    cnx = pyodbc.connect("DRIVER=FreeTDS;SERVER=192.168.0.1;PORT=1433;DATABASE=mydatabase;UID=sa;PWD=password;TDS_Version=7.0;ClientCharset=UTF8;")
    cursor = cnx.cursor()
    cursor.execute("SELECT * FROM sys_Атрибут")
    ...

As you can see, the name of a table contains non-latin characters. If I instead query another table, whose name is in Latin, then it's ok.

I also tried this:

cursor.execute("SELECT * FROM ?",tablename)

And this:

cursor.execute("SELECT * FROM %s" % tablename)

But it has no effect.

Jacobian
  • 10,122
  • 29
  • 128
  • 221

1 Answers1

1

"FreeTDS handles Unicode for you" https://stackoverflow.com/a/964825/3033586

cursor.execute(u'SELECT * FROM sys_Атрибут'.encode('utf-8'))
Community
  • 1
  • 1
madzohan
  • 11,488
  • 9
  • 40
  • 67