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
This commit is contained in:
parent
b3912d3609
commit
14db37319b
|
@ -84,6 +84,20 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
features = DatabaseFeatures()
|
features = DatabaseFeatures()
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
operators = {
|
||||||
|
'exact': '= %s',
|
||||||
|
'iexact': 'LIKE %s',
|
||||||
|
'contains': 'LIKE %s',
|
||||||
|
'icontains': 'LIKE %s',
|
||||||
|
'gt': '> %s',
|
||||||
|
'gte': '>= %s',
|
||||||
|
'lt': '< %s',
|
||||||
|
'lte': '<= %s',
|
||||||
|
'startswith': 'LIKE %s',
|
||||||
|
'endswith': 'LIKE %s',
|
||||||
|
'istartswith': 'LIKE %s',
|
||||||
|
'iendswith': 'LIKE %s',
|
||||||
|
}
|
||||||
|
|
||||||
def _cursor(self, settings):
|
def _cursor(self, settings):
|
||||||
if self.connection is None:
|
if self.connection is None:
|
||||||
|
@ -96,18 +110,3 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
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)
|
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)
|
||||||
self.connection = Database.connect(conn_string)
|
self.connection = Database.connect(conn_string)
|
||||||
return self.connection.cursor()
|
return self.connection.cursor()
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
|
||||||
'exact': '= %s',
|
|
||||||
'iexact': 'LIKE %s',
|
|
||||||
'contains': 'LIKE %s',
|
|
||||||
'icontains': 'LIKE %s',
|
|
||||||
'gt': '> %s',
|
|
||||||
'gte': '>= %s',
|
|
||||||
'lt': '< %s',
|
|
||||||
'lte': '<= %s',
|
|
||||||
'startswith': 'LIKE %s',
|
|
||||||
'endswith': 'LIKE %s',
|
|
||||||
'istartswith': 'LIKE %s',
|
|
||||||
'iendswith': 'LIKE %s',
|
|
||||||
}
|
|
||||||
|
|
|
@ -26,8 +26,9 @@ class ComplainOnGetattr(object):
|
||||||
complain()
|
complain()
|
||||||
|
|
||||||
class DatabaseWrapper(object):
|
class DatabaseWrapper(object):
|
||||||
ops = ComplainOnGetattr()
|
|
||||||
features = ComplainOnGetattr()
|
features = ComplainOnGetattr()
|
||||||
|
ops = ComplainOnGetattr()
|
||||||
|
operators = {}
|
||||||
cursor = complain
|
cursor = complain
|
||||||
_commit = complain
|
_commit = complain
|
||||||
_rollback = ignore
|
_rollback = ignore
|
||||||
|
@ -37,5 +38,3 @@ class DatabaseWrapper(object):
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
pass # close()
|
pass # close()
|
||||||
|
|
||||||
OPERATOR_MAPPING = {}
|
|
||||||
|
|
|
@ -121,6 +121,22 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
features = DatabaseFeatures()
|
features = DatabaseFeatures()
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
operators = {
|
||||||
|
'exact': '= %s',
|
||||||
|
'iexact': 'LIKE %s',
|
||||||
|
'contains': 'LIKE BINARY %s',
|
||||||
|
'icontains': 'LIKE %s',
|
||||||
|
'regex': 'REGEXP BINARY %s',
|
||||||
|
'iregex': 'REGEXP %s',
|
||||||
|
'gt': '> %s',
|
||||||
|
'gte': '>= %s',
|
||||||
|
'lt': '< %s',
|
||||||
|
'lte': '<= %s',
|
||||||
|
'startswith': 'LIKE BINARY %s',
|
||||||
|
'endswith': 'LIKE BINARY %s',
|
||||||
|
'istartswith': 'LIKE %s',
|
||||||
|
'iendswith': 'LIKE %s',
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(**kwargs)
|
super(DatabaseWrapper, self).__init__(**kwargs)
|
||||||
|
@ -178,20 +194,3 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
|
raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
|
||||||
self.server_version = tuple([int(x) for x in m.groups()])
|
self.server_version = tuple([int(x) for x in m.groups()])
|
||||||
return self.server_version
|
return self.server_version
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
|
||||||
'exact': '= %s',
|
|
||||||
'iexact': 'LIKE %s',
|
|
||||||
'contains': 'LIKE BINARY %s',
|
|
||||||
'icontains': 'LIKE %s',
|
|
||||||
'regex': 'REGEXP BINARY %s',
|
|
||||||
'iregex': 'REGEXP %s',
|
|
||||||
'gt': '> %s',
|
|
||||||
'gte': '>= %s',
|
|
||||||
'lt': '< %s',
|
|
||||||
'lte': '<= %s',
|
|
||||||
'startswith': 'LIKE BINARY %s',
|
|
||||||
'endswith': 'LIKE BINARY %s',
|
|
||||||
'istartswith': 'LIKE %s',
|
|
||||||
'iendswith': 'LIKE %s',
|
|
||||||
}
|
|
||||||
|
|
|
@ -131,6 +131,22 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
features = DatabaseFeatures()
|
features = DatabaseFeatures()
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
operators = {
|
||||||
|
'exact': '= %s',
|
||||||
|
'iexact': 'LIKE %s',
|
||||||
|
'contains': 'LIKE BINARY %s',
|
||||||
|
'icontains': 'LIKE %s',
|
||||||
|
'regex': 'REGEXP BINARY %s',
|
||||||
|
'iregex': 'REGEXP %s',
|
||||||
|
'gt': '> %s',
|
||||||
|
'gte': '>= %s',
|
||||||
|
'lt': '< %s',
|
||||||
|
'lte': '<= %s',
|
||||||
|
'startswith': 'LIKE BINARY %s',
|
||||||
|
'endswith': 'LIKE BINARY %s',
|
||||||
|
'istartswith': 'LIKE %s',
|
||||||
|
'iendswith': 'LIKE %s',
|
||||||
|
}
|
||||||
|
|
||||||
def __init__(self, **kwargs):
|
def __init__(self, **kwargs):
|
||||||
super(DatabaseWrapper, self).__init__(**kwargs)
|
super(DatabaseWrapper, self).__init__(**kwargs)
|
||||||
|
@ -197,20 +213,3 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
|
raise Exception('Unable to determine MySQL version from version string %r' % self.connection.get_server_info())
|
||||||
self.server_version = tuple([int(x) for x in m.groups()])
|
self.server_version = tuple([int(x) for x in m.groups()])
|
||||||
return self.server_version
|
return self.server_version
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
|
||||||
'exact': '= %s',
|
|
||||||
'iexact': 'LIKE %s',
|
|
||||||
'contains': 'LIKE BINARY %s',
|
|
||||||
'icontains': 'LIKE %s',
|
|
||||||
'regex': 'REGEXP BINARY %s',
|
|
||||||
'iregex': 'REGEXP %s',
|
|
||||||
'gt': '> %s',
|
|
||||||
'gte': '>= %s',
|
|
||||||
'lt': '< %s',
|
|
||||||
'lte': '<= %s',
|
|
||||||
'startswith': 'LIKE BINARY %s',
|
|
||||||
'endswith': 'LIKE BINARY %s',
|
|
||||||
'istartswith': 'LIKE %s',
|
|
||||||
'iendswith': 'LIKE %s',
|
|
||||||
}
|
|
||||||
|
|
|
@ -385,6 +385,20 @@ class DatabaseOperations(BaseDatabaseOperations):
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
features = DatabaseFeatures()
|
features = DatabaseFeatures()
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
operators = {
|
||||||
|
'exact': '= %s',
|
||||||
|
'iexact': '= UPPER(%s)',
|
||||||
|
'contains': "LIKE %s ESCAPE '\\'",
|
||||||
|
'icontains': "LIKE UPPER(%s) ESCAPE '\\'",
|
||||||
|
'gt': '> %s',
|
||||||
|
'gte': '>= %s',
|
||||||
|
'lt': '< %s',
|
||||||
|
'lte': '<= %s',
|
||||||
|
'startswith': "LIKE %s ESCAPE '\\'",
|
||||||
|
'endswith': "LIKE %s ESCAPE '\\'",
|
||||||
|
'istartswith': "LIKE UPPER(%s) ESCAPE '\\'",
|
||||||
|
'iendswith': "LIKE UPPER(%s) ESCAPE '\\'",
|
||||||
|
}
|
||||||
|
|
||||||
def _valid_connection(self):
|
def _valid_connection(self):
|
||||||
return self.connection is not None
|
return self.connection is not None
|
||||||
|
@ -498,18 +512,3 @@ def get_sequence_name(table):
|
||||||
def get_trigger_name(table):
|
def get_trigger_name(table):
|
||||||
name_length = DatabaseOperations().max_name_length() - 3
|
name_length = DatabaseOperations().max_name_length() - 3
|
||||||
return '%s_TR' % util.truncate_name(table, name_length).upper()
|
return '%s_TR' % util.truncate_name(table, name_length).upper()
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
|
||||||
'exact': '= %s',
|
|
||||||
'iexact': '= UPPER(%s)',
|
|
||||||
'contains': "LIKE %s ESCAPE '\\'",
|
|
||||||
'icontains': "LIKE UPPER(%s) ESCAPE '\\'",
|
|
||||||
'gt': '> %s',
|
|
||||||
'gte': '>= %s',
|
|
||||||
'lt': '< %s',
|
|
||||||
'lte': '<= %s',
|
|
||||||
'startswith': "LIKE %s ESCAPE '\\'",
|
|
||||||
'endswith': "LIKE %s ESCAPE '\\'",
|
|
||||||
'istartswith': "LIKE UPPER(%s) ESCAPE '\\'",
|
|
||||||
'iendswith': "LIKE UPPER(%s) ESCAPE '\\'",
|
|
||||||
}
|
|
||||||
|
|
|
@ -62,6 +62,22 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
features = DatabaseFeatures()
|
features = DatabaseFeatures()
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
operators = {
|
||||||
|
'exact': '= %s',
|
||||||
|
'iexact': 'ILIKE %s',
|
||||||
|
'contains': 'LIKE %s',
|
||||||
|
'icontains': 'ILIKE %s',
|
||||||
|
'regex': '~ %s',
|
||||||
|
'iregex': '~* %s',
|
||||||
|
'gt': '> %s',
|
||||||
|
'gte': '>= %s',
|
||||||
|
'lt': '< %s',
|
||||||
|
'lte': '<= %s',
|
||||||
|
'startswith': 'LIKE %s',
|
||||||
|
'endswith': 'LIKE %s',
|
||||||
|
'istartswith': 'ILIKE %s',
|
||||||
|
'iendswith': 'ILIKE %s',
|
||||||
|
}
|
||||||
|
|
||||||
def _cursor(self, settings):
|
def _cursor(self, settings):
|
||||||
set_tz = False
|
set_tz = False
|
||||||
|
@ -111,20 +127,3 @@ Database.register_type(Database.new_type((1114,1184), "TIMESTAMP", util.typecast
|
||||||
Database.register_type(Database.new_type((16,), "BOOLEAN", util.typecast_boolean))
|
Database.register_type(Database.new_type((16,), "BOOLEAN", util.typecast_boolean))
|
||||||
Database.register_type(Database.new_type((1700,), "NUMERIC", util.typecast_decimal))
|
Database.register_type(Database.new_type((1700,), "NUMERIC", util.typecast_decimal))
|
||||||
Database.register_type(Database.new_type(Database.types[1043].values, 'STRING', typecast_string))
|
Database.register_type(Database.new_type(Database.types[1043].values, 'STRING', typecast_string))
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
|
||||||
'exact': '= %s',
|
|
||||||
'iexact': 'ILIKE %s',
|
|
||||||
'contains': 'LIKE %s',
|
|
||||||
'icontains': 'ILIKE %s',
|
|
||||||
'regex': '~ %s',
|
|
||||||
'iregex': '~* %s',
|
|
||||||
'gt': '> %s',
|
|
||||||
'gte': '>= %s',
|
|
||||||
'lt': '< %s',
|
|
||||||
'lte': '<= %s',
|
|
||||||
'startswith': 'LIKE %s',
|
|
||||||
'endswith': 'LIKE %s',
|
|
||||||
'istartswith': 'ILIKE %s',
|
|
||||||
'iendswith': 'ILIKE %s',
|
|
||||||
}
|
|
||||||
|
|
|
@ -24,6 +24,22 @@ class DatabaseFeatures(BaseDatabaseFeatures):
|
||||||
class DatabaseWrapper(BaseDatabaseWrapper):
|
class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
features = DatabaseFeatures()
|
features = DatabaseFeatures()
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
operators = {
|
||||||
|
'exact': '= %s',
|
||||||
|
'iexact': 'ILIKE %s',
|
||||||
|
'contains': 'LIKE %s',
|
||||||
|
'icontains': 'ILIKE %s',
|
||||||
|
'regex': '~ %s',
|
||||||
|
'iregex': '~* %s',
|
||||||
|
'gt': '> %s',
|
||||||
|
'gte': '>= %s',
|
||||||
|
'lt': '< %s',
|
||||||
|
'lte': '<= %s',
|
||||||
|
'startswith': 'LIKE %s',
|
||||||
|
'endswith': 'LIKE %s',
|
||||||
|
'istartswith': 'ILIKE %s',
|
||||||
|
'iendswith': 'ILIKE %s',
|
||||||
|
}
|
||||||
|
|
||||||
def _cursor(self, settings):
|
def _cursor(self, settings):
|
||||||
set_tz = False
|
set_tz = False
|
||||||
|
@ -52,20 +68,3 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
cursor.execute("SELECT version()")
|
cursor.execute("SELECT version()")
|
||||||
self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
|
self.ops.postgres_version = [int(val) for val in cursor.fetchone()[0].split()[1].split('.')]
|
||||||
return cursor
|
return cursor
|
||||||
|
|
||||||
OPERATOR_MAPPING = {
|
|
||||||
'exact': '= %s',
|
|
||||||
'iexact': 'ILIKE %s',
|
|
||||||
'contains': 'LIKE %s',
|
|
||||||
'icontains': 'ILIKE %s',
|
|
||||||
'regex': '~ %s',
|
|
||||||
'iregex': '~* %s',
|
|
||||||
'gt': '> %s',
|
|
||||||
'gte': '>= %s',
|
|
||||||
'lt': '< %s',
|
|
||||||
'lte': '<= %s',
|
|
||||||
'startswith': 'LIKE %s',
|
|
||||||
'endswith': 'LIKE %s',
|
|
||||||
'istartswith': 'ILIKE %s',
|
|
||||||
'iendswith': 'ILIKE %s',
|
|
||||||
}
|
|
||||||
|
|
|
@ -76,6 +76,26 @@ class DatabaseWrapper(BaseDatabaseWrapper):
|
||||||
features = DatabaseFeatures()
|
features = DatabaseFeatures()
|
||||||
ops = DatabaseOperations()
|
ops = DatabaseOperations()
|
||||||
|
|
||||||
|
# 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.
|
||||||
|
operators = {
|
||||||
|
'exact': '= %s',
|
||||||
|
'iexact': "LIKE %s ESCAPE '\\'",
|
||||||
|
'contains': "LIKE %s ESCAPE '\\'",
|
||||||
|
'icontains': "LIKE %s ESCAPE '\\'",
|
||||||
|
'regex': 'REGEXP %s',
|
||||||
|
'iregex': "REGEXP '(?i)' || %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 '\\'",
|
||||||
|
}
|
||||||
|
|
||||||
def _cursor(self, settings):
|
def _cursor(self, settings):
|
||||||
if self.connection is None:
|
if self.connection is None:
|
||||||
kwargs = {
|
kwargs = {
|
||||||
|
@ -140,24 +160,3 @@ def _sqlite_regexp(re_pattern, re_string):
|
||||||
return bool(re.search(re_pattern, re_string))
|
return bool(re.search(re_pattern, re_string))
|
||||||
except:
|
except:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# 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': '= %s',
|
|
||||||
'iexact': "LIKE %s ESCAPE '\\'",
|
|
||||||
'contains': "LIKE %s ESCAPE '\\'",
|
|
||||||
'icontains': "LIKE %s ESCAPE '\\'",
|
|
||||||
'regex': 'REGEXP %s',
|
|
||||||
'iregex': "REGEXP '(?i)' || %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 '\\'",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import backend, connection, transaction
|
from django.db import connection, transaction
|
||||||
from django.db.models.fields import DateField, FieldDoesNotExist
|
from django.db.models.fields import DateField, FieldDoesNotExist
|
||||||
from django.db.models import signals, loading
|
from django.db.models import signals, loading
|
||||||
from django.dispatch import dispatcher
|
from django.dispatch import dispatcher
|
||||||
|
@ -797,7 +797,7 @@ def get_where_clause(lookup_type, table_prefix, field_name, value, db_type):
|
||||||
else:
|
else:
|
||||||
format = '%s %s'
|
format = '%s %s'
|
||||||
try:
|
try:
|
||||||
return format % (field_sql, backend.OPERATOR_MAPPING[lookup_type] % cast_sql)
|
return format % (field_sql, connection.operators[lookup_type] % cast_sql)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
pass
|
pass
|
||||||
if lookup_type == 'in':
|
if lookup_type == 'in':
|
||||||
|
|
Loading…
Reference in New Issue