[py3] Fixed Oracle specific failures

This commit is contained in:
Anssi Kääriäinen 2012-08-19 21:15:52 +03:00
parent 9729f77326
commit 4db38cbfe1
2 changed files with 16 additions and 2 deletions

View File

@ -221,7 +221,10 @@ WHEN (new.%(col_name)s IS NULL)
def last_executed_query(self, cursor, sql, params): def last_executed_query(self, cursor, sql, params):
# http://cx-oracle.sourceforge.net/html/cursor.html#Cursor.statement # http://cx-oracle.sourceforge.net/html/cursor.html#Cursor.statement
# The DB API definition does not define this attribute. # The DB API definition does not define this attribute.
return cursor.statement.decode("utf-8") if six.PY3:
return cursor.statement
else:
return cursor.statement.decode("utf-8")
def last_insert_id(self, cursor, table_name, pk_name): def last_insert_id(self, cursor, table_name, pk_name):
sq_name = self._get_sequence_name(table_name) sq_name = self._get_sequence_name(table_name)
@ -594,6 +597,12 @@ class OracleParam(object):
param = timezone.make_aware(param, default_timezone) param = timezone.make_aware(param, default_timezone)
param = param.astimezone(timezone.utc).replace(tzinfo=None) param = param.astimezone(timezone.utc).replace(tzinfo=None)
# Oracle doesn't recognize True and False correctly in Python 3.
# The conversion done below works both in 2 and 3.
if param is True:
param = "1"
elif param is False:
param = "0"
if hasattr(param, 'bind_parameter'): if hasattr(param, 'bind_parameter'):
self.smart_bytes = param.bind_parameter(cursor) self.smart_bytes = param.bind_parameter(cursor)
else: else:

View File

@ -1,4 +1,9 @@
from django.db.models.sql import compiler from django.db.models.sql import compiler
# The izip_longest was renamed to zip_longest in py3
try:
from itertools import zip_longest
except ImportError:
from itertools import izip_longest as zip_longest
class SQLCompiler(compiler.SQLCompiler): class SQLCompiler(compiler.SQLCompiler):
@ -13,7 +18,7 @@ class SQLCompiler(compiler.SQLCompiler):
index_start = rn_offset + len(self.query.extra_select) index_start = rn_offset + len(self.query.extra_select)
values = [self.query.convert_values(v, None, connection=self.connection) values = [self.query.convert_values(v, None, connection=self.connection)
for v in row[rn_offset:index_start]] for v in row[rn_offset:index_start]]
for value, field in map(None, row[index_start:], fields): for value, field in zip_longest(row[index_start:], fields):
values.append(self.query.convert_values(value, field, connection=self.connection)) values.append(self.query.convert_values(value, field, connection=self.connection))
return tuple(values) return tuple(values)