From 27c4e7aade7d98f909dfb362bead0e38528213eb Mon Sep 17 00:00:00 2001 From: Michael Trier Date: Sat, 17 Jan 2009 20:57:18 +0000 Subject: Corrected handling of large decimal values on mssql. Added more robust tests. - Removed string manipulation on floats. Float types are now passed through to mssql as is. - Fixes #1280 --- lib/sqlalchemy/databases/mssql.py | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) (limited to 'lib/sqlalchemy') diff --git a/lib/sqlalchemy/databases/mssql.py b/lib/sqlalchemy/databases/mssql.py index 7d23c5b27..24296c329 100644 --- a/lib/sqlalchemy/databases/mssql.py +++ b/lib/sqlalchemy/databases/mssql.py @@ -332,16 +332,17 @@ class MSNumeric(sqltypes.Numeric): # Not sure that this exception is needed return value else: - # FIXME: this will not correct a situation where a float - # gets converted to e-notation. - if isinstance(value, decimal.Decimal) and value._exp < -6: - value = ((value < 0 and '-' or '') - + '0.' - + '0' * -(value._exp+1) - + value._int) - return value + if isinstance(value, decimal.Decimal): + sign = (value < 0 and '-' or '') + if value._exp > -1: + return float(sign + value._int + '0' * value._exp) + else: + s = value._int.zfill(-value._exp+1) + pos = len(s) + value._exp + return sign + s[:pos] + '.' + s[pos:] else: - return str(value) + return value + return process def get_col_spec(self): @@ -358,14 +359,6 @@ class MSFloat(sqltypes.Float): else: return "FLOAT(%(precision)s)" % {'precision': self.precision} - def bind_processor(self, dialect): - def process(value): - """By converting to string, we can use Decimal types round-trip.""" - if not value is None: - return str(value) - return None - return process - class MSReal(MSFloat): """A type for ``real`` numbers.""" @@ -380,14 +373,6 @@ class MSReal(MSFloat): def adapt(self, impltype): return impltype() - def bind_processor(self, dialect): - def process(value): - if value is not None: - return float(value) - else: - return value - return process - def get_col_spec(self): return "REAL" -- cgit v1.2.1