diff options
| author | zeeeeeb <5767468+zeeeeeb@users.noreply.github.com> | 2022-02-12 14:00:02 -0500 |
|---|---|---|
| committer | mike bayer <mike_mp@zzzcomputing.com> | 2022-02-25 00:51:32 +0000 |
| commit | b9d231869d7e39decabdec12478e359c4dcb95ee (patch) | |
| tree | c6d8ebecc9c73206816cb54211f28a6dd7180e76 /lib/sqlalchemy/testing | |
| parent | 0353a9db76db6a46fa63d99a1d05c5cac45ea460 (diff) | |
| download | sqlalchemy-b9d231869d7e39decabdec12478e359c4dcb95ee.tar.gz | |
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
Diffstat (limited to 'lib/sqlalchemy/testing')
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_reflection.py | 4 | ||||
| -rw-r--r-- | lib/sqlalchemy/testing/suite/test_types.py | 14 |
2 files changed, 9 insertions, 9 deletions
diff --git a/lib/sqlalchemy/testing/suite/test_reflection.py b/lib/sqlalchemy/testing/suite/test_reflection.py index 6f02d5557..fb12d23c8 100644 --- a/lib/sqlalchemy/testing/suite/test_reflection.py +++ b/lib/sqlalchemy/testing/suite/test_reflection.py @@ -344,7 +344,7 @@ class ComponentReflectionTest(fixtures.TablesTest): metadata, Column("user_id", sa.INT, primary_key=True), Column("test1", sa.CHAR(5), nullable=False), - Column("test2", sa.Float(5), nullable=False), + Column("test2", sa.Float(), nullable=False), Column( "parent_user_id", sa.Integer, @@ -361,7 +361,7 @@ class ComponentReflectionTest(fixtures.TablesTest): metadata, Column("user_id", sa.INT, primary_key=True), Column("test1", sa.CHAR(5), nullable=False), - Column("test2", sa.Float(5), nullable=False), + Column("test2", sa.Float(), nullable=False), schema=schema, test_needs_fk=True, ) diff --git a/lib/sqlalchemy/testing/suite/test_types.py b/lib/sqlalchemy/testing/suite/test_types.py index 94bab009a..0940eab9b 100644 --- a/lib/sqlalchemy/testing/suite/test_types.py +++ b/lib/sqlalchemy/testing/suite/test_types.py @@ -731,7 +731,7 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase): def test_render_literal_float(self, literal_round_trip): literal_round_trip( - Float(4), + Float(), [15.7563, decimal.Decimal("15.7563")], [15.7563], filter_=lambda n: n is not None and round(n, 5) or None, @@ -783,17 +783,17 @@ class NumericTest(_LiteralRoundTripFixture, fixtures.TestBase): @testing.requires.floats_to_four_decimals def test_float_as_decimal(self, do_numeric_test): do_numeric_test( - Float(precision=8, asdecimal=True), - [15.7563, decimal.Decimal("15.7563"), None], - [decimal.Decimal("15.7563"), None], + Float(asdecimal=True), + [15.756, decimal.Decimal("15.756"), None], + [decimal.Decimal("15.756"), None], filter_=lambda n: n is not None and round(n, 4) or None, ) def test_float_as_float(self, do_numeric_test): do_numeric_test( - Float(precision=8), - [15.7563, decimal.Decimal("15.7563")], - [15.7563], + Float(), + [15.756, decimal.Decimal("15.756")], + [15.756], filter_=lambda n: n is not None and round(n, 5) or None, ) |
