diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-19 11:35:32 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-03-19 11:35:32 -0400 |
| commit | bb45ff1dbb6f0ec88d54813ead64b3a1cdac9bf5 (patch) | |
| tree | 2b94b16f9a9f15b17171300c2a1553e6a5bae715 /lib/sqlalchemy/connectors | |
| parent | 5be0d3133bb3591ca31e2da0a01fb3d3038aa9f8 (diff) | |
| download | sqlalchemy-bb45ff1dbb6f0ec88d54813ead64b3a1cdac9bf5.tar.gz | |
- the string approach appears to be necessary for large numbers, however.
Don't know how to get large decimals through to Sybase.
Diffstat (limited to 'lib/sqlalchemy/connectors')
| -rw-r--r-- | lib/sqlalchemy/connectors/pyodbc.py | 64 |
1 files changed, 26 insertions, 38 deletions
diff --git a/lib/sqlalchemy/connectors/pyodbc.py b/lib/sqlalchemy/connectors/pyodbc.py index 5cfe4a192..82e510754 100644 --- a/lib/sqlalchemy/connectors/pyodbc.py +++ b/lib/sqlalchemy/connectors/pyodbc.py @@ -8,55 +8,43 @@ import decimal from sqlalchemy import processors, types as sqltypes class PyODBCNumeric(sqltypes.Numeric): - """Turns Decimals with adjusted() < -6 into floats.""" + """Turns Decimals with adjusted() < -6 into floats, > 7 into strings""" def bind_processor(self, dialect): super_process = super(PyODBCNumeric, self).bind_processor(dialect) def process(value): if self.asdecimal and \ - isinstance(value, decimal.Decimal) and \ - value.adjusted() < -6: - return processors.to_float(value) - elif super_process: + isinstance(value, decimal.Decimal): + + if value.adjusted() < -6: + return processors.to_float(value) + elif value.adjusted() > 7: + return self._large_dec_to_string(value) + + if super_process: return super_process(value) else: return value return process - # This method turns the adjusted into a string. - # not sure if this has advantages over the simple float - # approach above. -# def bind_processor(self, dialect): -# def process(value): -# if isinstance(value, decimal.Decimal): -# if value.adjusted() < 0: -# result = "%s0.%s%s" % ( -# (value < 0 and '-' or ''), -# '0' * (abs(value.adjusted()) - 1), -# "".join([str(nint) for nint in value._int])) -# -# else: -# if 'E' in str(value): -# result = "%s%s%s" % ( -# (value < 0 and '-' or ''), -# "".join([str(s) for s in value._int]), -# "0" * (value.adjusted() - (len(value._int)-1))) -# else: -# if (len(value._int) - 1) > value.adjusted(): -# result = "%s%s.%s" % ( -# (value < 0 and '-' or ''), -# "".join([str(s) for s in value._int][0:value.adjusted() + 1]), -# "".join([str(s) for s in value._int][value.adjusted() + 1:])) -# else: -# result = "%s%s" % ( -# (value < 0 and '-' or ''), -# "".join([str(s) for s in value._int][0:value.adjusted() + 1])) -# return result -# -# else: -# return value -# return process + def _large_dec_to_string(self, value): + if 'E' in str(value): + result = "%s%s%s" % ( + (value < 0 and '-' or ''), + "".join([str(s) for s in value._int]), + "0" * (value.adjusted() - (len(value._int)-1))) + else: + if (len(value._int) - 1) > value.adjusted(): + result = "%s%s.%s" % ( + (value < 0 and '-' or ''), + "".join([str(s) for s in value._int][0:value.adjusted() + 1]), + "".join([str(s) for s in value._int][value.adjusted() + 1:])) + else: + result = "%s%s" % ( + (value < 0 and '-' or ''), + "".join([str(s) for s in value._int][0:value.adjusted() + 1])) + return result class PyODBCConnector(Connector): driver='pyodbc' |
