diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py
index 4ffe708..875bbbc 100644
a
|
b
|
class DatabaseFeatures(BaseDatabaseFeatures):
|
87 | 87 | supports_tablespaces = True |
88 | 88 | supports_sequence_reset = False |
89 | 89 | |
| 90 | class OracleDateTimeAdapter(datetime.datetime): |
| 91 | input_size = cx_Oracle.TIMESTAMP |
| 92 | |
90 | 93 | class DatabaseOperations(BaseDatabaseOperations): |
91 | 94 | compiler_module = "django.db.backends.oracle.compiler" |
92 | 95 | |
… |
… |
WHEN (new.%(col_name)s IS NULL)
|
358 | 361 | else: |
359 | 362 | return "TABLESPACE %s" % self.quote_name(tablespace) |
360 | 363 | |
| 364 | def value_to_db_date(self, value): |
| 365 | """ |
| 366 | Transform a date value to an object compatible with what is expected |
| 367 | by the backend driver for date columns. |
| 368 | """ |
| 369 | if value is None: |
| 370 | return None |
| 371 | return value |
| 372 | |
361 | 373 | def value_to_db_datetime(self, value): |
| 374 | """ |
| 375 | Transform a datetime value to an object compatible with what is expected |
| 376 | by the backend driver for datetime columns. |
| 377 | |
| 378 | If naive datetime is passed assumes that is in UTC. Normally Django |
| 379 | models.DateTimeField makes sure that if USE_TZ is True passed datetime |
| 380 | is timezone aware. |
| 381 | """ |
| 382 | |
362 | 383 | if value is None: |
363 | 384 | return None |
364 | | |
365 | | # Oracle doesn't support tz-aware datetimes |
366 | | if timezone.is_aware(value): |
367 | | if settings.USE_TZ: |
368 | | value = value.astimezone(timezone.utc).replace(tzinfo=None) |
| 385 | |
| 386 | if settings.USE_TZ: |
| 387 | if timezone.is_aware(value): |
| 388 | value = value.astimezone(timezone.utc) |
369 | 389 | else: |
370 | | raise ValueError("Oracle backend does not support timezone-aware datetimes when USE_TZ is False.") |
371 | | |
372 | | return six.text_type(value) |
373 | | |
| 390 | # Assume that naive datetime is actually in UTC, |
| 391 | value = value.replace(tzinfo=timezone.utc) |
| 392 | elif timezone.is_aware(value): |
| 393 | raise ValueError("Oracle backend does not support timezone-aware datetimes when USE_TZ is False.") |
| 394 | |
| 395 | |
| 396 | value = OracleDateTimeAdapter(value.year, value.month, value.day, |
| 397 | value.hour, value.minute, value.second, |
| 398 | value.microsecond, value.tzinfo) |
| 399 | |
| 400 | return value |
| 401 | |
374 | 402 | def value_to_db_time(self, value): |
375 | 403 | if value is None: |
376 | 404 | return None |
… |
… |
WHEN (new.%(col_name)s IS NULL)
|
386 | 414 | value.second, value.microsecond) |
387 | 415 | |
388 | 416 | def year_lookup_bounds_for_date_field(self, value): |
389 | | first = '%s-01-01' |
390 | | second = '%s-12-31' |
391 | | return [first % value, second % value] |
| 417 | # Create bounds as real date values |
| 418 | first = datetime.date(value, 1, 1) |
| 419 | last = datetime.date(value, 12, 31) |
| 420 | return [first, last] |
392 | 421 | |
393 | 422 | def combine_expression(self, connector, sub_expressions): |
394 | 423 | "Oracle requires special cases for %% and & operators in query expressions" |