From: Sheila Allen Date: Mon, 11 Apr 2016 19:29:03 +0000 (-0400) Subject: Use new mxODBC 3.3.4 varbinary null symbol X-Git-Tag: rel_1_1_0b1~35 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f55039e7f15efafacc3e8e0fbf0ba38fa612b09;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git 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 --- diff --git a/doc/build/changelog/changelog_11.rst b/doc/build/changelog/changelog_11.rst index cb42d61a4c..27513e5691 100644 --- a/doc/build/changelog/changelog_11.rst +++ b/doc/build/changelog/changelog_11.rst @@ -21,6 +21,14 @@ .. 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 diff --git a/lib/sqlalchemy/dialects/mssql/mxodbc.py b/lib/sqlalchemy/dialects/mssql/mxodbc.py index 5e20ed11b1..e968920bf5 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 37c0e7060f..f13e26c67c 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,