Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #800 -- Fixed bug in treatement of underscores and percent sign…

…s in SQLite backend. In order to do this, changed OPERATOR_MAPPING in DB backends to include a format string of the field value, because ESCAPE comes after the field value.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1326 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit f1a8869339a4d6d004028c1234aaf706e420b5dd 1 parent 10ca90a
Adrian Holovaty authored November 21, 2005
26  django/core/db/backends/ado_mssql.py
@@ -116,19 +116,19 @@ def get_relations(cursor, table_name):
116 116
     raise NotImplementedError
117 117
 
118 118
 OPERATOR_MAPPING = {
119  
-    'exact': '=',
120  
-    'iexact': 'LIKE',
121  
-    'contains': 'LIKE',
122  
-    'icontains': 'LIKE',
123  
-    'ne': '!=',
124  
-    'gt': '>',
125  
-    'gte': '>=',
126  
-    'lt': '<',
127  
-    'lte': '<=',
128  
-    'startswith': 'LIKE',
129  
-    'endswith': 'LIKE',
130  
-    'istartswith': 'LIKE',
131  
-    'iendswith': 'LIKE',
  119
+    'exact': '= %s',
  120
+    'iexact': 'LIKE %s',
  121
+    'contains': 'LIKE %s',
  122
+    'icontains': 'LIKE %s',
  123
+    'ne': '!= %s',
  124
+    'gt': '> %s',
  125
+    'gte': '>= %s',
  126
+    'lt': '< %s',
  127
+    'lte': '<= %s',
  128
+    'startswith': 'LIKE %s',
  129
+    'endswith': 'LIKE %s',
  130
+    'istartswith': 'LIKE %s',
  131
+    'iendswith': 'LIKE %s',
132 132
 }
133 133
 
134 134
 DATA_TYPES = {
26  django/core/db/backends/mysql.py
@@ -128,19 +128,19 @@ def get_relations(cursor, table_name):
128 128
     raise NotImplementedError
129 129
 
130 130
 OPERATOR_MAPPING = {
131  
-    'exact': '=',
132  
-    'iexact': 'LIKE',
133  
-    'contains': 'LIKE BINARY',
134  
-    'icontains': 'LIKE',
135  
-    'ne': '!=',
136  
-    'gt': '>',
137  
-    'gte': '>=',
138  
-    'lt': '<',
139  
-    'lte': '<=',
140  
-    'startswith': 'LIKE BINARY',
141  
-    'endswith': 'LIKE BINARY',
142  
-    'istartswith': 'LIKE',
143  
-    'iendswith': 'LIKE',
  131
+    'exact': '= %s',
  132
+    'iexact': 'LIKE %s',
  133
+    'contains': 'LIKE BINARY %s',
  134
+    'icontains': 'LIKE %s',
  135
+    'ne': '!= %s',
  136
+    'gt': '> %s',
  137
+    'gte': '>= %s',
  138
+    'lt': '< %s',
  139
+    'lte': '<= %s',
  140
+    'startswith': 'LIKE BINARY %s',
  141
+    'endswith': 'LIKE BINARY %s',
  142
+    'istartswith': 'LIKE %s',
  143
+    'iendswith': 'LIKE %s',
144 144
 }
145 145
 
146 146
 # This dictionary maps Field objects to their associated MySQL column
26  django/core/db/backends/postgresql.py
@@ -133,19 +133,19 @@ def get_relations(cursor, table_name):
133 133
 Database.register_type(Database.new_type((16,), "BOOLEAN", typecasts.typecast_boolean))
134 134
 
135 135
 OPERATOR_MAPPING = {
136  
-    'exact': '=',
137  
-    'iexact': 'ILIKE',
138  
-    'contains': 'LIKE',
139  
-    'icontains': 'ILIKE',
140  
-    'ne': '!=',
141  
-    'gt': '>',
142  
-    'gte': '>=',
143  
-    'lt': '<',
144  
-    'lte': '<=',
145  
-    'startswith': 'LIKE',
146  
-    'endswith': 'LIKE',
147  
-    'istartswith': 'ILIKE',
148  
-    'iendswith': 'ILIKE',
  136
+    'exact': '= %s',
  137
+    'iexact': 'ILIKE %s',
  138
+    'contains': 'LIKE %s',
  139
+    'icontains': 'ILIKE %s',
  140
+    'ne': '!= %s',
  141
+    'gt': '> %s',
  142
+    'gte': '>= %s',
  143
+    'lt': '< %s',
  144
+    'lte': '<= %s',
  145
+    'startswith': 'LIKE %s',
  146
+    'endswith': 'LIKE %s',
  147
+    'istartswith': 'ILIKE %s',
  148
+    'iendswith': 'ILIKE %s',
149 149
 }
150 150
 
151 151
 # This dictionary maps Field objects to their associated PostgreSQL column
29  django/core/db/backends/sqlite3.py
@@ -131,20 +131,23 @@ def get_relations(cursor, table_name):
131 131
 
132 132
 # Operators and fields ########################################################
133 133
 
  134
+# SQLite requires LIKE statements to include an ESCAPE clause if the value
  135
+# being escaped has a percent or underscore in it.
  136
+# See http://www.sqlite.org/lang_expr.html for an explanation.
134 137
 OPERATOR_MAPPING = {
135  
-    'exact':        '=',
136  
-    'iexact':       'LIKE',
137  
-    'contains':     'LIKE',
138  
-    'icontains':    'LIKE',
139  
-    'ne':           '!=',
140  
-    'gt':           '>',
141  
-    'gte':          '>=',
142  
-    'lt':           '<',
143  
-    'lte':          '<=',
144  
-    'startswith':   'LIKE',
145  
-    'endswith':     'LIKE',
146  
-    'istartswith':  'LIKE',
147  
-    'iendswith':    'LIKE',
  138
+    'exact': '= %s',
  139
+    'iexact': "LIKE %s ESCAPE '\\'",
  140
+    'contains': "LIKE %s ESCAPE '\\'",
  141
+    'icontains': "LIKE %s ESCAPE '\\'",
  142
+    'ne': '!= %s',
  143
+    'gt': '> %s',
  144
+    'gte': '>= %s',
  145
+    'lt': '< %s',
  146
+    'lte': '<= %s',
  147
+    'startswith': "LIKE %s ESCAPE '\\'",
  148
+    'endswith': "LIKE %s ESCAPE '\\'",
  149
+    'istartswith': "LIKE %s ESCAPE '\\'",
  150
+    'iendswith': "LIKE %s ESCAPE '\\'",
148 151
 }
149 152
 
150 153
 # SQLite doesn't actually support most of these types, but it "does the right
2  django/core/meta/__init__.py
@@ -1127,7 +1127,7 @@ def _get_where_clause(lookup_type, table_prefix, field_name, value):
1127 1127
         table_prefix = db.db.quote_name(table_prefix[:-1])+'.'
1128 1128
     field_name = db.db.quote_name(field_name)
1129 1129
     try:
1130  
-        return '%s%s %s %%s' % (table_prefix, field_name, db.OPERATOR_MAPPING[lookup_type])
  1130
+        return '%s%s %s' % (table_prefix, field_name, (db.OPERATOR_MAPPING[lookup_type] % '%s'))
1131 1131
     except KeyError:
1132 1132
         pass
1133 1133
     if lookup_type == 'in':

0 notes on commit f1a8869

Please sign in to comment.
Something went wrong with that request. Please try again.