Django

Code

Ticket #1261: firebird_backend_patch_6650.diff

File firebird_backend_patch_6650.diff, 9.9 kB (added by i_i, 10 months ago)

updated firevird backend patch

  • django/db/models/fields/__init__.py

    old new  
    206206        return value 
    207207 
    208208    def get_db_prep_lookup(self, lookup_type, value): 
     209        from django.db import connection 
    209210        "Returns field's value prepared for database lookup." 
    210211        if lookup_type in ('exact', 'regex', 'iregex', 'gt', 'gte', 'lt', 'lte', 'month', 'day', 'search'): 
    211212            return [value] 
    212213        elif lookup_type in ('range', 'in'): 
    213214            return value 
    214215        elif lookup_type in ('contains', 'icontains'): 
     216            if connection.features.uses_custom_icontains and lookup_type == 'icontains': 
     217                return [value]     
    215218            return ["%%%s%%" % prep_for_like_query(value)] 
    216219        elif lookup_type == 'iexact': 
    217220            return [prep_for_like_query(value)] 
    218221        elif lookup_type in ('startswith', 'istartswith'): 
     222            if connection.features.uses_custom_startswith: 
     223                return [value] 
    219224            return ["%s%%" % prep_for_like_query(value)] 
    220225        elif lookup_type in ('endswith', 'iendswith'): 
    221226            return ["%%%s" % prep_for_like_query(value)] 
     
    478483        defaults.update(kwargs) 
    479484        return super(CharField, self).formfield(**defaults) 
    480485 
     486class ASCIICharField(CharField): 
     487    pass 
     488 
    481489# TODO: Maybe move this into contrib, because it's specialized. 
    482490class CommaSeparatedIntegerField(CharField): 
    483491    def get_manipulator_field_objs(self): 
     
    587595            # doesn't support microseconds. 
    588596            if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'): 
    589597                value = value.replace(microsecond=0) 
    590             value = smart_unicode(value) 
     598            #Firebird supports native datetime 
     599            if settings.DATABASE_ENGINE != 'firebird': 
     600                value = smart_unicode(value) 
    591601        return Field.get_db_prep_save(self, value) 
    592602 
    593603    def get_db_prep_lookup(self, lookup_type, value): 
     
    9951005            # doesn't support microseconds. 
    9961006            if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'): 
    9971007                value = value.replace(microsecond=0) 
    998             if settings.DATABASE_ENGINE == 'oracle'
    999                 # cx_Oracle expects a datetime.datetime to persist into TIMESTAMP field. 
     1008            if settings.DATABASE_ENGINE in ('oracle', 'firebird')
     1009                # cx_Oracle and kinterbasdb expect a datetime.datetime to persist into TIMESTAMP field. 
    10001010                if isinstance(value, datetime.time): 
    10011011                    value = datetime.datetime(1900, 1, 1, value.hour, value.minute, 
    10021012                                              value.second, value.microsecond) 
  • django/db/backends/__init__.py

    old new  
    4545    autoindexes_primary_keys = True 
    4646    inline_fk_references = True 
    4747    needs_datetime_string_cast = True 
     48    needs_default_null = False 
    4849    needs_upper_for_iops = False 
    4950    supports_constraints = True 
    5051    supports_tablespaces = False 
    5152    uses_case_insensitive_names = False 
     53    uses_custom_icontains = False 
     54    uses_custom_startswith = False 
    5255    uses_custom_queryset = False 
    5356 
    5457class BaseDatabaseOperations(object): 
     
    6568        This SQL is executed when a table is created. 
    6669        """ 
    6770        return None 
    68  
     71     
     72    def cascade_delete_update_sql(self): 
     73        """ 
     74        Returns the SQL necessary to make a cascading deletes and updates 
     75        of foreign key references during a CREATE TABLE statement. 
     76        """ 
     77        return '' 
     78     
    6979    def date_extract_sql(self, lookup_type, field_name): 
    7080        """ 
    7181        Given a lookup_type of 'year', 'month' or 'day', returns the SQL that 
  • django/core/management/sql.py

    old new  
    263263        # Make the definition (e.g. 'foo VARCHAR(30)') for this field. 
    264264        field_output = [style.SQL_FIELD(qn(f.column)), 
    265265            style.SQL_COLTYPE(col_type)] 
    266         field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or ''))) 
     266        nullstring = "" 
     267        if connection.features.needs_default_null: 
     268            nullstring = "DEFAULT " 
     269        field_output.append(style.SQL_KEYWORD('%sNULL' % (not f.null and 'NOT ' or nullstring))) 
    267270        if f.unique and (not f.primary_key or connection.features.allows_unique_and_pk): 
    268271            field_output.append(style.SQL_KEYWORD('UNIQUE')) 
    269272        if f.primary_key: 
     
    276279            if inline_references and f.rel.to in known_models: 
    277280                field_output.append(style.SQL_KEYWORD('REFERENCES') + ' ' + \ 
    278281                    style.SQL_TABLE(qn(f.rel.to._meta.db_table)) + ' (' + \ 
    279                     style.SQL_FIELD(qn(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' + 
    280                     connection.ops.deferrable_sql() 
     282                    style.SQL_FIELD(qn(f.rel.to._meta.get_field(f.rel.field_name).column)) + ')' + \ 
     283                    connection.ops.cascade_delete_update_sql() + connection.ops.deferrable_sql() 
    281284                ) 
    282285            else: 
    283286                # We haven't yet created the table to which this field 
     
    335338                final_output.append(style.SQL_KEYWORD('ALTER TABLE') + ' %s ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s (%s)%s;' % \ 
    336339                    (qn(r_table), truncate_name(r_name, connection.ops.max_name_length()), 
    337340                    qn(r_col), qn(table), qn(col), 
     341                    connection.ops.cascade_delete_update_sql(), 
    338342                    connection.ops.deferrable_sql())) 
    339343            del pending_references[model] 
    340344    return final_output 
     
    364368                tablespace_sql)) 
    365369            if inline_references: 
    366370                deferred = [] 
    367                 table_output.append('    %s %s %s %s (%s)%s,' % 
     371                table_output.append('    %s %s %s %s (%s)%s%s,' % 
    368372                    (style.SQL_FIELD(qn(f.m2m_column_name())), 
    369373                    style.SQL_COLTYPE(models.ForeignKey(model).db_type()), 
    370374                    style.SQL_KEYWORD('NOT NULL REFERENCES'), 
    371375                    style.SQL_TABLE(qn(opts.db_table)), 
    372376                    style.SQL_FIELD(qn(opts.pk.column)), 
     377                    connection.ops.cascade_delete_update_sql(), 
    373378                    connection.ops.deferrable_sql())) 
    374                 table_output.append('    %s %s %s %s (%s)%s,' % 
     379                table_output.append('    %s %s %s %s (%s)%s%s,' % 
    375380                    (style.SQL_FIELD(qn(f.m2m_reverse_name())), 
    376381                    style.SQL_COLTYPE(models.ForeignKey(f.rel.to).db_type()), 
    377382                    style.SQL_KEYWORD('NOT NULL REFERENCES'), 
    378383                    style.SQL_TABLE(qn(f.rel.to._meta.db_table)), 
    379384                    style.SQL_FIELD(qn(f.rel.to._meta.pk.column)), 
     385                    connection.ops.cascade_delete_update_sql(), 
    380386                    connection.ops.deferrable_sql())) 
    381387            else: 
    382388                table_output.append('    %s %s %s,' % 
     
    412418                (qn(r_table), 
    413419                truncate_name(r_name, connection.ops.max_name_length()), 
    414420                qn(r_col), qn(table), qn(col), 
     421                connection.ops.cascade_delete_update_sql(), 
    415422                connection.ops.deferrable_sql())) 
    416423 
    417424            # Add any extra SQL needed to support auto-incrementing PKs 
  • django/contrib/contenttypes/models.py

    old new  
    11from django.db import models 
    22from django.utils.translation import ugettext_lazy as _ 
    33from django.utils.encoding import smart_unicode 
     4from django.conf import settings 
    45 
    56CONTENT_TYPE_CACHE = {} 
    67class ContentTypeManager(models.Manager): 
     
    3132        global CONTENT_TYPE_CACHE 
    3233        CONTENT_TYPE_CACHE = {} 
    3334 
    34 class ContentType(models.Model): 
     35class ContentType(models.Model):    
    3536    name = models.CharField(max_length=100) 
    36     app_label = models.CharField(max_length=100) 
    37     model = models.CharField(_('python model class name'), max_length=100) 
     37    # Need this because of Firebird restrictions on index key size < 252 bytes 
     38    if settings.DATABASE_ENGINE == 'firebird': 
     39        app_label = models.ASCIICharField(max_length=96) 
     40        model = models.ASCIICharField(_('python model class name'), max_length=96) 
     41    else: 
     42        app_label = models.CharField(max_length=100) 
     43        model = models.CharField(_('python model class name'), max_length=100) 
    3844    objects = ContentTypeManager() 
    3945    class Meta: 
    4046        verbose_name = _('content type') 
  • django/contrib/auth/models.py

    old new  
    66from django.contrib.contenttypes.models import ContentType 
    77from django.utils.encoding import smart_str 
    88from django.utils.translation import ugettext_lazy as _ 
     9from django.conf import settings 
    910import datetime 
    1011import urllib 
    1112 
     
    7273    """ 
    7374    name = models.CharField(_('name'), max_length=50) 
    7475    content_type = models.ForeignKey(ContentType) 
    75     codename = models.CharField(_('codename'), max_length=100) 
     76    # Need this because of Firebird restrictions on index key size < 252 bytes 
     77    if settings.DATABASE_ENGINE == 'firebird': 
     78        codename = models.ASCIICharField(_('codename'), max_length=100) 
     79    else: 
     80        codename = models.CharField(_('codename'), max_length=100) 
    7681 
    7782    class Meta: 
    7883        verbose_name = _('permission')