Changeset 8215 for django/branches/gis/django/db/backends
- Timestamp:
- 08/05/08 12:15:33 (5 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/db/backends/__init__.py (modified) (5 diffs)
- django/branches/gis/django/db/backends/mysql/base.py (modified) (2 diffs)
- django/branches/gis/django/db/backends/oracle/base.py (modified) (6 diffs)
- django/branches/gis/django/db/backends/oracle/query.py (modified) (4 diffs)
- django/branches/gis/django/db/backends/sqlite3/base.py (modified) (2 diffs)
- django/branches/gis/django/db/backends/util.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7978 to /django/trunk:1-8214
django/branches/gis/django/db/backends/__init__.py
r7979 r8215 5 5 # Import copy of _thread_local.py from Python 2.4 6 6 from django.utils._threading_local import local 7 8 from django.db.backends import util 9 from django.utils import datetime_safe 7 10 8 11 class BaseDatabaseWrapper(local): … … 37 40 38 41 def make_debug_cursor(self, cursor): 39 from django.db.backends import util40 42 return util.CursorDebugWrapper(cursor, self) 41 43 … … 43 45 allows_group_by_ordinal = True 44 46 inline_fk_references = True 47 # True if django.db.backend.utils.typecast_timestamp is used on values 48 # returned from dates() calls. 45 49 needs_datetime_string_cast = True 46 50 supports_constraints = True … … 50 54 empty_fetchmany_value = [] 51 55 update_can_self_select = True 52 supports_usecs = True53 time_field_needs_date = False54 56 interprets_empty_strings_as_nulls = False 55 date_field_supports_time_value = True56 57 can_use_chunked_reads = True 57 58 … … 264 265 from django.utils.encoding import smart_unicode 265 266 return smart_unicode(x).replace("\\", "\\\\").replace("%", "\%").replace("_", "\_") 267 268 def value_to_db_date(self, value): 269 """ 270 Transform a date value to an object compatible with what is expected 271 by the backend driver for date columns. 272 """ 273 if value is None: 274 return None 275 return datetime_safe.new_date(value).strftime('%Y-%m-%d') 276 277 def value_to_db_datetime(self, value): 278 """ 279 Transform a datetime value to an object compatible with what is expected 280 by the backend driver for datetime columns. 281 """ 282 if value is None: 283 return None 284 return unicode(value) 285 286 def value_to_db_time(self, value): 287 """ 288 Transform a datetime value to an object compatible with what is expected 289 by the backend driver for time columns. 290 """ 291 if value is None: 292 return None 293 return unicode(value) 294 295 def value_to_db_decimal(self, value, max_digits, decimal_places): 296 """ 297 Transform a decimal.Decimal value to an object compatible with what is 298 expected by the backend driver for decimal (numeric) columns. 299 """ 300 if value is None: 301 return None 302 return util.format_number(value, max_digits, decimal_places) 303 304 def year_lookup_bounds(self, value): 305 """ 306 Returns a two-elements list with the lower and upper bound to be used 307 with a BETWEEN operator to query a field value using a year lookup 308 309 `value` is an int, containing the looked-up year. 310 """ 311 first = '%s-01-01 00:00:00' 312 second = '%s-12-31 23:59:59.999999' 313 return [first % value, second % value] 314 315 def year_lookup_bounds_for_date_field(self, value): 316 """ 317 Returns a two-elements list with the lower and upper bound to be used 318 with a BETWEEN operator to query a DateField value using a year lookup 319 320 `value` is an int, containing the looked-up year. 321 322 By default, it just calls `self.year_lookup_bounds`. Some backends need 323 this hook because on their DB date fields can't be compared to values 324 which include a time part. 325 """ 326 return self.year_lookup_bounds(value) 327 django/branches/gis/django/db/backends/mysql/base.py
r7918 r8215 64 64 empty_fetchmany_value = () 65 65 update_can_self_select = False 66 supports_usecs = False67 66 68 67 class DatabaseOperations(BaseDatabaseOperations): … … 124 123 else: 125 124 return [] 125 126 def value_to_db_datetime(self, value): 127 # MySQL doesn't support microseconds 128 if value is None: 129 return None 130 return unicode(value.replace(microsecond=0)) 131 132 def value_to_db_time(self, value): 133 # MySQL doesn't support microseconds 134 if value is None: 135 return None 136 return unicode(value.replace(microsecond=0)) 137 138 def year_lookup_bounds(self, value): 139 # Again, no microseconds 140 first = '%s-01-01 00:00:00' 141 second = '%s-12-31 23:59:59.99' 142 return [first % value, second % value] 126 143 127 144 class DatabaseWrapper(BaseDatabaseWrapper): django/branches/gis/django/db/backends/oracle/base.py
r7918 r8215 6 6 7 7 import os 8 import datetime 9 import time 8 10 9 11 from django.db.backends import BaseDatabaseWrapper, BaseDatabaseFeatures, BaseDatabaseOperations, util 10 12 from django.db.backends.oracle import query 11 from django.utils.datastructures import SortedDict12 13 from django.utils.encoding import smart_str, force_unicode 13 14 … … 30 31 uses_case_insensitive_names = True 31 32 uses_custom_query_class = True 32 time_field_needs_date = True33 33 interprets_empty_strings_as_nulls = True 34 date_field_supports_time_value = False35 34 36 35 class DatabaseOperations(BaseDatabaseOperations): … … 181 180 def tablespace_sql(self, tablespace, inline=False): 182 181 return "%sTABLESPACE %s" % ((inline and "USING INDEX " or ""), self.quote_name(tablespace)) 182 183 def value_to_db_time(self, value): 184 if value is None: 185 return None 186 if isinstance(value, basestring): 187 return datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6])) 188 return datetime.datetime(1900, 1, 1, value.hour, value.minute, 189 value.second, value.microsecond) 190 191 def year_lookup_bounds_for_date_field(self, value): 192 first = '%s-01-01' 193 second = '%s-12-31' 194 return [first % value, second % value] 195 196 183 197 184 198 class DatabaseWrapper(BaseDatabaseWrapper): … … 246 260 class OracleParam(object): 247 261 """ 248 Wrapper object for formatting parameters for Oracle. If the string 249 representation of the value is large enough (greater than 4000 characters) 262 Wrapper object for formatting parameters for Oracle. If the string 263 representation of the value is large enough (greater than 4000 characters) 250 264 the input size needs to be set as NCLOB. Alternatively, if the parameter has 251 an `input_size` attribute, then the value of the `input_size` attribute will 265 an `input_size` attribute, then the value of the `input_size` attribute will 252 266 be used instead. Otherwise, no input size will be set for the parameter when 253 267 executing the query. … … 283 297 else: 284 298 return tuple([OracleParam(p, self.charset, True) for p in params]) 285 299 286 300 def _guess_input_sizes(self, params_list): 287 301 if isinstance(params_list[0], dict): … … 304 318 else: 305 319 return [p.smart_str for p in params] 306 320 307 321 def execute(self, query, params=None): 308 322 if params is None: django/branches/gis/django/db/backends/oracle/query.py
r7523 r8215 88 88 included in the query. 89 89 """ 90 90 91 # The `do_offset` flag indicates whether we need to construct 91 92 # the SQL needed to use limit/offset w/Oracle. 92 do_offset = with_limits and (self.high_mark or self.low_mark) 93 do_offset = with_limits and (self.high_mark is not None 94 or self.low_mark) 93 95 94 96 # If no offsets, just return the result of the base class … … 118 120 # extra selection SQL. 119 121 self.extra_select['rn'] = 'ROW_NUMBER() OVER (ORDER BY %s )' % rn_orderby 120 sql, params = super(OracleQuery, self).as_sql(with_limits=False,122 sql, params = super(OracleQuery, self).as_sql(with_limits=False, 121 123 with_col_aliases=True) 122 124 … … 127 129 # Place WHERE condition on `rn` for the desired range. 128 130 result.append('WHERE rn > %d' % self.low_mark) 129 if self.high_mark :131 if self.high_mark is not None: 130 132 result.append('AND rn <= %d' % self.high_mark) 131 133 … … 149 151 _classes[QueryClass] = OracleQuery 150 152 return OracleQuery 151 django/branches/gis/django/db/backends/sqlite3/base.py
r7979 r8215 85 85 return sql 86 86 87 def year_lookup_bounds(self, value): 88 first = '%s-01-01' 89 second = '%s-12-31 23:59:59.999999' 90 return [first % value, second % value] 91 92 87 93 class DatabaseWrapper(BaseDatabaseWrapper): 88 94 features = DatabaseFeatures() … … 160 166 except (ValueError, TypeError): 161 167 return None 162 return str(getattr(dt, lookup_type))168 return getattr(dt, lookup_type) 163 169 164 170 def _sqlite_date_trunc(lookup_type, dt): django/branches/gis/django/db/backends/util.py
r7279 r8215 1 1 import datetime 2 import md53 2 from time import time 3 4 from django.utils.hashcompat import md5_constructor 4 5 5 6 try: … … 115 116 return name 116 117 117 hash = md5 .md5(name).hexdigest()[:4]118 hash = md5_constructor(name).hexdigest()[:4] 118 119 119 120 return '%s%s' % (name[:length-4], hash) 121 122 def format_number(value, max_digits, decimal_places): 123 """ 124 Formats a number into a string with the requisite number of digits and 125 decimal places. 126 """ 127 return u"%.*f" % (decimal_places, value)
