mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
boulder-oracle-sprint: Fixed datetime behavior. All tests pass now in
Python 2.5! (Fixing 2.3 failures next...) git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5002 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
ed9c870e45
commit
5729876275
@ -298,18 +298,37 @@ def get_query_set_class(DefaultQuerySet):
|
|||||||
|
|
||||||
def resolve_cols(row):
|
def resolve_cols(row):
|
||||||
for field in row:
|
for field in row:
|
||||||
|
value = field
|
||||||
if isinstance(field, Database.LOB):
|
if isinstance(field, Database.LOB):
|
||||||
yield str(field)
|
value = field.read()
|
||||||
# cx_Oracle returns datetime.datetime objects for DATE
|
# cx_Oracle always returns datetime.datetime objects for
|
||||||
# columns, but Django wants a datetime.date.
|
# DATE and TIMESTAMP columns, but Django wants to see a
|
||||||
# A workaround is to return a date if time fields are 0.
|
# python datetime.date, .time, or .datetime.
|
||||||
# A safer fix would involve either patching cx_Oracle,
|
# As a workaround, we cast to date if all the time-related
|
||||||
|
# fields are 0, or to time if the date is 1/1/1900.
|
||||||
|
# A better fix would involve either patching cx_Oracle
|
||||||
# or checking the Model here, neither of which is good.
|
# or checking the Model here, neither of which is good.
|
||||||
elif isinstance(field, datetime.datetime) and \
|
elif isinstance(field, datetime.datetime):
|
||||||
field.hour == field.minute == field.second == field.microsecond == 0:
|
if field.hour == field.minute == field.second == field.microsecond == 0:
|
||||||
yield field.date()
|
value = field.date()
|
||||||
else:
|
elif field.year == 1900 and field.month == field.day == 1:
|
||||||
yield field
|
value = field.time()
|
||||||
|
# In Python 2.3, the cx_Oracle driver returns its own
|
||||||
|
# Timestamp object that we must convert to a datetime class.
|
||||||
|
elif isinstance(field, Database.Timestamp):
|
||||||
|
if field.hour == field.minute == field.second == field.fsecond == 0:
|
||||||
|
value = datetime.date(field.year, field.month, field.day)
|
||||||
|
elif field.year == 1900 and field.month == field.day == 1:
|
||||||
|
value = datetime.time(field.hour, field.minute, field.second, field.fsecond)
|
||||||
|
else:
|
||||||
|
value = datetime.datetime(field.year, field.month, field.day, field.hour,
|
||||||
|
field.minute, field.second, field.fsecond)
|
||||||
|
# Since Oracle won't distinguish between NULL and an empty
|
||||||
|
# string (''), we store empty strings as a space. Here is
|
||||||
|
# where we undo that treachery.
|
||||||
|
if value == ' ':
|
||||||
|
value = ''
|
||||||
|
yield value
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
rows = cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)
|
rows = cursor.fetchmany(GET_ITERATOR_CHUNK_SIZE)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user