0

I have an Ubuntu 13.10 server, Django 1.5 application and Sql Server 2008 and I try to execute a raw query which works fine if it is only without unicode.

Sample Model:

class SomeRecords(models.Model):
    EntryName = models.CharField(max_length=20)

Some sample records in the table: (in EntryName field)

['elma', 'armut', 'ıspanak']

elma and armut are not unicode, because it doesn't have special characters, but at ıspanak, there is "ı" letter so it is unicode.

This returns with data: (elma query)

# -*- coding:utf-8 -*-
from django.db import connection, transaction
cursor = connection.cursor()
sql = u"select entryname from somerecords where entryname='elma'"
cursor.execute(sql)
rows=cursor.fetchall()
print len(rows)

And this returns empty: (ıspanak query)

# -*- coding:utf-8 -*-
from django.db import connection, transaction
cursor = connection.cursor()
sql = u"select entryname from somerecords where entryname='ıspanak'"
cursor.execute(sql)
rows=cursor.fetchall()
print len(rows)

So, why the second one returns empty?

cem
  • 1,535
  • 19
  • 25
  • A similar problem (and possible solution) has been discussed earlier here: http://stackoverflow.com/questions/2192982/django-sql-server-2005-text-encoding-problem – HAL Nov 21 '13 at 23:46
  • I had problems (but not exactly this one) working with Unicode characters and an ODBC connection to a MS SQL server until I changed my TDS version. On my environment, it defaulted to a very early one that couldn't handle Unicode - setting `TDSVER=8.0` worked for me. This is definitely guesswork but it might be something to check. – Peter DeGlopper Nov 21 '13 at 23:49
  • @HAL: I don't get any error as different from the example, i have also put utf8 to the settings file of freetds already, it didn't help. – cem Nov 21 '13 at 23:54
  • @Peter DeGlopper: There was tds version = 8.0 in freetdf.conf, i have also put TDSVER=8.0 with a hope, but damn it, it didn't work either. – cem Nov 21 '13 at 23:55

0 Answers0