Ticket #5087: oracle_textfield_lookup.diff
File oracle_textfield_lookup.diff, 5.1 KB (added by , 17 years ago) |
---|
-
django/db/models/query.py
777 777 return SortedDict(), [], [] 778 778 return joins, where2, params 779 779 780 def get_where_clause(lookup_type, table_prefix, field_name, value ):780 def get_where_clause(lookup_type, table_prefix, field_name, value, db_type): 781 781 if table_prefix.endswith('.'): 782 782 table_prefix = backend.quote_name(table_prefix[:-1])+'.' 783 783 field_name = backend.quote_name(field_name) … … 785 785 cast_sql = backend.get_datetime_cast_sql() 786 786 else: 787 787 cast_sql = '%s' 788 if hasattr(backend, 'get_field_cast_sql'): 789 field_cast_sql = backend.get_field_cast_sql(db_type) 790 else: 791 field_cast_sql = '%s%s' 792 field_sql = field_cast_sql % (table_prefix, field_name) 788 793 if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith') and backend.needs_upper_for_iops: 789 format = 'UPPER(%s %s) %s'794 format = 'UPPER(%s) %s' 790 795 else: 791 format = '%s %s%s'796 format = '%s %s' 792 797 try: 793 return format % ( table_prefix, field_name,798 return format % (field_sql, 794 799 backend.OPERATOR_MAPPING[lookup_type] % cast_sql) 795 800 except KeyError: 796 801 pass 797 802 if lookup_type == 'in': 798 803 in_string = ','.join(['%s' for id in value]) 799 804 if in_string: 800 return '%s %s IN (%s)' % (table_prefix, field_name, in_string)805 return '%s IN (%s)' % (field_sql, in_string) 801 806 else: 802 807 raise EmptyResultSet 803 808 elif lookup_type in ('range', 'year'): 804 return '%s %s BETWEEN %%s AND %%s' % (table_prefix, field_name)809 return '%s BETWEEN %%s AND %%s' % field_sql 805 810 elif lookup_type in ('month', 'day'): 806 return "%s = %%s" % backend.get_date_extract_sql(lookup_type, table_prefix + field_name)811 return "%s = %%s" % backend.get_date_extract_sql(lookup_type, field_sql) 807 812 elif lookup_type == 'isnull': 808 return "%s %s IS %sNULL" % (table_prefix, field_name, (not value and 'NOT ' or ''))813 return "%s IS %sNULL" % (field_sql, (not value and 'NOT ' or '')) 809 814 elif lookup_type == 'search': 810 return backend.get_fulltext_search_sql( table_prefix + field_name)815 return backend.get_fulltext_search_sql(field_sql) 811 816 elif lookup_type in ('regex', 'iregex'): 812 817 if settings.DATABASE_ENGINE == 'oracle': 813 818 if lookup_type == 'regex': 814 819 match_option = 'c' 815 820 else: 816 821 match_option = 'i' 817 return "REGEXP_LIKE(%s %s, %s, '%s')" % (table_prefix, field_name, cast_sql, match_option)822 return "REGEXP_LIKE(%s, %s, '%s')" % (field_sql, cast_sql, match_option) 818 823 else: 819 824 raise NotImplementedError 820 825 raise TypeError, "Got invalid lookup_type: %s" % repr(lookup_type) … … 1101 1106 # Last query term was a normal field. 1102 1107 column = field.column 1103 1108 1104 where.append(get_where_clause(lookup_type, current_table + '.', column, value ))1109 where.append(get_where_clause(lookup_type, current_table + '.', column, value, field.db_type())) 1105 1110 params.extend(field.get_db_prep_lookup(lookup_type, value)) 1106 1111 1107 1112 return joins, where, params -
django/db/backends/oracle/base.py
181 181 def get_datetime_cast_sql(): 182 182 return "TO_TIMESTAMP(%s, 'YYYY-MM-DD HH24:MI:SS.FF')" 183 183 184 def get_field_cast_sql(db_type): 185 if db_type.endswith('LOB'): 186 return "DBMS_LOB.SUBSTR(%s%s)" 187 else: 188 return "%s%s" 189 184 190 def get_limit_offset_sql(limit, offset=None): 185 191 # Limits and offset are too complicated to be handled here. 186 192 # Instead, they are handled in django/db/backends/oracle/query.py. -
tests/regressiontests/string_lookup/models.py
36 36 def __unicode__(self): 37 37 return "Base %s" % self.name 38 38 39 class Article(models.Model): 40 name = models.CharField(maxlength = 50) 41 text = models.TextField() 42 43 def __str__(self): 44 return "Article %s" % self.name 45 39 46 __test__ = {'API_TESTS': ur""" 40 47 # Regression test for #1661 and #1662: Check that string form referencing of 41 48 # models works, both as pre and post reference, on all RelatedField types. … … 82 89 # We can also do the above query using UTF-8 strings. 83 90 >>> Foo.objects.get(friend__contains='\xc3\xa7') 84 91 <Foo: Foo Bjorn> 92 93 # Regression tests for #5087: make sure we can perform queries on TextFields. 94 >>> a = Article(name='Test', text='The quick brown fox jumps over the lazy dog.') 95 >>> a.save() 96 >>> Article.objects.get(text__exact='The quick brown fox jumps over the lazy dog.') 97 <Article: Article Test> 98 99 >>> Article.objects.get(text__contains='quick brown fox') 100 <Article: Article Test> 85 101 """}