]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Use new mxODBC 3.3.4 varbinary null symbol
authorSheila Allen <sallen@zeomega.com>
Mon, 11 Apr 2016 19:29:03 +0000 (15:29 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Tue, 31 May 2016 15:03:34 +0000 (11:03 -0400)
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

doc/build/changelog/changelog_11.rst
lib/sqlalchemy/dialects/mssql/mxodbc.py
test/dialect/mssql/test_types.py

index cb42d61a4cbbe94c64d7b2ec2034aff2951bec4c..27513e5691d03341db13f433aa934af2a66a88b4 100644 (file)
 .. changelog::
     :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
index 5e20ed11b111ac8f01414a2e613df66bfb3fd20e..e968920bf521082a131daf644d8c889ac8914ee8 100644 (file)
@@ -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):
index 37c0e7060f7204789af8315dfd1d3660e922c943..f13e26c67ca5f9df9ac390c60d16bb17493c6c6a 100644 (file)
@@ -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,