Skip to content

Commit

Permalink
Merge branch '2.13.x' into merge/2.13.x
Browse files Browse the repository at this point in the history
* 2.13.x:
  Backport doc block fix
  Cast decimals to string on SQLite
  • Loading branch information
derrabus committed Sep 28, 2021
2 parents b19b22e + 5f6c6e6 commit 8bef5c2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Schema/AbstractAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function getShortestName($defaultNamespaceName)
}

/**
* The normalized name is full-qualified and lowerspaced. Lowerspacing is
* The normalized name is full-qualified and lower-cased. Lower-casing is
* actually wrong, but we have to do it to keep our sanity. If you are
* using database objects that only differentiate in the casing (FOO vs
* Foo) then you will NOT be able to use Doctrine Schema abstraction.
Expand Down
8 changes: 8 additions & 0 deletions src/Types/DecimalType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use Doctrine\DBAL\Platforms\AbstractPlatform;

use function is_float;

use const PHP_VERSION_ID;

/**
* Type that maps an SQL DECIMAL to a PHP string.
*/
Expand All @@ -30,6 +34,10 @@ public function getSQLDeclaration(array $column, AbstractPlatform $platform)
*/
public function convertToPHPValue($value, AbstractPlatform $platform)
{
if (PHP_VERSION_ID >= 80100 && is_float($value)) {
return (string) $value;
}

return $value;
}
}
35 changes: 35 additions & 0 deletions tests/Functional/Types/DecimalTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tests\Functional\Types;

use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;

final class DecimalTest extends FunctionalTestCase
{
public function testInsertAndRetrieveDecimal(): void
{
$table = new Table('decimal_table');
$table->addColumn('val', Types::DECIMAL, ['precision' => 4, 'scale' => 2]);

$sm = $this->connection->getSchemaManager();
$sm->dropAndCreateTable($table);

$this->connection->insert(
'decimal_table',
['val' => '13.37'],
['val' => Types::DECIMAL]
);

$value = Type::getType(Types::DECIMAL)->convertToPHPValue(
$this->connection->fetchOne('SELECT val FROM decimal_table'),
$this->connection->getDatabasePlatform()
);

self::assertSame('13.37', $value);
}
}

0 comments on commit 8bef5c2

Please sign in to comment.