Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Adrian Holovaty authored August 20, 2007
9  django/db/backends/__init__.py
@@ -103,6 +103,15 @@ def drop_foreignkey_sql(self):
103 103
         """
104 104
         return "DROP CONSTRAINT"
105 105
 
  106
+    def field_cast_sql(self, db_type):
  107
+        """
  108
+        Given a column type (e.g. 'BLOB', 'VARCHAR'), returns the SQL necessary
  109
+        to cast it before using it in a WHERE statement. Note that the
  110
+        resulting string should contain a '%s' placeholder for the column being
  111
+        searched against.
  112
+        """
  113
+        return '%s'
  114
+
106 115
     def fulltext_search_sql(self, field_name):
107 116
         """
108 117
         Returns the SQL WHERE clause to use in order to perform a full-text
12  django/db/backends/oracle/base.py
@@ -66,6 +66,12 @@ def datetime_cast_sql(self):
66 66
     def deferrable_sql(self):
67 67
         return " DEFERRABLE INITIALLY DEFERRED"
68 68
 
  69
+    def field_cast_sql(self, db_type):
  70
+        if db_type.endswith('LOB'):
  71
+            return "DBMS_LOB.SUBSTR(%s)"
  72
+        else:
  73
+            return "%s"
  74
+
69 75
     def last_insert_id(self, cursor, table_name, pk_name):
70 76
         sq_name = util.truncate_name(table_name, self.max_name_length() - 3)
71 77
         cursor.execute('SELECT %s_sq.currval FROM dual' % sq_name)
@@ -462,12 +468,6 @@ def to_unicode(s):
462 468
         return force_unicode(s)
463 469
     return s
464 470
 
465  
-def get_field_cast_sql(db_type):
466  
-    if db_type.endswith('LOB'):
467  
-        return "DBMS_LOB.SUBSTR(%s%s)"
468  
-    else:
469  
-        return "%s%s"
470  
-
471 471
 def get_drop_sequence(table):
472 472
     return "DROP SEQUENCE %s;" % DatabaseOperations().quote_name(get_sequence_name(table))
473 473
 
6  django/db/models/query.py
@@ -791,11 +791,7 @@ def get_where_clause(lookup_type, table_prefix, field_name, value, db_type):
791 791
         cast_sql = connection.ops.datetime_cast_sql()
792 792
     else:
793 793
         cast_sql = '%s'
794  
-    if db_type and hasattr(backend, 'get_field_cast_sql'):
795  
-        field_cast_sql = backend.get_field_cast_sql(db_type)
796  
-    else:
797  
-        field_cast_sql = '%s%s'
798  
-    field_sql = field_cast_sql % (table_prefix, field_name)
  794
+    field_sql = connection.ops.field_cast_sql(db_type) % (table_prefix + field_name)
799 795
     if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith') and connection.features.needs_upper_for_iops:
800 796
         format = 'UPPER(%s) %s'
801 797
     else:

0 notes on commit 4c5248f

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