diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-02-26 17:50:34 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-02-26 17:50:34 +0000 |
commit | 2d95ef1f252b2752a3840e84a01d989af9921033 (patch) | |
tree | f7a9086dc5fed65ef4cc658a5c5d9742bcc58077 /lib/sqlalchemy/processors.py | |
parent | 11f996da20cf40692a21f6e836655cc36d1857d7 (diff) | |
download | sqlalchemy-2d95ef1f252b2752a3840e84a01d989af9921033.tar.gz |
- the "scale" argument of the Numeric() type is honored when
coercing a returned floating point value into a string
on its way to Decimal - this allows accuracy to function
on SQLite, MySQL. [ticket:1717]
Diffstat (limited to 'lib/sqlalchemy/processors.py')
-rw-r--r-- | lib/sqlalchemy/processors.py | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/lib/sqlalchemy/processors.py b/lib/sqlalchemy/processors.py index 4cf6831bd..04fa5054a 100644 --- a/lib/sqlalchemy/processors.py +++ b/lib/sqlalchemy/processors.py @@ -38,9 +38,10 @@ try: return UnicodeResultProcessor(encoding, errors).process else: return UnicodeResultProcessor(encoding).process - - def to_decimal_processor_factory(target_class): - return DecimalResultProcessor(target_class).process + + # TODO: add scale argument + #def to_decimal_processor_factory(target_class): + # return DecimalResultProcessor(target_class).process except ImportError: def to_unicode_processor_factory(encoding, errors=None): @@ -57,13 +58,14 @@ except ImportError: return decoder(value, errors)[0] return process - def to_decimal_processor_factory(target_class): - def process(value): - if value is None: - return None - else: - return target_class(str(value)) - return process + # TODO: add scale argument + #def to_decimal_processor_factory(target_class): + # def process(value): + # if value is None: + # return None + # else: + # return target_class(str(value)) + # return process def to_float(value): if value is None: @@ -92,3 +94,13 @@ except ImportError: str_to_time = str_to_datetime_processor_factory(TIME_RE, datetime.time) str_to_date = str_to_datetime_processor_factory(DATE_RE, datetime.date) + +def to_decimal_processor_factory(target_class, scale=10): + fstring = "%%.%df" % scale + + def process(value): + if value is None: + return None + else: + return target_class(fstring % value) + return process |