diff options
author | Michael Trier <mtrier@gmail.com> | 2009-01-17 20:57:18 +0000 |
---|---|---|
committer | Michael Trier <mtrier@gmail.com> | 2009-01-17 20:57:18 +0000 |
commit | 27c4e7aade7d98f909dfb362bead0e38528213eb (patch) | |
tree | 5e13d74ad05a52dc264cfe9a2c3f7a5aa216721d /lib/sqlalchemy/databases/mssql.py | |
parent | f5eca3933eb54c697fe6f9b9fb218a4d98f96c3f (diff) | |
download | sqlalchemy-27c4e7aade7d98f909dfb362bead0e38528213eb.tar.gz |
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
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" |