From: Brad Allen Date: Tue, 16 Mar 2010 22:53:21 +0000 (-0600) Subject: Fixes to pass numeric tests; now by default, the mxodbc connector natively returns... X-Git-Tag: rel_0_6beta2~50 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=79a40e0cdb4a320dc66069e8c51beecdc599ea9f;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fixes to pass numeric tests; now by default, the mxodbc connector natively returns Python Decimal data types from columns of type SQL.NUMERIC or SQL.DECIMAL --- diff --git a/lib/sqlalchemy/connectors/mxodbc.py b/lib/sqlalchemy/connectors/mxodbc.py index 0ed8dc7364..bae6c4549a 100644 --- a/lib/sqlalchemy/connectors/mxodbc.py +++ b/lib/sqlalchemy/connectors/mxodbc.py @@ -14,11 +14,15 @@ For more info on mxODBC, see http://www.egenix.com/ import sys import re import warnings +from decimal import Decimal -from sqlalchemy.connectors import Connector from mx.ODBC import InterfaceError from mx.ODBC.Error import Warning as MxOdbcWarning +from sqlalchemy.connectors import Connector +from sqlalchemy import types as sqltypes +import sqlalchemy.processors as processors + class MxODBCConnector(Connector): driver='mxodbc' @@ -107,3 +111,47 @@ def error_handler(connection, cursor, errorclass, errorvalue): else: raise errorclass, errorvalue + +class MxNumeric(sqltypes.Numeric): + """ + Handle Numeric types between SQLAlchemy and mxODBC. + """ + def bind_processor(self, dialect): + """ + SQLAlchemy can accept a Python Decimal for bind + variables, so no special bind_processor is needed. + """ + return None + + def result_processor(self, dialect, coltype): + """ + For cases when a + """ + if self.asdecimal: + return None + else: + return processors.to_float + + +class MxFloat(sqltypes.Float): + """ + Handle Numeric types between SQLAlchemy and mxODBC. + """ + def bind_processor(self, dialect): + """ + SQLAlchemy can accept a Python Decimal for bind + variables, so no special bind_processor is needed. + """ + return None + + def result_processor(self, dialect, coltype): + """ + mxODBC returns Python float values for REAL, FLOAT, and + DOUBLE column types. + """ + if self.asdecimal: + return processors.to_decimal_processor_factory(Decimal) + else: + return None + + diff --git a/lib/sqlalchemy/dialects/mssql/mxodbc.py b/lib/sqlalchemy/dialects/mssql/mxodbc.py index bf14601b87..5ef73bf376 100644 --- a/lib/sqlalchemy/dialects/mssql/mxodbc.py +++ b/lib/sqlalchemy/dialects/mssql/mxodbc.py @@ -20,6 +20,14 @@ class MSExecutionContext_mxodbc(MSExecutionContext_pyodbc): class MSDialect_mxodbc(MxODBCConnector, MSDialect): execution_ctx_cls = MSExecutionContext_mxodbc + colspecs = util.update_copy( + MSDialect.colspecs, + { + sqltypes.Numeric : MxNumeric, + sqltypes.Float : MxFloat + }, + ) + def __init__(self, description_encoding='latin-1', **params): super(MSDialect_mxodbc, self).__init__(**params)