Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 14db373

Browse files
Refactored OPERATOR_MAPPING so that it exists as django.db.connection.operators instead of django.db.backend.OPERATOR_MAPPING. Refs #5106
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5982 bcc190cf-cafb-0310-a4f2-bffc1f526a37
1 parent b3912d3 commit 14db373

File tree

9 files changed

+116
-124
lines changed

9 files changed

+116
-124
lines changed

‎django/db/backends/ado_mssql/base.py‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,20 @@ def tablespace_sql(self, tablespace, inline=False):
8484
class DatabaseWrapper(BaseDatabaseWrapper):
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):
89103
if self.connection is None:
@@ -96,18 +110,3 @@ def _cursor(self, settings):
96110
conn_string = "PROVIDER=SQLOLEDB;DATA SOURCE=%s;UID=%s;PWD=%s;DATABASE=%s" % (settings.DATABASE_HOST, settings.DATABASE_USER, settings.DATABASE_PASSWORD, settings.DATABASE_NAME)
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/db/backends/dummy/base.py‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ def __getattr__(self, *args, **kwargs):
2626
complain()
2727

2828
class DatabaseWrapper(object):
29-
ops = ComplainOnGetattr()
3029
features = ComplainOnGetattr()
30+
ops = ComplainOnGetattr()
31+
operators = {}
3132
cursor = complain
3233
_commit = complain
3334
_rollback = ignore
@@ -37,5 +38,3 @@ def __init__(self, **kwargs):
3738

3839
def close(self):
3940
pass # close()
40-
41-
OPERATOR_MAPPING = {}

‎django/db/backends/mysql/base.py‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,22 @@ def sql_flush(self, style, tables, sequences):
121121
class DatabaseWrapper(BaseDatabaseWrapper):
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):
126142
super(DatabaseWrapper, self).__init__(**kwargs)
@@ -178,20 +194,3 @@ def get_server_version(self):
178194
raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
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/db/backends/mysql_old/base.py‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,22 @@ def sql_flush(self, style, tables, sequences):
131131
class DatabaseWrapper(BaseDatabaseWrapper):
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):
136152
super(DatabaseWrapper, self).__init__(**kwargs)
@@ -197,20 +213,3 @@ def get_server_version(self):
197213
raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
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/db/backends/oracle/base.py‎

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,20 @@ def tablespace_sql(self, tablespace, inline=False):
385385
class DatabaseWrapper(BaseDatabaseWrapper):
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):
390404
return self.connection is not None
@@ -498,18 +512,3 @@ def get_sequence_name(table):
498512
def get_trigger_name(table):
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/db/backends/postgresql/base.py‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,22 @@ class DatabaseFeatures(BaseDatabaseFeatures):
6262
class DatabaseWrapper(BaseDatabaseWrapper):
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):
6783
set_tz = False
@@ -111,20 +127,3 @@ def typecast_string(s):
111127
Database.register_type(Database.new_type((16,), "BOOLEAN", util.typecast_boolean))
112128
Database.register_type(Database.new_type((1700,), "NUMERIC", util.typecast_decimal))
113129
Database.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/db/backends/postgresql_psycopg2/base.py‎

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@ class DatabaseFeatures(BaseDatabaseFeatures):
2424
class DatabaseWrapper(BaseDatabaseWrapper):
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):
2945
set_tz = False
@@ -52,20 +68,3 @@ def _cursor(self, settings):
5268
cursor.execute("SELECT version()")
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/db/backends/sqlite3/base.py‎

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,26 @@ class DatabaseWrapper(BaseDatabaseWrapper):
7676
features = DatabaseFeatures()
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:
81101
kwargs = {
@@ -140,24 +160,3 @@ def _sqlite_regexp(re_pattern, re_string):
140160
return bool(re.search(re_pattern, re_string))
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/db/models/query.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from django.conf import settings
2-
from django.db import backend, connection, transaction
2+
from django.db import connection, transaction
33
from django.db.models.fields import DateField, FieldDoesNotExist
44
from django.db.models import signals, loading
55
from django.dispatch import dispatcher
@@ -797,7 +797,7 @@ def get_where_clause(lookup_type, table_prefix, field_name, value, db_type):
797797
else:
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
803803
if lookup_type == 'in':

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /