diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-06 12:52:18 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2013-06-06 12:52:18 -0400 |
commit | 555f30d64c23558a13bb95c2c10cb8556b5b21ae (patch) | |
tree | c4ff1b1cc9d181be987e2210020d7c39c274d35b | |
parent | 9a736a4c6e3a21a4d3682a0bd2b547ef0703a027 (diff) | |
download | sqlalchemy-555f30d64c23558a13bb95c2c10cb8556b5b21ae.tar.gz |
When querying the information schema on SQL Server 2000, removed
a CAST call that was added in 0.8.1 to help with driver issues,
which apparently is not compatible on 2000.
The CAST remains in place for SQL Server 2005 and greater.
[ticket:2747]
-rw-r--r-- | doc/build/changelog/changelog_08.rst | 9 | ||||
-rw-r--r-- | doc/build/changelog/changelog_09.rst | 10 | ||||
-rw-r--r-- | lib/sqlalchemy/dialects/mssql/information_schema.py | 17 | ||||
-rw-r--r-- | test/dialect/test_mssql.py | 26 |
4 files changed, 58 insertions, 4 deletions
diff --git a/doc/build/changelog/changelog_08.rst b/doc/build/changelog/changelog_08.rst index 82e65272b..e3b14bc28 100644 --- a/doc/build/changelog/changelog_08.rst +++ b/doc/build/changelog/changelog_08.rst @@ -7,6 +7,15 @@ :version: 0.8.2 .. change:: + :tags: bug, mssql + :tickets: 2747 + + When querying the information schema on SQL Server 2000, removed + a CAST call that was added in 0.8.1 to help with driver issues, + which apparently is not compatible on 2000. + The CAST remains in place for SQL Server 2005 and greater. + + .. change:: :tags: bug, mysql :tickets: 2721 diff --git a/doc/build/changelog/changelog_09.rst b/doc/build/changelog/changelog_09.rst index c5ee84a7b..1c27d7bf6 100644 --- a/doc/build/changelog/changelog_09.rst +++ b/doc/build/changelog/changelog_09.rst @@ -7,6 +7,16 @@ :version: 0.9.0 .. change:: + :tags: bug, mssql + :tickets: 2747 + + When querying the information schema on SQL Server 2000, removed + a CAST call that was added in 0.8.1 to help with driver issues, + which apparently is not compatible on 2000. + The CAST remains in place for SQL Server 2005 and greater. + Also in 0.8.2. + + .. change:: :tags: bug, mysql :tickets: 2721 diff --git a/lib/sqlalchemy/dialects/mssql/information_schema.py b/lib/sqlalchemy/dialects/mssql/information_schema.py index a7628f213..c0d5d9168 100644 --- a/lib/sqlalchemy/dialects/mssql/information_schema.py +++ b/lib/sqlalchemy/dialects/mssql/information_schema.py @@ -10,10 +10,11 @@ from ... import Table, MetaData, Column from ...types import String, Unicode, Integer, TypeDecorator from ... import cast from ... import util +from ...sql import expression +from ...ext.compiler import compiles ischema = MetaData() - class CoerceUnicode(TypeDecorator): impl = Unicode @@ -23,7 +24,19 @@ class CoerceUnicode(TypeDecorator): return value def bind_expression(self, bindvalue): - return cast(bindvalue, Unicode) + return _cast_on_2005(bindvalue) + +class _cast_on_2005(expression.ColumnElement): + def __init__(self, bindvalue): + self.bindvalue = bindvalue + +@compiles(_cast_on_2005) +def _compile(element, compiler, **kw): + from . import base + if compiler.dialect.server_version_info < base.MS_2005_VERSION: + return compiler.process(element.bindvalue, **kw) + else: + return compiler.process(cast(element.bindvalue, Unicode), **kw) schemata = Table("SCHEMATA", ischema, Column("CATALOG_NAME", CoerceUnicode, key="catalog_name"), diff --git a/test/dialect/test_mssql.py b/test/dialect/test_mssql.py index 4a99ef5f7..b2eb8609b 100644 --- a/test/dialect/test_mssql.py +++ b/test/dialect/test_mssql.py @@ -2078,14 +2078,36 @@ class BinaryTest(fixtures.TestBase, AssertsExecutionResults): fp.close() return stream -class InfoCoerceUnicodeTest(fixtures.TestBase): +from sqlalchemy.dialects.mssql.information_schema import CoerceUnicode, tables +from sqlalchemy.dialects.mssql import base + +class InfoCoerceUnicodeTest(fixtures.TestBase, AssertsCompiledSQL): def test_info_unicode_coercion(self): - from sqlalchemy.dialects.mssql.information_schema import CoerceUnicode dialect = mssql.dialect() value = CoerceUnicode().bind_processor(dialect)('a string') assert isinstance(value, util.text_type) + def test_info_unicode_cast_no_2000(self): + dialect = mssql.dialect() + dialect.server_version_info = base.MS_2000_VERSION + stmt = tables.c.table_name == 'somename' + self.assert_compile( + stmt, + "[TABLES_1].[TABLE_NAME] = :TABLE_NAME_1", + dialect=dialect + ) + + def test_info_unicode_cast(self): + dialect = mssql.dialect() + dialect.server_version_info = base.MS_2005_VERSION + stmt = tables.c.table_name == 'somename' + self.assert_compile( + stmt, + "[TABLES_1].[TABLE_NAME] = CAST(:TABLE_NAME_1 AS NVARCHAR(max))", + dialect=dialect + ) + class ReflectHugeViewTest(fixtures.TestBase): __only_on__ = 'mssql' |