From 4db38cbfe1087a51cd5d3d4fed9c7fcb952424d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Sun, 19 Aug 2012 21:15:52 +0300 Subject: [PATCH] [py3] Fixed Oracle specific failures --- django/db/backends/oracle/base.py | 11 ++++++++++- django/db/backends/oracle/compiler.py | 7 ++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 89cad12b6c..7d4f2b445a 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -221,7 +221,10 @@ WHEN (new.%(col_name)s IS NULL) def last_executed_query(self, cursor, sql, params): # http://cx-oracle.sourceforge.net/html/cursor.html#Cursor.statement # 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): sq_name = self._get_sequence_name(table_name) @@ -594,6 +597,12 @@ class OracleParam(object): param = timezone.make_aware(param, default_timezone) 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'): self.smart_bytes = param.bind_parameter(cursor) else: diff --git a/django/db/backends/oracle/compiler.py b/django/db/backends/oracle/compiler.py index e21f867f82..24030cdffc 100644 --- a/django/db/backends/oracle/compiler.py +++ b/django/db/backends/oracle/compiler.py @@ -1,4 +1,9 @@ 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): @@ -13,7 +18,7 @@ class SQLCompiler(compiler.SQLCompiler): index_start = rn_offset + len(self.query.extra_select) values = [self.query.convert_values(v, None, connection=self.connection) 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)) return tuple(values)