Django

Code

Changeset 5982

Show
Ignore:
Timestamp:
08/19/07 22:26:55 (1 year ago)
Author:
adrian
Message:

Refactored OPERATOR_MAPPING so that it exists as django.db.connection.operators instead of django.db.backend.OPERATOR_MAPPING. Refs #5106

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/db/backends/ado_mssql/base.py

    r5974 r5982  
    8585    features = DatabaseFeatures() 
    8686    ops = DatabaseOperations() 
     87    operators = { 
     88        'exact': '= %s', 
     89        'iexact': 'LIKE %s', 
     90        'contains': 'LIKE %s', 
     91        'icontains': 'LIKE %s', 
     92        'gt': '> %s', 
     93        'gte': '>= %s', 
     94        'lt': '< %s', 
     95        'lte': '<= %s', 
     96        'startswith': 'LIKE %s', 
     97        'endswith': 'LIKE %s', 
     98        'istartswith': 'LIKE %s', 
     99        'iendswith': 'LIKE %s', 
     100    } 
    87101 
    88102    def _cursor(self, settings): 
     
    97111            self.connection = Database.connect(conn_string) 
    98112        return self.connection.cursor() 
    99  
    100 OPERATOR_MAPPING = { 
    101     'exact': '= %s', 
    102     'iexact': 'LIKE %s', 
    103     'contains': 'LIKE %s', 
    104     'icontains': 'LIKE %s', 
    105     'gt': '> %s', 
    106     'gte': '>= %s', 
    107     'lt': '< %s', 
    108     'lte': '<= %s', 
    109     'startswith': 'LIKE %s', 
    110     'endswith': 'LIKE %s', 
    111     'istartswith': 'LIKE %s', 
    112     'iendswith': 'LIKE %s', 
    113 } 
  • django/trunk/django/db/backends/dummy/base.py

    r5974 r5982  
    2727 
    2828class DatabaseWrapper(object): 
     29    features = ComplainOnGetattr() 
    2930    ops = ComplainOnGetattr() 
    30     features = ComplainOnGetattr() 
     31    operators = {} 
    3132    cursor = complain 
    3233    _commit = complain 
     
    3839    def close(self): 
    3940        pass # close() 
    40  
    41 OPERATOR_MAPPING = {} 
  • django/trunk/django/db/backends/mysql/base.py

    r5974 r5982  
    122122    features = DatabaseFeatures() 
    123123    ops = DatabaseOperations() 
     124    operators = { 
     125        'exact': '= %s', 
     126        'iexact': 'LIKE %s', 
     127        'contains': 'LIKE BINARY %s', 
     128        'icontains': 'LIKE %s', 
     129        'regex': 'REGEXP BINARY %s', 
     130        'iregex': 'REGEXP %s', 
     131        'gt': '> %s', 
     132        'gte': '>= %s', 
     133        'lt': '< %s', 
     134        'lte': '<= %s', 
     135        'startswith': 'LIKE BINARY %s', 
     136        'endswith': 'LIKE BINARY %s', 
     137        'istartswith': 'LIKE %s', 
     138        'iendswith': 'LIKE %s', 
     139    } 
    124140 
    125141    def __init__(self, **kwargs): 
     
    179195            self.server_version = tuple([int(x) for x in m.groups()]) 
    180196        return self.server_version 
    181  
    182 OPERATOR_MAPPING = { 
    183     'exact': '= %s', 
    184     'iexact': 'LIKE %s', 
    185     'contains': 'LIKE BINARY %s', 
    186     'icontains': 'LIKE %s', 
    187     'regex': 'REGEXP BINARY %s', 
    188     'iregex': 'REGEXP %s', 
    189     'gt': '> %s', 
    190     'gte': '>= %s', 
    191     'lt': '< %s', 
    192     'lte': '<= %s', 
    193     'startswith': 'LIKE BINARY %s', 
    194     'endswith': 'LIKE BINARY %s', 
    195     'istartswith': 'LIKE %s', 
    196     'iendswith': 'LIKE %s', 
    197 } 
  • django/trunk/django/db/backends/mysql_old/base.py

    r5974 r5982  
    132132    features = DatabaseFeatures() 
    133133    ops = DatabaseOperations() 
     134    operators = { 
     135        'exact': '= %s', 
     136        'iexact': 'LIKE %s', 
     137        'contains': 'LIKE BINARY %s', 
     138        'icontains': 'LIKE %s', 
     139        'regex': 'REGEXP BINARY %s', 
     140        'iregex': 'REGEXP %s', 
     141        'gt': '> %s', 
     142        'gte': '>= %s', 
     143        'lt': '< %s', 
     144        'lte': '<= %s', 
     145        'startswith': 'LIKE BINARY %s', 
     146        'endswith': 'LIKE BINARY %s', 
     147        'istartswith': 'LIKE %s', 
     148        'iendswith': 'LIKE %s', 
     149    } 
    134150 
    135151    def __init__(self, **kwargs): 
     
    198214            self.server_version = tuple([int(x) for x in m.groups()]) 
    199215        return self.server_version 
    200  
    201 OPERATOR_MAPPING = { 
    202     'exact': '= %s', 
    203     'iexact': 'LIKE %s', 
    204     'contains': 'LIKE BINARY %s', 
    205     'icontains': 'LIKE %s', 
    206     'regex': 'REGEXP BINARY %s', 
    207     'iregex': 'REGEXP %s', 
    208     'gt': '> %s', 
    209     'gte': '>= %s', 
    210     'lt': '< %s', 
    211     'lte': '<= %s', 
    212     'startswith': 'LIKE BINARY %s', 
    213     'endswith': 'LIKE BINARY %s', 
    214     'istartswith': 'LIKE %s', 
    215     'iendswith': 'LIKE %s', 
    216 } 
  • django/trunk/django/db/backends/oracle/base.py

    r5979 r5982  
    386386    features = DatabaseFeatures() 
    387387    ops = DatabaseOperations() 
     388    operators = { 
     389        'exact': '= %s', 
     390        'iexact': '= UPPER(%s)', 
     391        'contains': "LIKE %s ESCAPE '\\'", 
     392        'icontains': "LIKE UPPER(%s) ESCAPE '\\'", 
     393        'gt': '> %s', 
     394        'gte': '>= %s', 
     395        'lt': '< %s', 
     396        'lte': '<= %s', 
     397        'startswith': "LIKE %s ESCAPE '\\'", 
     398        'endswith': "LIKE %s ESCAPE '\\'", 
     399        'istartswith': "LIKE UPPER(%s) ESCAPE '\\'", 
     400        'iendswith': "LIKE UPPER(%s) ESCAPE '\\'", 
     401    } 
    388402 
    389403    def _valid_connection(self): 
     
    499513    name_length = DatabaseOperations().max_name_length() - 3 
    500514    return '%s_TR' % util.truncate_name(table, name_length).upper() 
    501  
    502 OPERATOR_MAPPING = { 
    503     'exact': '= %s', 
    504     'iexact': '= UPPER(%s)', 
    505     'contains': "LIKE %s ESCAPE '\\'", 
    506     'icontains': "LIKE UPPER(%s) ESCAPE '\\'", 
    507     'gt': '> %s', 
    508     'gte': '>= %s', 
    509     'lt': '< %s', 
    510     'lte': '<= %s', 
    511     'startswith': "LIKE %s ESCAPE '\\'", 
    512     'endswith': "LIKE %s ESCAPE '\\'", 
    513     'istartswith': "LIKE UPPER(%s) ESCAPE '\\'", 
    514     'iendswith': "LIKE UPPER(%s) ESCAPE '\\'", 
    515 } 
  • django/trunk/django/db/backends/postgresql/base.py

    r5974 r5982  
    6363    features = DatabaseFeatures() 
    6464    ops = DatabaseOperations() 
     65    operators = { 
     66        'exact': '= %s', 
     67        'iexact': 'ILIKE %s', 
     68        'contains': 'LIKE %s', 
     69        'icontains': 'ILIKE %s', 
     70        'regex': '~ %s', 
     71        'iregex': '~* %s', 
     72        'gt': '> %s', 
     73        'gte': '>= %s', 
     74        'lt': '< %s', 
     75        'lte': '<= %s', 
     76        'startswith': 'LIKE %s', 
     77        'endswith': 'LIKE %s', 
     78        'istartswith': 'ILIKE %s', 
     79        'iendswith': 'ILIKE %s', 
     80    } 
    6581 
    6682    def _cursor(self, settings): 
     
    112128Database.register_type(Database.new_type((1700,), "NUMERIC", util.typecast_decimal)) 
    113129Database.register_type(Database.new_type(Database.types[1043].values, 'STRING', typecast_string)) 
    114  
    115 OPERATOR_MAPPING = { 
    116     'exact': '= %s', 
    117     'iexact': 'ILIKE %s', 
    118     'contains': 'LIKE %s', 
    119     'icontains': 'ILIKE %s', 
    120     'regex': '~ %s', 
    121     'iregex': '~* %s', 
    122     'gt': '> %s', 
    123     'gte': '>= %s', 
    124     'lt': '< %s', 
    125     'lte': '<= %s', 
    126     'startswith': 'LIKE %s', 
    127     'endswith': 'LIKE %s', 
    128     'istartswith': 'ILIKE %s', 
    129     'iendswith': 'ILIKE %s', 
    130 } 
  • django/trunk/django/db/backends/postgresql_psycopg2/base.py

    r5974 r5982  
    2525    features = DatabaseFeatures() 
    2626    ops = DatabaseOperations() 
     27    operators = { 
     28        'exact': '= %s', 
     29        'iexact': 'ILIKE %s', 
     30        'contains': 'LIKE %s', 
     31        'icontains': 'ILIKE %s', 
     32        'regex': '~ %s', 
     33        'iregex': '~* %s', 
     34        'gt': '> %s', 
     35        'gte': '>= %s', 
     36        'lt': '< %s', 
     37        'lte': '<= %s', 
     38        'startswith': 'LIKE %s', 
     39        'endswith': 'LIKE %s', 
     40        'istartswith': 'ILIKE %s', 
     41        'iendswith': 'ILIKE %s', 
     42    } 
    2743 
    2844    def _cursor(self, settings): 
     
    5369            self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')] 
    5470        return cursor 
    55  
    56 OPERATOR_MAPPING = { 
    57     'exact': '= %s', 
    58     'iexact': 'ILIKE %s', 
    59     'contains': 'LIKE %s', 
    60     'icontains': 'ILIKE %s', 
    61     'regex': '~ %s', 
    62     'iregex': '~* %s', 
    63     'gt': '> %s', 
    64     'gte': '>= %s', 
    65     'lt': '< %s', 
    66     'lte': '<= %s', 
    67     'startswith': 'LIKE %s', 
    68     'endswith': 'LIKE %s', 
    69     'istartswith': 'ILIKE %s', 
    70     'iendswith': 'ILIKE %s', 
    71 } 
  • django/trunk/django/db/backends/sqlite3/base.py

    r5974 r5982  
    7777    ops = DatabaseOperations() 
    7878 
     79    # SQLite requires LIKE statements to include an ESCAPE clause if the value 
     80    # being escaped has a percent or underscore in it. 
     81    # See http://www.sqlite.org/lang_expr.html for an explanation. 
     82    operators = { 
     83        'exact': '= %s', 
     84        'iexact': "LIKE %s ESCAPE '\\'", 
     85        'contains': "LIKE %s ESCAPE '\\'", 
     86        'icontains': "LIKE %s ESCAPE '\\'", 
     87        'regex': 'REGEXP %s', 
     88        'iregex': "REGEXP '(?i)' || %s", 
     89        'gt': '> %s', 
     90        'gte': '>= %s', 
     91        'lt': '< %s', 
     92        'lte': '<= %s', 
     93        'startswith': "LIKE %s ESCAPE '\\'", 
     94        'endswith': "LIKE %s ESCAPE '\\'", 
     95        'istartswith': "LIKE %s ESCAPE '\\'", 
     96        'iendswith': "LIKE %s ESCAPE '\\'", 
     97    } 
     98 
    7999    def _cursor(self, settings): 
    80100        if self.connection is None: 
     
    141161    except: 
    142162        return False 
    143  
    144 # SQLite requires LIKE statements to include an ESCAPE clause if the value 
    145 # being escaped has a percent or underscore in it. 
    146 # See http://www.sqlite.org/lang_expr.html for an explanation. 
    147 OPERATOR_MAPPING = { 
    148     'exact': '= %s', 
    149     'iexact': "LIKE %s ESCAPE '\\'", 
    150     'contains': "LIKE %s ESCAPE '\\'", 
    151     'icontains': "LIKE %s ESCAPE '\\'", 
    152     'regex': 'REGEXP %s', 
    153     'iregex': "REGEXP '(?i)' || %s", 
    154     'gt': '> %s', 
    155     'gte': '>= %s', 
    156     'lt': '< %s', 
    157     'lte': '<= %s', 
    158     'startswith': "LIKE %s ESCAPE '\\'", 
    159     'endswith': "LIKE %s ESCAPE '\\'", 
    160     'istartswith': "LIKE %s ESCAPE '\\'", 
    161     'iendswith': "LIKE %s ESCAPE '\\'", 
    162 } 
    163  
  • django/trunk/django/db/models/query.py

    r5977 r5982  
    11from django.conf import settings 
    2 from django.db import backend, connection, transaction 
     2from django.db import connection, transaction 
    33from django.db.models.fields import DateField, FieldDoesNotExist 
    44from django.db.models import signals, loading 
     
    798798        format = '%s %s' 
    799799    try: 
    800         return format % (field_sql, backend.OPERATOR_MAPPING[lookup_type] % cast_sql) 
     800        return format % (field_sql, connection.operators[lookup_type] % cast_sql) 
    801801    except KeyError: 
    802802        pass