From b9d231869d7e39decabdec12478e359c4dcb95ee Mon Sep 17 00:00:00 2001 From: zeeeeeb <5767468+zeeeeeb@users.noreply.github.com> Date: Sat, 12 Feb 2022 14:00:02 -0500 Subject: Implement generic Double and related fixed types Added :class:`.Double`, :class:`.DOUBLE`, :class:`.DOUBLE_PRECISION` datatypes to the base ``sqlalchemy.`` module namespace, for explicit use of double/double precision as well as generic "double" datatypes. Use :class:`.Double` for generic support that will resolve to DOUBLE/DOUBLE PRECISION/FLOAT as needed for different backends. Implemented DDL and reflection support for ``FLOAT`` datatypes which include an explicit "binary_precision" value. Using the Oracle-specific :class:`_oracle.FLOAT` datatype, the new parameter :paramref:`_oracle.FLOAT.binary_precision` may be specified which will render Oracle's precision for floating point types directly. This value is interpreted during reflection. Upon reflecting back a ``FLOAT`` datatype, the datatype returned is one of :class:`_types.DOUBLE_PRECISION` for a ``FLOAT`` for a precision of 126 (this is also Oracle's default precision for ``FLOAT``), :class:`_types.REAL` for a precision of 63, and :class:`_oracle.FLOAT` for a custom precision, as per Oracle documentation. As part of this change, the generic :paramref:`_sqltypes.Float.precision` value is explicitly rejected when generating DDL for Oracle, as this precision cannot be accurately converted to "binary precision"; instead, an error message encourages the use of :meth:`_sqltypes.TypeEngine.with_variant` so that Oracle's specific form of precision may be chosen exactly. This is a backwards-incompatible change in behavior, as the previous "precision" value was silently ignored for Oracle. Fixes: #5465 Closes: #7674 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/7674 Pull-request-sha: 5c68419e5aee2e27bf21a8ac9eb5950d196c77e5 Change-Id: I831f4af3ee3b23fde02e8f6393c83e23dd7cd34d --- test/sql/test_types.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/sql') diff --git a/test/sql/test_types.py b/test/sql/test_types.py index f441c3b46..4e1048cb6 100644 --- a/test/sql/test_types.py +++ b/test/sql/test_types.py @@ -23,6 +23,7 @@ from sqlalchemy import DateTime from sqlalchemy import DECIMAL from sqlalchemy import dialects from sqlalchemy import distinct +from sqlalchemy import Double from sqlalchemy import Enum from sqlalchemy import exc from sqlalchemy import FLOAT @@ -277,6 +278,7 @@ class AdaptTest(fixtures.TestBase): eq_(types.Numeric(asdecimal=False).python_type, float) eq_(types.LargeBinary().python_type, bytes) eq_(types.Float().python_type, float) + eq_(types.Double().python_type, float) eq_(types.Interval().python_type, datetime.timedelta) eq_(types.Date().python_type, datetime.date) eq_(types.DateTime().python_type, datetime.datetime) @@ -3455,6 +3457,9 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL): dialects.postgresql.FLOAT(), "FLOAT", allow_dialect_select=True ) + def test_default_compile_double(self): + self.assert_compile(Double(), "DOUBLE") + def test_default_compile_mysql_integer(self): self.assert_compile( dialects.mysql.INTEGER(display_width=5), -- cgit v1.2.1