]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- apply a similar fix for floats to mssql+pyodbc as we did to firebird
authorMike Bayer <mike_mp@zzzcomputing.com>
Sat, 28 Dec 2013 22:50:19 +0000 (17:50 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sat, 28 Dec 2013 22:50:19 +0000 (17:50 -0500)
- wrangle through osx+pyodbc+freetds to get at least test_suite to pass again
with mssql+pyodbc. invovled adding some silly requirements

doc/build/changelog/changelog_08.rst
lib/sqlalchemy/dialects/mssql/pyodbc.py
lib/sqlalchemy/testing/requirements.py
lib/sqlalchemy/testing/suite/test_types.py
test/requirements.py

index 2e6bc153cb0a974b2d79fe55c7a32d519a320291..974949cffdc4d46b4f49ed60b463bec40cb3f292 100644 (file)
         in order of RDB$FIELD_POSITION.
 
     .. change::
-        :tags: bug, firebird
+        :tags: bug, mssql, firebird
         :versions: 0.9.0b2
 
         The "asdecimal" flag used with the :class:`.Float` type will now
-        work with Firebird dialects; previously the decimal conversion was
-        not occurring.
+        work with Firebird as well as the mssql+pyodbc dialects; previously the
+        decimal conversion was not occurring.
 
     .. change::
         :tags: bug, mssql, pymssql
index 5a359d1795f58bed8d3778a15ffa142ae7da2b31..036265cfb429ffd47cd51eb678cd1eda546fb01e 100644 (file)
@@ -116,8 +116,8 @@ from ...connectors.pyodbc import PyODBCConnector
 from ... import types as sqltypes, util
 import decimal
 
+class _ms_numeric_pyodbc(object):
 
-class _MSNumeric_pyodbc(sqltypes.Numeric):
     """Turns Decimals with adjusted() < 0 or > 7 into strings.
 
     The routines here are needed for older pyodbc versions
@@ -127,7 +127,7 @@ class _MSNumeric_pyodbc(sqltypes.Numeric):
 
     def bind_processor(self, dialect):
 
-        super_process = super(_MSNumeric_pyodbc, self).\
+        super_process = super(_ms_numeric_pyodbc, self).\
                         bind_processor(dialect)
 
         if not dialect._need_decimal_fix:
@@ -180,6 +180,11 @@ class _MSNumeric_pyodbc(sqltypes.Numeric):
                     [str(s) for s in _int][0:value.adjusted() + 1]))
         return result
 
+class _MSNumeric_pyodbc(_ms_numeric_pyodbc, sqltypes.Numeric):
+    pass
+
+class _MSFloat_pyodbc(_ms_numeric_pyodbc, sqltypes.Float):
+    pass
 
 class MSExecutionContext_pyodbc(MSExecutionContext):
     _embedded_scope_identity = False
@@ -238,7 +243,8 @@ class MSDialect_pyodbc(PyODBCConnector, MSDialect):
     colspecs = util.update_copy(
         MSDialect.colspecs,
         {
-            sqltypes.Numeric: _MSNumeric_pyodbc
+            sqltypes.Numeric: _MSNumeric_pyodbc,
+            sqltypes.Float: _MSFloat_pyodbc
         }
     )
 
index 3e48ba026eb8cb8ab81d1ed6c66e898dc3e358a1..60e966b3b886f820c0e920e5c10e78ca6b681f54 100644 (file)
@@ -424,6 +424,16 @@ class SuiteRequirements(Requirements):
         """
         return exclusions.open()
 
+    @property
+    def fetch_null_from_numeric(self):
+        """target backend doesn't crash when you try to select a NUMERIC
+        value that has a value of NULL.
+
+        Added to support Pyodbc bug #351.
+        """
+
+        return exclusions.open()
+
     @property
     def text_type(self):
         """Target database must support an unbounded Text() "
index b147f891a7dc8ae6e59bccee88954eba1c97d56e..a6e937e8e228141f3ddbd7f45d568c2fc0e1e6b5 100644 (file)
@@ -369,15 +369,31 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase):
     def test_numeric_as_decimal(self):
         self._do_test(
             Numeric(precision=8, scale=4),
-            [15.7563, decimal.Decimal("15.7563"), None],
-            [decimal.Decimal("15.7563"), None],
+            [15.7563, decimal.Decimal("15.7563")],
+            [decimal.Decimal("15.7563")],
         )
 
     def test_numeric_as_float(self):
         self._do_test(
             Numeric(precision=8, scale=4, asdecimal=False),
-            [15.7563, decimal.Decimal("15.7563"), None],
-            [15.7563, None],
+            [15.7563, decimal.Decimal("15.7563")],
+            [15.7563],
+        )
+
+    @testing.requires.fetch_null_from_numeric
+    def test_numeric_null_as_decimal(self):
+        self._do_test(
+            Numeric(precision=8, scale=4),
+            [None],
+            [None],
+        )
+
+    @testing.requires.fetch_null_from_numeric
+    def test_numeric_null_as_float(self):
+        self._do_test(
+            Numeric(precision=8, scale=4, asdecimal=False),
+            [None],
+            [None],
         )
 
     @testing.requires.floats_to_four_decimals
index b90591a802adc78091c2bbc95d517322cf1d6de2..d26eb86cbe4e8f0407fdaab2c3cb10f7350d5cae 100644 (file)
@@ -570,9 +570,19 @@ class DefaultRequirements(SuiteRequirements):
                     ("mysql+oursql", None, None, "Floating point error"),
                     ("firebird", None, None,
                         "Firebird still has FP inaccuracy even "
-                        "with only four decimal places")
+                        "with only four decimal places"),
+                    ('mssql+pyodbc', None, None,
+                                'mssql+pyodbc has FP inaccuracy even with '
+                                'only four decimal places '
+                            )
                 ])
 
+    @property
+    def fetch_null_from_numeric(self):
+        return skip_if(
+                    ("mssql+pyodbc", None, None, "crashes due to bug #351"),
+                )
+
     @property
     def python2(self):
         return skip_if(