My favorites | Sign in
Project Home Downloads Wiki
READ-ONLY: This project has been archived. For more information see this post.
Search
for
  Advanced search   Search tips   Subscriptions
Issue 284: unicode_results is not honored when connecting to SQL Server Express Edition
1 person starred this issue and may be notified of changes. Back to list
Status:  NoFix
Owner:  ----
Closed:  Sep 2012


 
Reported by elver.loho@gmail.com, Sep 6, 2012
What steps will reproduce the problem?
1. Use django-pyodbc to connect to SQL Server Express Edition running on AWS RDS.
2. Data going in seems to be utf8 encoded properly.
3. Data coming out seems to be decoded as something else and it bubbles back to Django as unicode objects full of garbage where non-ascii characters are supposed to be.

What is the expected output? What do you see instead?

I see strings like 'Jõuülekande osad' instead of 'Jõuülekande osad'.

django-pyodbc connects to the database as:

            if self.unicode_results:
                self.connection = Database.connect(connstr, \
                        autocommit=autocommit, \
                        unicode_results='True')
            else:
                self.connection = Database.connect(connstr, \
                        autocommit=autocommit)

In format_results() it has the following code:

        for row in rows:
            if isinstance(row, str):
                fr.append(row.decode('utf-8'))
            else:
                fr.append(row)

However, cursor.execute() returns nvarchar() columns as unicode objects even though unicode_results = False. By my logic it should return them as str objects so that django-pyodbc can do the proper decoding itself. Why is pyodbc not honoring the unicode_results flag?

What version of the product are you using? On what operating system?

pyodbc version 3.0.6, django-pyodbc is from https://github.com/elver/django-pyodbc


Sep 6, 2012
#1 elver.loho@gmail.com
Adding the following to connection params seems to have made the driver return properly-decoded unicode objects, at the very least, so it kinda works as a workaround for now.

'extra_params' : "TDS_VERSION=8.0;ClientCharset=UTF-8",
Sep 26, 2012
Project Member #2 mkleehammer
Also, when possible, I recommend using Microsoft's driver for Linux instead of FreeTDS.  It has significantly fewer problems.
Status: NoFix

Powered by Google Project Hosting