1
0
mirror of https://github.com/django/django.git synced 2025-07-04 17:59:13 +00:00

boulder-oracle-sprint: Made Oracle return DecimalField values as decimal objects.

git-svn-id: http://code.djangoproject.com/svn/django/branches/boulder-oracle-sprint@5309 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Boulder Sprinters 2007-05-21 21:37:52 +00:00
parent 97ccb9304e
commit 12b5df62dd
2 changed files with 12 additions and 8 deletions

View File

@ -461,7 +461,7 @@ def get_query_set_class(DefaultQuerySet):
def resolve_columns(self, row, fields=()):
from django.db.models.fields import DateField, DateTimeField, \
TimeField, BooleanField, NullBooleanField
TimeField, BooleanField, NullBooleanField, DecimalField
values = []
for value, field in map(None, row, fields):
if isinstance(value, Database.LOB):
@ -475,6 +475,9 @@ def get_query_set_class(DefaultQuerySet):
# Convert 1 or 0 to True or False
elif value in (1, 0) and isinstance(field, (BooleanField, NullBooleanField)):
value = bool(value)
# Convert floats to decimals
elif value is not None and isinstance(field, DecimalField):
value = util.typecast_decimal(field.format_number(value))
# cx_Oracle always returns datetime.datetime objects for
# DATE and TIMESTAMP columns, but Django wants to see a
# python datetime.date, .time, or .datetime. We use the type

View File

@ -96,9 +96,9 @@ class Model(object):
def __init__(self, *args, **kwargs):
dispatcher.send(signal=signals.pre_init, sender=self.__class__, args=args, kwargs=kwargs)
# There is a rather weird disparity here; if kwargs, it's set, then args
# overrides it. It should be one or the other; don't duplicate the work
# overrides it. It should be one or the other; don't duplicate the work
# The reason for the kwargs check is that standard iterator passes in by
# args, and nstantiation for iteration is 33% faster.
args_len = len(args)
@ -122,10 +122,10 @@ class Model(object):
# Maintain compatibility with existing calls.
if isinstance(field.rel, ManyToOneRel):
kwargs.pop(field.attname, None)
# Now we're left with the unprocessed fields that *must* come from
# keywords, or default.
for field in fields_iter:
if kwargs:
if isinstance(field.rel, ManyToOneRel):
@ -147,7 +147,7 @@ class Model(object):
try:
val = getattr(rel_obj, field.rel.get_related_field().attname)
except AttributeError:
raise TypeError("Invalid value: %r should be a %s instance, not a %s" %
raise TypeError("Invalid value: %r should be a %s instance, not a %s" %
(field.name, field.rel.to, type(rel_obj)))
else:
val = kwargs.pop(field.attname, field.get_default())
@ -211,7 +211,8 @@ class Model(object):
if pk_set:
# Determine whether a record with the primary key already exists.
cursor.execute("SELECT COUNT(*) FROM %s WHERE %s=%%s" % \
(backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)), [pk_val])
(backend.quote_name(self._meta.db_table), backend.quote_name(self._meta.pk.column)),
self._meta.pk.get_db_prep_lookup('exact', pk_val))
# If it does already exist, do an UPDATE.
if cursor.fetchone()[0] > 0:
db_values = [f.get_db_prep_save(f.pre_save(self, False)) for f in non_pks]
@ -220,7 +221,7 @@ class Model(object):
(backend.quote_name(self._meta.db_table),
','.join(['%s=%%s' % backend.quote_name(f.column) for f in non_pks]),
backend.quote_name(self._meta.pk.column)),
db_values + [pk_val])
db_values + self._meta.pk.get_db_prep_lookup('exact', pk_val))
else:
record_exists = False
if not pk_set or not record_exists: