]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
When querying the information schema on SQL Server 2000, removed
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 Jun 2013 16:52:18 +0000 (12:52 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 6 Jun 2013 16:55:00 +0000 (12:55 -0400)
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]

Conflicts:
doc/build/changelog/changelog_09.rst
lib/sqlalchemy/dialects/mssql/information_schema.py

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/dialects/mssql/information_schema.py
test/dialect/test_mssql.py

index 82e65272b7bb690b31384b51eae7ef5a88ba8950..e3b14bc28e962c534cb238005de63fcce4c13977 100644 (file)
@@ -6,6 +6,15 @@
 .. changelog::
     :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
index 80e59d323e6fe16dc880e75a5118099b69a2cebd..030074fbe9da3b07c02f9194d11f868a5e5100b8 100644 (file)
@@ -9,10 +9,12 @@
 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
 
@@ -24,7 +26,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"),
index 7b8f533908fd066520ff034e60c1d41772432aa8..28dcd1dd4310a9b42027b73cbbcc71d25e29799b 100644 (file)
@@ -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, unicode)
 
+    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'