Django

Code

Changeset 5254

Show
Ignore:
Timestamp:
05/15/07 17:45:52 (1 year ago)
Author:
bouldersprinters
Message:

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.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/branches/boulder-oracle-sprint/django/db/backends/oracle/base.py

    r5149 r5254  
    467467                if isinstance(value, Database.LOB): 
    468468                    value = value.read() 
    469                 # Since Oracle won't distinguish between NULL and an empty 
    470                 # string (''), we store empty strings as a space.  Here is 
    471                 # where we undo that treachery. 
    472                 if value == ' ': 
     469                # Oracle stores empty strings as null. We need to undo this in 
     470                # order to adhere to the Django convention of using the empty 
     471                # string instead of null, but only if the field accepts the 
     472                # empty string. 
     473                if value is None and field.empty_strings_allowed: 
    473474                    value = '' 
    474475                # Convert 1 or 0 to True or False 
  • django/branches/boulder-oracle-sprint/django/db/models/fields/__init__.py

    r5135 r5254  
    7777        self.maxlength, self.unique = maxlength, unique 
    7878        self.blank, self.null = blank, null 
     79        # Oracle treats the empty string ('') as null, so coerce the null 
     80        # option whenever '' is a possible value. 
     81        if self.empty_strings_allowed and settings.DATABASE_ENGINE == 'oracle': 
     82            self.null = True 
    7983        self.core, self.rel, self.default = core, rel, default 
    8084        self.editable = editable 
     
    163167    def get_db_prep_save(self, value): 
    164168        "Returns field's value prepared for saving into a database." 
    165         # Oracle treats empty strings ('') the same as NULLs. 
    166         # To get around this wart, we need to change it to something else... 
    167         if settings.DATABASE_ENGINE == 'oracle' and value == '': 
    168             value = ' ' 
    169169        return value 
    170170