From 32959282d6c1548b89c47c6384d640fda9410f63 Mon Sep 17 00:00:00 2001 From: Michiya Takahashi Date: Wed, 29 Jan 2014 13:42:25 +0900 Subject: [PATCH] fix potential errors on Python 3 --- sql_server/pyodbc/base.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql_server/pyodbc/base.py b/sql_server/pyodbc/base.py index 1816cb5f..06e3b658 100644 --- a/sql_server/pyodbc/base.py +++ b/sql_server/pyodbc/base.py @@ -22,6 +22,7 @@ from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseValidation from django.db.backends.signals import connection_created from django.conf import settings +from django.utils.encoding import smart_str from django import VERSION as DjangoVersion if DjangoVersion[:2] == (1,5): _DJANGO_VERSION = 15 @@ -344,7 +345,7 @@ def format_sql(self, sql, n_params=None): if self.driver_needs_utf8 and isinstance(sql, text_type): # FreeTDS (and other ODBC drivers?) doesn't support Unicode # yet, so we need to encode the SQL clause itself in utf-8 - sql = sql.encode('utf-8') + sql = smart_str(sql, 'utf-8') # pyodbc uses '?' instead of '%s' as parameter placeholder. if n_params is not None and n_params > 0: @@ -361,7 +362,7 @@ def format_params(self, params): if self.driver_needs_utf8: # FreeTDS (and other ODBC drivers?) doesn't support Unicode # yet, so we need to encode parameters in utf-8 - fp.append(p.encode('utf-8')) + fp.append(smart_str(p, 'utf-8')) else: fp.append(p)