diff options
Diffstat (limited to 'lib/sqlalchemy/databases/mssql.py')
-rw-r--r-- | lib/sqlalchemy/databases/mssql.py | 35 |
1 files changed, 10 insertions, 25 deletions
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" |