diff options
author | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2007-05-15 22:45:52 +0000 |
---|---|---|
committer | Boulder Sprinters <boulder-sprinters@djangoproject.com> | 2007-05-15 22:45:52 +0000 |
commit | 41921a4e7381c99918780fef5f4f81e4d4b86693 (patch) | |
tree | 73f6311b2e48d83c38d015f9e070fc28621b7063 /django | |
parent | f948bb371e44c50e3c1b585f10f485eafcbae602 (diff) | |
download | django-41921a4e7381c99918780fef5f4f81e4d4b86693.tar.gz |
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
Diffstat (limited to 'django')
-rw-r--r-- | django/db/backends/oracle/base.py | 9 | ||||
-rw-r--r-- | django/db/models/fields/__init__.py | 8 |
2 files changed, 9 insertions, 8 deletions
diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index efec3e58f1..c5da7ac25c 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -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)): diff --git a/django/db/models/fields/__init__.py b/django/db/models/fields/__init__.py index f9aed8b98e..0afd8471fd 100644 --- a/django/db/models/fields/__init__.py +++ b/django/db/models/fields/__init__.py @@ -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): |