Commits

Mike Bayer committed 0d5dd88 Merge

Merge branch 'master' into rel_0_9

Comments (0)

Files changed (5)

doc/build/changelog/changelog_08.rst

         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

lib/sqlalchemy/dialects/mssql/pyodbc.py

 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
 
     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:
                     [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
     colspecs = util.update_copy(
         MSDialect.colspecs,
         {
-            sqltypes.Numeric: _MSNumeric_pyodbc
+            sqltypes.Numeric: _MSNumeric_pyodbc,
+            sqltypes.Float: _MSFloat_pyodbc
         }
     )
 

lib/sqlalchemy/testing/requirements.py

         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() "
         "type such as TEXT or CLOB"""

lib/sqlalchemy/testing/suite/test_types.py

     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
                     ("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(
                 lambda: sys.version_info >= (3,),