Fixed #22715: Corrected sql for defaults of BinaryField on Oracle with Python3

While at it, fixed a problem in returning empty values
(still with BinaryField/Oracle/Python3).
This commit is contained in:
Shai Berger 2014-05-28 18:57:40 +03:00
parent e97b7a2677
commit fd427f1fe3
2 changed files with 8 additions and 3 deletions

View File

@ -259,6 +259,9 @@ WHEN (new.%(col_name)s IS NULL)
# string instead of null, but only if the field accepts the # string instead of null, but only if the field accepts the
# empty string. # empty string.
if value is None and field and field.empty_strings_allowed: if value is None and field and field.empty_strings_allowed:
if field.get_internal_type() == 'BinaryField':
value = bytes() # same as '' on PY2 but different on PY3
else:
value = '' value = ''
# Convert 1 or 0 to True or False # Convert 1 or 0 to True or False
elif value in (1, 0) and field and field.get_internal_type() in ('BooleanField', 'NullBooleanField'): elif value in (1, 0) and field and field.get_internal_type() in ('BooleanField', 'NullBooleanField'):

View File

@ -3,6 +3,7 @@ import datetime
import binascii import binascii
from django.utils import six from django.utils import six
from django.utils.text import force_text
from django.db.backends.schema import BaseDatabaseSchemaEditor from django.db.backends.schema import BaseDatabaseSchemaEditor
from django.db.utils import DatabaseError from django.db.utils import DatabaseError
@ -23,8 +24,9 @@ class DatabaseSchemaEditor(BaseDatabaseSchemaEditor):
return "'%s'" % value return "'%s'" % value
elif isinstance(value, six.string_types): elif isinstance(value, six.string_types):
return "'%s'" % six.text_type(value).replace("\'", "\'\'") return "'%s'" % six.text_type(value).replace("\'", "\'\'")
elif isinstance(value, buffer): elif (isinstance(value, six.memoryview) or
return "'%s'" % binascii.hexlify(value) six.PY3 and isinstance(value, bytes)):
return "'%s'" % force_text(binascii.hexlify(value))
elif isinstance(value, bool): elif isinstance(value, bool):
return "1" if value else "0" return "1" if value else "0"
else: else: