diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-11 17:44:46 -0500 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2010-12-11 17:44:46 -0500 |
| commit | c691b4cbdf7424964f49ac2fd05057514e5856a3 (patch) | |
| tree | a4d62e1d5c0e63c90fd1b5ce125928d7a86852c6 /lib/sqlalchemy/dialects/mssql/pyodbc.py | |
| parent | b88c54f95be3e3bc2e0923181d56862fa3fda9fa (diff) | |
| download | sqlalchemy-c691b4cbdf7424964f49ac2fd05057514e5856a3.tar.gz | |
- support for cdecimal
- add --with-cdecimal flag to tests, monkeypatches cdecimal in
- fix mssql/pyodbc.py to not use private '_int' accessor in decimal conversion
routines
- pyodbc version 2.1.8 is needed for cdecimal in any case as
previous versions also called '_int', 2.1.8 adds the same string
logic as our own dialect, so that logic is skipped for modern
pyodbc version
- make the imports for "Decimal" consistent across the whole lib. not sure
yet how we should be importing "Decimal" or what the best way forward
is that would allow a clean user-invoked swap of cdecimal; for now,
added docs suggesting a global monkeypatch - the two decimal libs
are not compatible with each other so any chance of mixing produces
serious issues. adding adapters to DBAPIs tedious and adds in-python
overhead. suggestions welcome on how we should be doing
Decimal/cdecimal.
Diffstat (limited to 'lib/sqlalchemy/dialects/mssql/pyodbc.py')
| -rw-r--r-- | lib/sqlalchemy/dialects/mssql/pyodbc.py | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/pyodbc.py b/lib/sqlalchemy/dialects/mssql/pyodbc.py index 5bba24514..93a516706 100644 --- a/lib/sqlalchemy/dialects/mssql/pyodbc.py +++ b/lib/sqlalchemy/dialects/mssql/pyodbc.py @@ -88,7 +88,12 @@ class _MSNumeric_pyodbc(sqltypes.Numeric): """ def bind_processor(self, dialect): - super_process = super(_MSNumeric_pyodbc, self).bind_processor(dialect) + + super_process = super(_MSNumeric_pyodbc, self).\ + bind_processor(dialect) + + if not dialect._need_decimal_fix: + return super_process def process(value): if self.asdecimal and \ @@ -106,31 +111,35 @@ class _MSNumeric_pyodbc(sqltypes.Numeric): return value return process + # these routines needed for older versions of pyodbc. + # as of 2.1.8 this logic is integrated. + def _small_dec_to_string(self, value): return "%s0.%s%s" % ( (value < 0 and '-' or ''), '0' * (abs(value.adjusted()) - 1), - "".join([str(nint) for nint in value._int])) + "".join([str(nint) for nint in value.as_tuple()[1]])) def _large_dec_to_string(self, value): + _int = value.as_tuple()[1] 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))) + "".join([str(s) for s in _int]), + "0" * (value.adjusted() - (len(_int)-1))) else: - if (len(value._int) - 1) > value.adjusted(): + if (len(_int) - 1) > value.adjusted(): result = "%s%s.%s" % ( (value < 0 and '-' or ''), "".join( - [str(s) for s in value._int][0:value.adjusted() + 1]), + [str(s) for s in _int][0:value.adjusted() + 1]), "".join( - [str(s) for s in value._int][value.adjusted() + 1:])) + [str(s) for s in _int][value.adjusted() + 1:])) else: result = "%s%s" % ( (value < 0 and '-' or ''), "".join( - [str(s) for s in value._int][0:value.adjusted() + 1])) + [str(s) for s in _int][0:value.adjusted() + 1])) return result @@ -200,5 +209,7 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect): self.description_encoding = description_encoding self.use_scope_identity = self.dbapi and \ hasattr(self.dbapi.Cursor, 'nextset') + self._need_decimal_fix = self.dbapi and \ + tuple(self.dbapi.version.split(".")) < (2, 1, 8) dialect = MSDialect_pyodbc |
