Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
@adrianholovaty adrianholovaty authored
View
26 django/core/db/backends/ado_mssql.py
@@ -116,19 +116,19 @@ def get_relations(cursor, table_name):
raise NotImplementedError
OPERATOR_MAPPING = {
- 'exact': '=',
- 'iexact': 'LIKE',
- 'contains': 'LIKE',
- 'icontains': 'LIKE',
- 'ne': '!=',
- 'gt': '>',
- 'gte': '>=',
- 'lt': '<',
- 'lte': '<=',
- 'startswith': 'LIKE',
- 'endswith': 'LIKE',
- 'istartswith': 'LIKE',
- 'iendswith': 'LIKE',
+ 'exact': '= %s',
+ 'iexact': 'LIKE %s',
+ 'contains': 'LIKE %s',
+ 'icontains': 'LIKE %s',
+ 'ne': '!= %s',
+ 'gt': '> %s',
+ 'gte': '>= %s',
+ 'lt': '< %s',
+ 'lte': '<= %s',
+ 'startswith': 'LIKE %s',
+ 'endswith': 'LIKE %s',
+ 'istartswith': 'LIKE %s',
+ 'iendswith': 'LIKE %s',
}
DATA_TYPES = {
View
26 django/core/db/backends/mysql.py
@@ -128,19 +128,19 @@ def get_relations(cursor, table_name):
raise NotImplementedError
OPERATOR_MAPPING = {
- 'exact': '=',
- 'iexact': 'LIKE',
- 'contains': 'LIKE BINARY',
- 'icontains': 'LIKE',
- 'ne': '!=',
- 'gt': '>',
- 'gte': '>=',
- 'lt': '<',
- 'lte': '<=',
- 'startswith': 'LIKE BINARY',
- 'endswith': 'LIKE BINARY',
- 'istartswith': 'LIKE',
- 'iendswith': 'LIKE',
+ 'exact': '= %s',
+ 'iexact': 'LIKE %s',
+ 'contains': 'LIKE BINARY %s',
+ 'icontains': 'LIKE %s',
+ 'ne': '!= %s',
+ 'gt': '> %s',
+ 'gte': '>= %s',
+ 'lt': '< %s',
+ 'lte': '<= %s',
+ 'startswith': 'LIKE BINARY %s',
+ 'endswith': 'LIKE BINARY %s',
+ 'istartswith': 'LIKE %s',
+ 'iendswith': 'LIKE %s',
}
# This dictionary maps Field objects to their associated MySQL column
View
26 django/core/db/backends/postgresql.py
@@ -133,19 +133,19 @@ def get_relations(cursor, table_name):
Database.register_type(Database.new_type((16,), "BOOLEAN", typecasts.typecast_boolean))
OPERATOR_MAPPING = {
- 'exact': '=',
- 'iexact': 'ILIKE',
- 'contains': 'LIKE',
- 'icontains': 'ILIKE',
- 'ne': '!=',
- 'gt': '>',
- 'gte': '>=',
- 'lt': '<',
- 'lte': '<=',
- 'startswith': 'LIKE',
- 'endswith': 'LIKE',
- 'istartswith': 'ILIKE',
- 'iendswith': 'ILIKE',
+ 'exact': '= %s',
+ 'iexact': 'ILIKE %s',
+ 'contains': 'LIKE %s',
+ 'icontains': 'ILIKE %s',
+ 'ne': '!= %s',
+ 'gt': '> %s',
+ 'gte': '>= %s',
+ 'lt': '< %s',
+ 'lte': '<= %s',
+ 'startswith': 'LIKE %s',
+ 'endswith': 'LIKE %s',
+ 'istartswith': 'ILIKE %s',
+ 'iendswith': 'ILIKE %s',
}
# This dictionary maps Field objects to their associated PostgreSQL column
View
29 django/core/db/backends/sqlite3.py
@@ -131,20 +131,23 @@ def get_relations(cursor, table_name):
# Operators and fields ########################################################
+# SQLite requires LIKE statements to include an ESCAPE clause if the value
+# being escaped has a percent or underscore in it.
+# See http://www.sqlite.org/lang_expr.html for an explanation.
OPERATOR_MAPPING = {
- 'exact': '=',
- 'iexact': 'LIKE',
- 'contains': 'LIKE',
- 'icontains': 'LIKE',
- 'ne': '!=',
- 'gt': '>',
- 'gte': '>=',
- 'lt': '<',
- 'lte': '<=',
- 'startswith': 'LIKE',
- 'endswith': 'LIKE',
- 'istartswith': 'LIKE',
- 'iendswith': 'LIKE',
+ 'exact': '= %s',
+ 'iexact': "LIKE %s ESCAPE '\\'",
+ 'contains': "LIKE %s ESCAPE '\\'",
+ 'icontains': "LIKE %s ESCAPE '\\'",
+ 'ne': '!= %s',
+ 'gt': '> %s',
+ 'gte': '>= %s',
+ 'lt': '< %s',
+ 'lte': '<= %s',
+ 'startswith': "LIKE %s ESCAPE '\\'",
+ 'endswith': "LIKE %s ESCAPE '\\'",
+ 'istartswith': "LIKE %s ESCAPE '\\'",
+ 'iendswith': "LIKE %s ESCAPE '\\'",
}
# SQLite doesn't actually support most of these types, but it "does the right
View
2  django/core/meta/__init__.py
@@ -1127,7 +1127,7 @@ def _get_where_clause(lookup_type, table_prefix, field_name, value):
table_prefix = db.db.quote_name(table_prefix[:-1])+'.'
field_name = db.db.quote_name(field_name)
try:
- return '%s%s %s %%s' % (table_prefix, field_name, db.OPERATOR_MAPPING[lookup_type])
+ return '%s%s %s' % (table_prefix, field_name, (db.OPERATOR_MAPPING[lookup_type] % '%s'))
except KeyError:
pass
if lookup_type == 'in':
Please sign in to comment.
Something went wrong with that request. Please try again.