]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fixes to pass numeric tests; now by default, the mxodbc connector natively returns...
authorBrad Allen <bradallen137@gmail.com>
Tue, 16 Mar 2010 22:53:21 +0000 (16:53 -0600)
committerBrad Allen <bradallen137@gmail.com>
Tue, 16 Mar 2010 22:53:21 +0000 (16:53 -0600)
lib/sqlalchemy/connectors/mxodbc.py
lib/sqlalchemy/dialects/mssql/mxodbc.py

index 0ed8dc73641ccc792fd9d05a3c1913f63b3cfd9b..bae6c4549accb87a7a9013b8e6fd551a115d8214 100644 (file)
@@ -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
+
+        
index bf14601b871c68d454b941564290292e1ba5f81e..5ef73bf37697cdaaed084cd3b08d8d046e548600 100644 (file)
@@ -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)