diff --git a/docs/en/reference/types.rst b/docs/en/reference/types.rst index 841e9675fe6..af3633dc6ac 100644 --- a/docs/en/reference/types.rst +++ b/docs/en/reference/types.rst @@ -125,7 +125,7 @@ or ``null`` if no data is present. it approximates precision which can lead to false assumptions in applications. -real +smallfloat +++++ Maps and converts single precision floating-point values. @@ -580,7 +580,7 @@ Please also notice the mapping specific footnotes for additional information. | | +--------------------------+ | | | | | **SQLite** | | | +-------------------+---------------+--------------------------+---------+----------------------------------------------------------+ - | **real** | ``float`` | **MySQL** | *all* | ``FLOAT`` ``UNSIGNED`` [10] | + | **smallfloat** | ``float`` | **MySQL** | *all* | ``FLOAT`` ``UNSIGNED`` [10] | | | +--------------------------+---------+----------------------------------------------------------+ | | | **PostgreSQL** | *all* | ``REAL`` | | | +--------------------------+ | | diff --git a/src/Platforms/AbstractMySQLPlatform.php b/src/Platforms/AbstractMySQLPlatform.php index e4cb6ca1e01..e94fbaefd07 100644 --- a/src/Platforms/AbstractMySQLPlatform.php +++ b/src/Platforms/AbstractMySQLPlatform.php @@ -649,7 +649,7 @@ public function getFloatDeclarationSQL(array $column): string /** * {@inheritDoc} */ - public function getRealFloatDeclarationSQL(array $column): string + public function getSmallFloatDeclarationSQL(array $column): string { return 'FLOAT' . $this->getUnsignedDeclaration($column); } @@ -735,7 +735,7 @@ protected function initializeDoctrineTypeMappings(): void 'datetime' => Types::DATETIME_MUTABLE, 'decimal' => Types::DECIMAL, 'double' => Types::FLOAT, - 'float' => Types::REAL, + 'float' => Types::SMALLFLOAT, 'int' => Types::INTEGER, 'integer' => Types::INTEGER, 'json' => Types::JSON, diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 9731fbf8e0e..31b3c102762 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -1878,7 +1878,7 @@ public function getFloatDeclarationSQL(array $column): string } /** @param mixed[] $column */ - public function getRealFloatDeclarationSQL(array $column): string + public function getSmallFloatDeclarationSQL(array $column): string { return 'REAL'; } diff --git a/src/Platforms/DB2Platform.php b/src/Platforms/DB2Platform.php index 6d89fe593c0..1167620dab8 100644 --- a/src/Platforms/DB2Platform.php +++ b/src/Platforms/DB2Platform.php @@ -52,7 +52,7 @@ protected function initializeDoctrineTypeMappings(): void 'decimal' => Types::DECIMAL, 'double' => Types::FLOAT, 'integer' => Types::INTEGER, - 'real' => Types::REAL, + 'real' => Types::SMALLFLOAT, 'smallint' => Types::SMALLINT, 'time' => Types::TIME_MUTABLE, 'timestamp' => Types::DATETIME_MUTABLE, diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index fb891a76612..2e123feabf2 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -750,7 +750,7 @@ protected function initializeDoctrineTypeMappings(): void 'nvarchar2' => Types::STRING, 'pls_integer' => Types::BOOLEAN, 'raw' => Types::BINARY, - 'real' => Types::REAL, + 'real' => Types::SMALLFLOAT, 'rowid' => Types::STRING, 'timestamp' => Types::DATETIME_MUTABLE, 'timestamptz' => Types::DATETIMETZ_MUTABLE, diff --git a/src/Platforms/PostgreSQLPlatform.php b/src/Platforms/PostgreSQLPlatform.php index 27cea0a6958..329a2b1a53a 100644 --- a/src/Platforms/PostgreSQLPlatform.php +++ b/src/Platforms/PostgreSQLPlatform.php @@ -701,7 +701,7 @@ protected function initializeDoctrineTypeMappings(): void 'double' => Types::FLOAT, 'double precision' => Types::FLOAT, 'float' => Types::FLOAT, - 'float4' => Types::REAL, + 'float4' => Types::SMALLFLOAT, 'float8' => Types::FLOAT, 'inet' => Types::STRING, 'int' => Types::INTEGER, @@ -717,7 +717,7 @@ protected function initializeDoctrineTypeMappings(): void 'serial' => Types::INTEGER, 'serial4' => Types::INTEGER, 'serial8' => Types::BIGINT, - 'real' => Types::REAL, + 'real' => Types::SMALLFLOAT, 'smallint' => Types::SMALLINT, 'text' => Types::TEXT, 'time' => Types::TIME_MUTABLE, diff --git a/src/Platforms/SQLServerPlatform.php b/src/Platforms/SQLServerPlatform.php index d74597ca67e..c1fcb8fcb98 100644 --- a/src/Platforms/SQLServerPlatform.php +++ b/src/Platforms/SQLServerPlatform.php @@ -1057,7 +1057,7 @@ protected function initializeDoctrineTypeMappings(): void 'ntext' => Types::TEXT, 'numeric' => Types::DECIMAL, 'nvarchar' => Types::STRING, - 'real' => Types::REAL, + 'real' => Types::SMALLFLOAT, 'smalldatetime' => Types::DATETIME_MUTABLE, 'smallint' => Types::SMALLINT, 'smallmoney' => Types::INTEGER, diff --git a/src/Platforms/SQLitePlatform.php b/src/Platforms/SQLitePlatform.php index b7b1b11a550..aec916f10d5 100644 --- a/src/Platforms/SQLitePlatform.php +++ b/src/Platforms/SQLitePlatform.php @@ -459,7 +459,7 @@ protected function initializeDoctrineTypeMappings(): void 'ntext' => 'string', 'numeric' => 'decimal', 'nvarchar' => 'string', - 'real' => 'real', + 'real' => 'smallfloat', 'serial' => 'integer', 'smallint' => 'smallint', 'string' => 'string', diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index 420596b08a5..3de6892c81c 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -152,7 +152,7 @@ protected function _getPortableTableColumnDefinition(array $tableColumn): Column case 'float': if ($precision === 63) { - $type = 'real'; + $type = 'smallfloat'; } break; diff --git a/src/Types/RealFloatType.php b/src/Types/SmallFloatType.php similarity index 83% rename from src/Types/RealFloatType.php rename to src/Types/SmallFloatType.php index 9c661860c82..431ddb2870e 100644 --- a/src/Types/RealFloatType.php +++ b/src/Types/SmallFloatType.php @@ -6,14 +6,14 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; -final class RealFloatType extends Type +class SmallFloatType extends Type { /** * {@inheritDoc} */ public function getSQLDeclaration(array $column, AbstractPlatform $platform): string { - return $platform->getRealFloatDeclarationSQL($column); + return $platform->getSmallFloatDeclarationSQL($column); } /** diff --git a/src/Types/Type.php b/src/Types/Type.php index 15192ddefd3..bc4d3aaf417 100644 --- a/src/Types/Type.php +++ b/src/Types/Type.php @@ -38,8 +38,8 @@ abstract class Type Types::GUID => GuidType::class, Types::INTEGER => IntegerType::class, Types::JSON => JsonType::class, - Types::REAL => RealFloatType::class, Types::SIMPLE_ARRAY => SimpleArrayType::class, + Types::SMALLFLOAT => SmallFloatType::class, Types::SMALLINT => SmallIntType::class, Types::STRING => StringType::class, Types::TEXT => TextType::class, diff --git a/src/Types/Types.php b/src/Types/Types.php index 049bf7624d7..6fef4cfce08 100644 --- a/src/Types/Types.php +++ b/src/Types/Types.php @@ -26,8 +26,8 @@ final class Types public const GUID = 'guid'; public const INTEGER = 'integer'; public const JSON = 'json'; - public const REAL = 'real'; public const SIMPLE_ARRAY = 'simple_array'; + public const SMALLFLOAT = 'smallfloat'; public const SMALLINT = 'smallint'; public const STRING = 'string'; public const TEXT = 'text'; diff --git a/tests/Functional/Driver/PgSQL/ResultTest.php b/tests/Functional/Driver/PgSQL/ResultTest.php index 6212cfd0507..a61ab026400 100644 --- a/tests/Functional/Driver/PgSQL/ResultTest.php +++ b/tests/Functional/Driver/PgSQL/ResultTest.php @@ -144,9 +144,9 @@ public static function typedValueProvider(): Generator yield 'boolean true' => ['BOOLEAN', true, Types::BOOLEAN]; yield 'boolean false' => ['BOOLEAN', false, Types::BOOLEAN]; yield 'float' => ['DOUBLE PRECISION', 47.11, Types::FLOAT]; - yield 'real' => ['REAL', 47.11, Types::REAL]; + yield 'real' => ['REAL', 47.11, Types::SMALLFLOAT]; yield 'negative float with exponent' => ['DOUBLE PRECISION', -8.15e10, Types::FLOAT]; - yield 'negative real with exponent' => ['REAL', -8.15e5, Types::REAL]; + yield 'negative real with exponent' => ['REAL', -8.15e5, Types::SMALLFLOAT]; yield 'double' => ['DOUBLE PRECISION', 47.11, Types::FLOAT]; yield 'decimal' => ['NUMERIC (6, 2)', '47.11', Types::DECIMAL]; yield 'binary' => ['BYTEA', chr(0x8b), Types::BINARY]; diff --git a/tests/Functional/Schema/MySQLSchemaManagerTest.php b/tests/Functional/Schema/MySQLSchemaManagerTest.php index df041485bb3..852eb555423 100644 --- a/tests/Functional/Schema/MySQLSchemaManagerTest.php +++ b/tests/Functional/Schema/MySQLSchemaManagerTest.php @@ -17,7 +17,7 @@ use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\FloatType; use Doctrine\DBAL\Types\JsonType; -use Doctrine\DBAL\Types\RealFloatType; +use Doctrine\DBAL\Types\SmallFloatType; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; @@ -378,16 +378,16 @@ public function testListUnsignedFloatTypeColumns(): void $table = new Table($tableName); $table->addColumn('col_unsigned', Types::FLOAT, ['unsigned' => true]); - $table->addColumn('col_real_unsigned', Types::REAL, ['unsigned' => true]); + $table->addColumn('col_smallfloat_unsigned', Types::SMALLFLOAT, ['unsigned' => true]); $this->dropAndCreateTable($table); $columns = $this->schemaManager->listTableColumns($tableName); self::assertInstanceOf(FloatType::class, $columns['col_unsigned']->getType()); - self::assertInstanceOf(RealFloatType::class, $columns['col_real_unsigned']->getType()); + self::assertInstanceOf(SmallFloatType::class, $columns['col_smallfloat_unsigned']->getType()); self::assertTrue($columns['col_unsigned']->getUnsigned()); - self::assertTrue($columns['col_real_unsigned']->getUnsigned()); + self::assertTrue($columns['col_smallfloat_unsigned']->getUnsigned()); } public function testJsonColumnType(): void diff --git a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php index e7a93e26dd9..3cf2ee70708 100644 --- a/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php +++ b/tests/Functional/Schema/PostgreSQLSchemaManagerTest.php @@ -415,7 +415,7 @@ public function testListNegativeColumnDefaultValue(): void $table->addColumn('col_integer', Types::INTEGER, ['default' => -1]); $table->addColumn('col_bigint', Types::BIGINT, ['default' => -1]); $table->addColumn('col_float', Types::FLOAT, ['default' => -1.1]); - $table->addColumn('col_real', Types::REAL, ['default' => -1.1]); + $table->addColumn('col_smallfloat', Types::SMALLFLOAT, ['default' => -1.1]); $table->addColumn('col_decimal', Types::DECIMAL, [ 'precision' => 2, 'scale' => 1, @@ -431,7 +431,7 @@ public function testListNegativeColumnDefaultValue(): void self::assertEquals(-1, $columns['col_integer']->getDefault()); self::assertEquals(-1, $columns['col_bigint']->getDefault()); self::assertEquals(-1.1, $columns['col_float']->getDefault()); - self::assertEquals(-1.1, $columns['col_real']->getDefault()); + self::assertEquals(-1.1, $columns['col_smallfloat']->getDefault()); self::assertEquals(-1.1, $columns['col_decimal']->getDefault()); self::assertEquals('(-1)', $columns['col_string']->getDefault()); } diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index 38d616c46ac..7ca35dee0d4 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -29,7 +29,7 @@ use Doctrine\DBAL\Types\DecimalType; use Doctrine\DBAL\Types\FloatType; use Doctrine\DBAL\Types\IntegerType; -use Doctrine\DBAL\Types\RealFloatType; +use Doctrine\DBAL\Types\SmallFloatType; use Doctrine\DBAL\Types\StringType; use Doctrine\DBAL\Types\TextType; use Doctrine\DBAL\Types\TimeType; @@ -867,16 +867,16 @@ public function testListTableFloatTypeColumns(): void $table = new Table($tableName); $table->addColumn('col_float', Types::FLOAT); - $table->addColumn('col_real_float', Types::REAL); + $table->addColumn('col_smallfloat', Types::SMALLFLOAT); $this->dropAndCreateTable($table); $columns = $this->schemaManager->listTableColumns($tableName); self::assertInstanceOf(FloatType::class, $columns['col_float']->getType()); - self::assertInstanceOf(RealFloatType::class, $columns['col_real_float']->getType()); + self::assertInstanceOf(SmallFloatType::class, $columns['col_smallfloat']->getType()); self::assertFalse($columns['col_float']->getUnsigned()); - self::assertFalse($columns['col_real_float']->getUnsigned()); + self::assertFalse($columns['col_smallfloat']->getUnsigned()); } /** @param mixed[] $data */ diff --git a/tests/Functional/TypeConversionTest.php b/tests/Functional/TypeConversionTest.php index ec92ac1612c..7a577faee92 100644 --- a/tests/Functional/TypeConversionTest.php +++ b/tests/Functional/TypeConversionTest.php @@ -36,7 +36,7 @@ protected function setUp(): void $table->addColumn('test_text', Types::TEXT, ['notnull' => false]); $table->addColumn('test_json', Types::JSON, ['notnull' => false]); $table->addColumn('test_float', Types::FLOAT, ['notnull' => false]); - $table->addColumn('test_real', Types::REAL, ['notnull' => false]); + $table->addColumn('test_smallfloat', Types::SMALLFLOAT, ['notnull' => false]); $table->addColumn('test_decimal', Types::DECIMAL, ['notnull' => false, 'scale' => 2, 'precision' => 10]); $table->setPrimaryKey(['id']); @@ -92,23 +92,7 @@ public static function floatProvider(): iterable { return [ 'float' => [Types::FLOAT, 1.5], - ]; - } - - #[DataProvider('realFloatProvider')] - public function testIdempotentConversionToRealFloat(string $type, mixed $originalValue): void - { - $dbValue = $this->processValue($type, $originalValue); - - self::assertIsFloat($dbValue); - self::assertEquals($originalValue, $dbValue); - } - - /** @return mixed[][] */ - public static function realFloatProvider(): iterable - { - return [ - 'real' => [Types::REAL, 1.5], + 'smallfloat' => [Types::SMALLFLOAT, 1.5], ]; } diff --git a/tests/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Platforms/AbstractMySQLPlatformTestCase.php index 5935e9d4803..684af042256 100644 --- a/tests/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Platforms/AbstractMySQLPlatformTestCase.php @@ -624,7 +624,7 @@ public static function getGeneratesFloatDeclarationSQL(): iterable /** * {@inheritDoc} */ - public static function getGeneratesRealFloatDeclarationSQL(): iterable + public static function getGeneratesSmallFloatDeclarationSQL(): iterable { return [ [[], 'FLOAT'], diff --git a/tests/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index b4711df28b5..a2ce07aebb9 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -979,14 +979,14 @@ public static function getGeneratesFloatDeclarationSQL(): iterable } /** @param mixed[] $column */ - #[DataProvider('getGeneratesRealFloatDeclarationSQL')] - public function testGeneratesRealFloatDeclarationSQL(array $column, string $expectedSql): void + #[DataProvider('getGeneratesSmallFloatDeclarationSQL')] + public function testGeneratesSmallFloatDeclarationSQL(array $column, string $expectedSql): void { - self::assertSame($expectedSql, $this->platform->getRealFloatDeclarationSQL($column)); + self::assertSame($expectedSql, $this->platform->getSmallFloatDeclarationSQL($column)); } /** @return mixed[][] */ - public static function getGeneratesRealFloatDeclarationSQL(): iterable + public static function getGeneratesSmallFloatDeclarationSQL(): iterable { return [ [[], 'REAL'], diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index 4accbcb2068..dfb5b85036b 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -322,7 +322,7 @@ public function testInitializesDoctrineTypeMappings(): void self::assertSame(Types::DATE_MUTABLE, $this->platform->getDoctrineTypeMapping('date')); self::assertTrue($this->platform->hasDoctrineTypeMappingFor('real')); - self::assertSame(Types::REAL, $this->platform->getDoctrineTypeMapping('real')); + self::assertSame(Types::SMALLFLOAT, $this->platform->getDoctrineTypeMapping('real')); } public function testGetVariableLengthStringTypeDeclarationSQLNoLength(): void diff --git a/tests/Platforms/SQLServerPlatformTest.php b/tests/Platforms/SQLServerPlatformTest.php index a555e71c962..4c1e25f2f25 100644 --- a/tests/Platforms/SQLServerPlatformTest.php +++ b/tests/Platforms/SQLServerPlatformTest.php @@ -732,7 +732,7 @@ public function testInitializesDoctrineTypeMappings(): void self::assertSame(Types::FLOAT, $this->platform->getDoctrineTypeMapping('float')); self::assertTrue($this->platform->hasDoctrineTypeMappingFor('real')); - self::assertSame(Types::REAL, $this->platform->getDoctrineTypeMapping('real')); + self::assertSame(Types::SMALLFLOAT, $this->platform->getDoctrineTypeMapping('real')); self::assertTrue($this->platform->hasDoctrineTypeMappingFor('double')); self::assertSame(Types::FLOAT, $this->platform->getDoctrineTypeMapping('double')); diff --git a/tests/Types/RealFloatTest.php b/tests/Types/SmallFloatTest.php similarity index 86% rename from tests/Types/RealFloatTest.php rename to tests/Types/SmallFloatTest.php index 3013a0d9f3c..0e126b2e9f2 100644 --- a/tests/Types/RealFloatTest.php +++ b/tests/Types/SmallFloatTest.php @@ -5,19 +5,19 @@ namespace Doctrine\DBAL\Tests\Types; use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Types\RealFloatType; +use Doctrine\DBAL\Types\SmallFloatType; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class RealFloatTest extends TestCase +class SmallFloatTest extends TestCase { private AbstractPlatform&MockObject $platform; - private RealFloatType $type; + private SmallFloatType $type; protected function setUp(): void { $this->platform = $this->createMock(AbstractPlatform::class); - $this->type = new RealFloatType(); + $this->type = new SmallFloatType(); } public function testFloatConvertsToPHPValue(): void