1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

boulder-oracle-sprint: It makes more sense on multiple levels to just let Oracle store '' (empty string) as NULL like it wants to than to try to save the empty string by storing it as some other value. This breaks a few test cases in serializers_regress, but that IMO is a matter of fixing the test cases, not the backend.

git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5254 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Boulder Sprinters 2007-05-15 22:45:52 +00:00
parent f948bb371e
commit 41921a4e73
2 changed files with 9 additions and 8 deletions

View File

@ -466,10 +466,11 @@ def get_query_set_class(DefaultQuerySet):
for value, field in map(None, row, fields):
if isinstance(value, Database.LOB):
value = value.read()
# Since Oracle won't distinguish between NULL and an empty
# string (''), we store empty strings as a space. Here is
# where we undo that treachery.
if value == ' ':
# Oracle stores empty strings as null. We need to undo this in
# order to adhere to the Django convention of using the empty
# string instead of null, but only if the field accepts the
# empty string.
if value is None and field.empty_strings_allowed:
value = ''
# Convert 1 or 0 to True or False
elif value in (1, 0) and isinstance(field, (BooleanField, NullBooleanField)):

View File

@ -76,6 +76,10 @@ class Field(object):
self.primary_key = primary_key
self.maxlength, self.unique = maxlength, unique
self.blank, self.null = blank, null
# Oracle treats the empty string ('') as null, so coerce the null
# option whenever '' is a possible value.
if self.empty_strings_allowed and settings.DATABASE_ENGINE == 'oracle':
self.null = True
self.core, self.rel, self.default = core, rel, default
self.editable = editable
self.serialize = serialize
@ -162,10 +166,6 @@ class Field(object):
def get_db_prep_save(self, value):
"Returns field's value prepared for saving into a database."
# Oracle treats empty strings ('') the same as NULLs.
# To get around this wart, we need to change it to something else...
if settings.DATABASE_ENGINE == 'oracle' and value == '':
value = ' '
return value
def get_db_prep_lookup(self, lookup_type, value):