summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSheila Allen <sallen@zeomega.com>2016-04-11 15:29:03 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2016-05-31 11:03:34 -0400
commit3f55039e7f15efafacc3e8e0fbf0ba38fa612b09 (patch)
tree04161d60c983feae3438ce76609e0e2e25bdd568
parent513a045395b4cb5d8e1a9deb69bc9761d79eee37 (diff)
downloadsqlalchemy-3f55039e7f15efafacc3e8e0fbf0ba38fa612b09.tar.gz
Use new mxODBC 3.3.4 varbinary null symbol
Use new mxODBC 3.3.4 varbinary null symbol with VARBINARY data types when value is None(based on similar change to pyodbc). Fix a test to pass on mxODBC starting w 3.3.3 version Change-Id: Id703ecb51ebc5db149c81fef124f673433606c7f Pull-request: https://bitbucket.org/zzzeek/sqlalchemy/pull-requests/58
-rw-r--r--doc/build/changelog/changelog_11.rst8
-rw-r--r--lib/sqlalchemy/dialects/mssql/mxodbc.py27
-rw-r--r--test/dialect/mssql/test_types.py4
3 files changed, 38 insertions, 1 deletions
diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst
index cb42d61a4..27513e569 100644
--- a/doc/build/changelog/changelog_11.rst
+++ b/doc/build/changelog/changelog_11.rst
@@ -22,6 +22,14 @@
:version: 1.1.0b1
.. change::
+ :tags: bug, mssql
+ :pullreq: bitbucket:58
+
+ Adjustments to the mxODBC dialect to make use of the ``BinaryNull``
+ symbol when appropriate in conjunction with the ``VARBINARY``
+ data type. Pull request courtesy Sheila Allen.
+
+ .. change::
:tags: change, orm
:tickets: 3394
diff --git a/lib/sqlalchemy/dialects/mssql/mxodbc.py b/lib/sqlalchemy/dialects/mssql/mxodbc.py
index 5e20ed11b..e968920bf 100644
--- a/lib/sqlalchemy/dialects/mssql/mxodbc.py
+++ b/lib/sqlalchemy/dialects/mssql/mxodbc.py
@@ -48,6 +48,7 @@ from ...connectors.mxodbc import MxODBCConnector
from .pyodbc import MSExecutionContext_pyodbc, _MSNumeric_pyodbc
from .base import (MSDialect,
MSSQLStrictCompiler,
+ VARBINARY,
_MSDateTime, _MSDate, _MSTime)
@@ -76,6 +77,30 @@ class _MSTime_mxodbc(_MSTime):
return process
+class _VARBINARY_mxodbc(VARBINARY):
+
+ """
+ mxODBC Support for VARBINARY column types.
+
+ This handles the special case for null VARBINARY values,
+ which maps None values to the mx.ODBC.Manager.BinaryNull symbol.
+ """
+
+ def bind_processor(self, dialect):
+ if dialect.dbapi is None:
+ return None
+
+ DBAPIBinary = dialect.dbapi.Binary
+
+ def process(value):
+ if value is not None:
+ return DBAPIBinary(value)
+ else:
+ # should pull from mx.ODBC.Manager.BinaryNull
+ return dialect.dbapi.BinaryNull
+ return process
+
+
class MSExecutionContext_mxodbc(MSExecutionContext_pyodbc):
"""
The pyodbc execution context is useful for enabling
@@ -103,6 +128,8 @@ class MSDialect_mxodbc(MxODBCConnector, MSDialect):
sqltypes.DateTime: _MSDateTime,
sqltypes.Date: _MSDate_mxodbc,
sqltypes.Time: _MSTime_mxodbc,
+ VARBINARY: _VARBINARY_mxodbc,
+ sqltypes.LargeBinary: _VARBINARY_mxodbc,
}
def __init__(self, description_encoding=None, **params):
diff --git a/test/dialect/mssql/test_types.py b/test/dialect/mssql/test_types.py
index 37c0e7060..f13e26c67 100644
--- a/test/dialect/mssql/test_types.py
+++ b/test/dialect/mssql/test_types.py
@@ -442,7 +442,9 @@ class TypeRoundTripTest(
def teardown(self):
metadata.drop_all()
- @testing.fails_on_everything_except('mssql+pyodbc')
+ @testing.fails_on_everything_except(
+ 'mssql+pyodbc',
+ 'mssql+mxodbc')
def test_decimal_notation(self):
numeric_table = Table(
'numeric_table', metadata,