Changeset 7087
- Timestamp:
- 02/04/08 06:02:36 (10 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/queryset-refactor/django/db/backends/__init__.py
r6690 r7087 87 87 retrieved as a Python datetime object instead of a string. 88 88 89 This SQL should include a '%s' in place of the field's name. This 90 method should return None if no casting is necessary. 91 """ 92 return None 89 This SQL should include a '%s' in place of the field's name. 90 """ 91 return "%s" 93 92 94 93 def deferrable_sql(self): … … 170 169 return sql 171 170 171 def lookup_cast(self, lookup_type): 172 """ 173 Returns the string to use in a query when performing lookups 174 ("contains", "like", etc). The resulting string should contain a '%s' 175 placeholder for the column being searched against. 176 """ 177 return "%s" 178 172 179 def max_name_length(self): 173 180 """ … … 206 213 return 'RANDOM()' 207 214 215 def regex_lookup(self, lookup_type): 216 """ 217 Returns the string to use in a query when performing regular expression 218 lookups (using "regex" or "iregex"). The resulting string should 219 contain a '%s' placeholder for the column being searched against. 220 221 If the feature is not supported (or part of it is not supported), a 222 NotImplementedError exception can be raised. 223 """ 224 raise NotImplementedError 225 208 226 def sql_flush(self, style, tables, sequences): 209 227 """ django/branches/queryset-refactor/django/db/backends/oracle/base.py
r7004 r7087 4 4 Requires cx_Oracle: http://www.python.net/crew/atuining/cx_Oracle/ 5 5 """ 6 7 import datetime 8 import os 6 9 7 10 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 8 11 from django.utils.datastructures import SortedDict 9 12 from django.utils.encoding import smart_str, force_unicode 10 import datetime11 import os12 13 13 14 # Oracle takes client-side character set encoding from the environment. … … 89 90 # Instead, they are handled in django/db/backends/oracle/query.py. 90 91 return "" 92 93 def lookup_cast(self, lookup_type): 94 if lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith'): 95 return "UPPER(%s)" 96 return "%s" 91 97 92 98 def max_name_length(self): … … 340 346 return "DBMS_RANDOM.RANDOM" 341 347 348 def regex_lookup_9(self, lookup_type): 349 raise NotImplementedError("Regexes are not supported in Oracle before version 10g.") 350 351 def regex_lookup_10(self, lookup_type): 352 if lookup_type == 'regex': 353 match_option = 'c' 354 else: 355 match_option = 'i' 356 return 'REGEXP_LIKE(%%s %%s %s)' % match_option 357 342 358 def sql_flush(self, style, tables, sequences): 343 359 # Return a list of 'TRUNCATE x;', 'TRUNCATE y;', … … 431 447 try: 432 448 self.oracle_version = int(self.connection.version.split('.')[0]) 449 # There's no way for the DatabaseOperations class to know the 450 # currently active Oracle version, so we do some setups here. 451 # TODO: Multi-db support will need a better solution (a way to 452 # communicate the current version). 453 if self.oracle_version <= 9: 454 self.ops.regex_lookup = self.ops.regex_lookup_9 455 else: 456 self.ops.regex_lookup = self.ops.regex_lookup_10 433 457 except ValueError: 434 458 pass django/branches/queryset-refactor/django/db/models/sql/where.py
r6967 r7087 100 100 101 101 if isinstance(value, datetime.datetime): 102 # FIXME datetime_cast_sql() should return '%s' by default. 103 cast_sql = connection.ops.datetime_cast_sql() or '%s' 102 cast_sql = connection.ops.datetime_cast_sql() 104 103 else: 105 104 cast_sql = '%s' 106 105 107 # FIXME: This is out of place. Move to a function like 108 # datetime_cast_sql() 109 if (lookup_type in ('iexact', 'icontains', 'istartswith', 'iendswith') 110 and connection.features.needs_upper_for_iops): 111 format = 'UPPER(%s) %s' 112 else: 113 format = '%s %s' 114 106 format = "%s %%s" % connection.ops.lookup_cast(lookup_type) 115 107 params = field.get_db_prep_lookup(lookup_type, value) 116 108 … … 136 128 return (connection.ops.fulltest_search_sql(field_sql), params) 137 129 elif lookup_type in ('regex', 'iregex'): 138 # FIXME: Factor this out in to connection.ops 139 if settings.DATABASE_ENGINE == 'oracle': 140 if connection.oracle_version and connection.oracle_version <= 9: 141 raise NotImplementedError("Regexes are not supported in Oracle before version 10g.") 142 if lookup_type == 'regex': 143 match_option = 'c' 144 else: 145 match_option = 'i' 146 return ("REGEXP_LIKE(%s, %s, '%s')" % (field_sql, cast_sql, 147 match_option), params) 148 else: 149 raise NotImplementedError 130 return connection.ops.regex_lookup % (field_sql, cast_sql), params 150 131 151 132 raise TypeError('Invalid lookup_type: %r' % lookup_type)
