mirror of
https://github.com/django/django.git
synced 2025-07-05 18:29:11 +00:00
boulder-oracle-sprint: Removed obsolete stripping of microseconds from datetime objects.
git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5260 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
786782edc5
commit
8ccc894e17
@ -535,18 +535,14 @@ class DateTimeField(DateField):
|
|||||||
def get_db_prep_save(self, value):
|
def get_db_prep_save(self, value):
|
||||||
# Casts dates into string format for entry into database.
|
# Casts dates into string format for entry into database.
|
||||||
if value is not None:
|
if value is not None:
|
||||||
# MySQL/Oracle will throw a warning if microseconds are given, because
|
# MySQL will throw a warning if microseconds are given, because it
|
||||||
# neither database supports microseconds.
|
# doesn't support microseconds.
|
||||||
if settings.DATABASE_ENGINE in ('mysql', 'oracle') and hasattr(value, 'microsecond'):
|
if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):
|
||||||
value = value.replace(microsecond=0)
|
value = value.replace(microsecond=0)
|
||||||
value = str(value)
|
value = str(value)
|
||||||
return Field.get_db_prep_save(self, value)
|
return Field.get_db_prep_save(self, value)
|
||||||
|
|
||||||
def get_db_prep_lookup(self, lookup_type, value):
|
def get_db_prep_lookup(self, lookup_type, value):
|
||||||
# Oracle will throw an error if microseconds are given, because it
|
|
||||||
# doesn't support microseconds.
|
|
||||||
if settings.DATABASE_ENGINE == 'oracle' and hasattr(value, 'microsecond'):
|
|
||||||
value = value.replace(microsecond=0)
|
|
||||||
if lookup_type == 'range':
|
if lookup_type == 'range':
|
||||||
value = [str(v) for v in value]
|
value = [str(v) for v in value]
|
||||||
else:
|
else:
|
||||||
@ -846,12 +842,13 @@ class TimeField(Field):
|
|||||||
if value is not None:
|
if value is not None:
|
||||||
# MySQL will throw a warning if microseconds are given, because it
|
# MySQL will throw a warning if microseconds are given, because it
|
||||||
# doesn't support microseconds.
|
# doesn't support microseconds.
|
||||||
if settings.DATABASE_ENGINE in ('mysql', 'oracle') and hasattr(value, 'microsecond'):
|
if settings.DATABASE_ENGINE == 'mysql' and hasattr(value, 'microsecond'):
|
||||||
value = value.replace(microsecond=0)
|
value = value.replace(microsecond=0)
|
||||||
if settings.DATABASE_ENGINE == 'oracle':
|
elif settings.DATABASE_ENGINE == 'oracle':
|
||||||
# cx_Oracle expects a datetime.datetime to persist into TIMESTAMP field.
|
# cx_Oracle expects a datetime.datetime to persist into TIMESTAMP field.
|
||||||
if isinstance(value, datetime.time):
|
if isinstance(value, datetime.time):
|
||||||
value = datetime.datetime(1900, 1, 1, value.hour, value.minute, value.second)
|
value = datetime.datetime(1900, 1, 1, value.hour, value.minute,
|
||||||
|
value.second, value.microsecond)
|
||||||
elif isinstance(value, basestring):
|
elif isinstance(value, basestring):
|
||||||
value = datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
|
value = datetime.datetime(*(time.strptime(value, '%H:%M:%S')[:6]))
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user