Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

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
  • Loading branch information...
commit 4c5248f98f0460018aff635abd955867980bf3bc 1 parent e13ea3c
@adrianholovaty adrianholovaty authored
View
9 django/db/backends/__init__.py
@@ -103,6 +103,15 @@ def drop_foreignkey_sql(self):
"""
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
View
12 django/db/backends/oracle/base.py
@@ -66,6 +66,12 @@ def datetime_cast_sql(self):
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))
View
6 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:
Please sign in to comment.
Something went wrong with that request. Please try again.