summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy
diff options
context:
space:
mode:
authorBrad Allen <bradallen137@gmail.com>2010-03-16 16:53:21 -0600
committerBrad Allen <bradallen137@gmail.com>2010-03-16 16:53:21 -0600
commit79a40e0cdb4a320dc66069e8c51beecdc599ea9f (patch)
treec37dfac102db505bd3e88267ac2e53a5f40b48a0 /lib/sqlalchemy
parentf07393d0c40bf6eed391397a2350bff404059bbb (diff)
downloadsqlalchemy-79a40e0cdb4a320dc66069e8c51beecdc599ea9f.tar.gz
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
Diffstat (limited to 'lib/sqlalchemy')
-rw-r--r--lib/sqlalchemy/connectors/mxodbc.py50
-rw-r--r--lib/sqlalchemy/dialects/mssql/mxodbc.py8
2 files changed, 57 insertions, 1 deletions
diff --git a/lib/sqlalchemy/connectors/mxodbc.py b/lib/sqlalchemy/connectors/mxodbc.py
index 0ed8dc736..bae6c4549 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 bf14601b8..5ef73bf37 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)