From 4c5248f98f0460018aff635abd955867980bf3bc Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 20 Aug 2007 03:03:40 +0000 Subject: [PATCH] Refactored get_field_cast_sql() to DatabaseOperations.field_cast_sql(). Refs #5106 git-svn-id: http://code.djangoproject.com/svn/django/trunk@5977 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/__init__.py | 9 +++++++++ django/db/backends/oracle/base.py | 12 ++++++------ django/db/models/query.py | 6 +----- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/django/db/backends/__init__.py b/django/db/backends/__init__.py index 0a86ed1476d..01cc025608c 100644 --- a/django/db/backends/__init__.py +++ b/django/db/backends/__init__.py @@ -103,6 +103,15 @@ class BaseDatabaseOperations(object): """ return "DROP CONSTRAINT" + def field_cast_sql(self, db_type): + """ + Given a column type (e.g. 'BLOB', 'VARCHAR'), returns the SQL necessary + to cast it before using it in a WHERE statement. Note that the + resulting string should contain a '%s' placeholder for the column being + searched against. + """ + return '%s' + def fulltext_search_sql(self, field_name): """ Returns the SQL WHERE clause to use in order to perform a full-text diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 0f1c475871d..1a23d367096 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -66,6 +66,12 @@ class DatabaseOperations(BaseDatabaseOperations): def deferrable_sql(self): return " DEFERRABLE INITIALLY DEFERRED" + def field_cast_sql(self, db_type): + if db_type.endswith('LOB'): + return "DBMS_LOB.SUBSTR(%s)" + else: + return "%s" + def last_insert_id(self, cursor, table_name, pk_name): sq_name = util.truncate_name(table_name, self.max_name_length() - 3) cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name) @@ -462,12 +468,6 @@ def to_unicode(s): return force_unicode(s) return s -def get_field_cast_sql(db_type): - if db_type.endswith('LOB'): - return "DBMS_LOB.SUBSTR(%s%s)" - else: - return "%s%s" - def get_drop_sequence(table): return "DROP SEQUENCE %s;" % DatabaseOperations().quote_name(get_sequence_name(table)) diff --git a/django/db/models/query.py b/django/db/models/query.py index f4ebca2ac58..b0556ac2a3e 100644 --- a/django/db/models/query.py +++ b/django/db/models/query.py @@ -791,11 +791,7 @@ def get_where_clause(lookup_type, table_prefix, field_name, value, db_type): cast_sql = connection.ops.datetime_cast_sql() else: cast_sql = '%s' - if db_type and hasattr(backend, 'get_field_cast_sql'): - field_cast_sql = backend.get_field_cast_sql(db_type) - else: - field_cast_sql = '%s%s' - field_sql = field_cast_sql % (table_prefix, field_name) + field_sql = connection.ops.field_cast_sql(db_type) % (table_prefix + field_name) if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith') and connection.features.needs_upper_for_iops: format = 'UPPER(%s) %s' else: