From 6aabdec97b5fe0f8c6f80306afb690715b80b162 Mon Sep 17 00:00:00 2001 From: Michael Moravec Date: Wed, 14 Feb 2018 17:22:57 +0100 Subject: [PATCH] Fix compatibility with DBAL develop * ResultStatement signature BC break * PDO::FETCH_* -> FetchMode::* * PDO::PARAM_* -> ParameterType::* * AbstractPlatform::DATE_INTERVAL_UNIT_* -> DateIntervalUnit::* * AbstractPlatform::TRIM_* -> TrimMode::* --- docs/en/reference/dql-doctrine-query-language.rst | 3 ++- docs/en/reference/query-builder.rst | 4 ++-- .../ORM/Internal/Hydration/AbstractHydrator.php | 4 ++-- .../ORM/Internal/Hydration/ArrayHydrator.php | 4 ++-- .../ORM/Internal/Hydration/ObjectHydrator.php | 4 ++-- .../ORM/Internal/Hydration/ScalarHydrator.php | 4 +++- .../ORM/Internal/Hydration/SimpleObjectHydrator.php | 4 ++-- .../ORM/Internal/Hydration/SingleScalarHydrator.php | 3 ++- .../ORM/Query/AST/Functions/TrimFunction.php | 10 +++++----- lib/Doctrine/ORM/Query/ParameterTypeInferer.php | 3 ++- lib/Doctrine/ORM/QueryBuilder.php | 2 +- tests/Doctrine/Tests/Mocks/DriverConnectionMock.php | 3 ++- .../Tests/ORM/Functional/Ticket/DDC1225Test.php | 12 +++++------- .../Tests/ORM/Functional/Ticket/DDC1250Test.php | 11 ++++------- .../Tests/ORM/Hydration/CustomHydratorTest.php | 4 ++-- .../Tests/ORM/Query/ParameterTypeInfererTest.php | 6 +++--- tests/Doctrine/Tests/ORM/Query/QueryTest.php | 5 +++-- 17 files changed, 44 insertions(+), 42 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 10561ff8e88..f6f0f1bd762 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -1228,13 +1228,14 @@ creating a class which extends ``AbstractHydrator``: stmt->fetchAll(PDO::FETCH_ASSOC); + return $this->stmt->fetchAll(FetchMode::Associative); } } diff --git a/docs/en/reference/query-builder.rst b/docs/en/reference/query-builder.rst index 8047ebf701a..d7c85ad45b2 100644 --- a/docs/en/reference/query-builder.rst +++ b/docs/en/reference/query-builder.rst @@ -244,8 +244,8 @@ while the named placeholders start with a : followed by a string. Calling ``setParameter()`` automatically infers which type you are setting as value. This works for integers, arrays of strings/integers, DateTime instances and for managed entities. If you want to set a type explicitly you can call -the third argument to ``setParameter()`` explicitly. It accepts either a PDO -type or a DBAL Type name for conversion. +the third argument to ``setParameter()`` explicitly. It accepts either a DBAL +Doctrine\DBAL\ParameterType::* or a DBAL Type name for conversion. If you've got several parameters to bind to your query, you can also use setParameters() instead of setParameter() with the diff --git a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php index 018095a9141..76740834f70 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php @@ -5,13 +5,13 @@ namespace Doctrine\ORM\Internal\Hydration; use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Events; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Query\ResultSetMapping; use Doctrine\ORM\UnitOfWork; -use PDO; use function array_merge; /** @@ -146,7 +146,7 @@ public function hydrateAll($stmt, $resultSetMapping, array $hints = []) */ public function hydrateRow() { - $row = $this->stmt->fetch(PDO::FETCH_ASSOC); + $row = $this->stmt->fetch(FetchMode::ASSOCIATIVE); if (! $row) { $this->cleanup(); diff --git a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php index 462a1145076..fbce06e3451 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php @@ -4,8 +4,8 @@ namespace Doctrine\ORM\Internal\Hydration; +use Doctrine\DBAL\FetchMode; use Doctrine\ORM\Mapping\ToOneAssociationMetadata; -use PDO; use function count; use function end; use function is_array; @@ -72,7 +72,7 @@ protected function hydrateAllData() { $result = []; - while ($data = $this->stmt->fetch(PDO::FETCH_ASSOC)) { + while ($data = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) { $this->hydrateRowData($data, $result); } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php index 76a2e23e5fc..8e5b789702f 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php @@ -5,6 +5,7 @@ namespace Doctrine\ORM\Internal\Hydration; use Doctrine\Common\Collections\Collection; +use Doctrine\DBAL\FetchMode; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\ManyToManyAssociationMetadata; use Doctrine\ORM\Mapping\ToManyAssociationMetadata; @@ -12,7 +13,6 @@ use Doctrine\ORM\PersistentCollection; use Doctrine\ORM\Query; use Doctrine\ORM\UnitOfWork; -use PDO; use ProxyManager\Proxy\GhostObjectInterface; use function array_fill_keys; use function array_keys; @@ -146,7 +146,7 @@ protected function hydrateAllData() { $result = []; - while ($row = $this->stmt->fetch(PDO::FETCH_ASSOC)) { + while ($row = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) { $this->hydrateRowData($row, $result); } diff --git a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php index ef85e0ad32f..ed0c6e9bb72 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php @@ -4,6 +4,8 @@ namespace Doctrine\ORM\Internal\Hydration; +use Doctrine\DBAL\FetchMode; + /** * Hydrator that produces flat, rectangular results of scalar data. * The created result is almost the same as a regular SQL result set, except @@ -18,7 +20,7 @@ protected function hydrateAllData() { $result = []; - while ($data = $this->stmt->fetch(\PDO::FETCH_ASSOC)) { + while ($data = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) { $this->hydrateRowData($data, $result); } diff --git a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php index 7351eb586a0..42c27fbd328 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php @@ -4,10 +4,10 @@ namespace Doctrine\ORM\Internal\Hydration; +use Doctrine\DBAL\FetchMode; use Doctrine\ORM\Mapping\ClassMetadata; use Doctrine\ORM\Mapping\InheritanceType; use Doctrine\ORM\Query; -use PDO; use function array_keys; use function array_search; use function count; @@ -56,7 +56,7 @@ protected function hydrateAllData() { $result = []; - while ($row = $this->stmt->fetch(PDO::FETCH_ASSOC)) { + while ($row = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) { $this->hydrateRowData($row, $result); } diff --git a/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php index 7c7d29d5554..a26f7a63c1a 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/SingleScalarHydrator.php @@ -4,6 +4,7 @@ namespace Doctrine\ORM\Internal\Hydration; +use Doctrine\DBAL\FetchMode; use Doctrine\ORM\NonUniqueResultException; use Doctrine\ORM\NoResultException; use function array_shift; @@ -20,7 +21,7 @@ class SingleScalarHydrator extends AbstractHydrator */ protected function hydrateAllData() { - $data = $this->stmt->fetchAll(\PDO::FETCH_ASSOC); + $data = $this->stmt->fetchAll(FetchMode::ASSOCIATIVE); $numRows = count($data); if ($numRows === 0) { diff --git a/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php b/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php index b9a56bc36dc..70e41a10bb9 100644 --- a/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php +++ b/lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php @@ -4,7 +4,7 @@ namespace Doctrine\ORM\Query\AST\Functions; -use Doctrine\DBAL\Platforms\AbstractPlatform; +use Doctrine\DBAL\Platforms\TrimMode; use Doctrine\ORM\Query\AST\Node; use Doctrine\ORM\Query\Lexer; use Doctrine\ORM\Query\Parser; @@ -89,18 +89,18 @@ public function parse(Parser $parser) private function getTrimMode() { if ($this->leading) { - return AbstractPlatform::TRIM_LEADING; + return TrimMode::LEADING; } if ($this->trailing) { - return AbstractPlatform::TRIM_TRAILING; + return TrimMode::TRAILING; } if ($this->both) { - return AbstractPlatform::TRIM_BOTH; + return TrimMode::BOTH; } - return AbstractPlatform::TRIM_UNSPECIFIED; + return TrimMode::UNSPECIFIED; } private function parseTrimMode(Parser $parser) diff --git a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php index 61afa7fe0fa..48d00cdc72e 100644 --- a/lib/Doctrine/ORM/Query/ParameterTypeInferer.php +++ b/lib/Doctrine/ORM/Query/ParameterTypeInferer.php @@ -5,6 +5,7 @@ namespace Doctrine\ORM\Query; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Types\Type; use function current; use function is_array; @@ -49,6 +50,6 @@ public static function inferType($value) : Connection::PARAM_STR_ARRAY; } - return \PDO::PARAM_STR; + return ParameterType::STRING; } } diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index f3f8a44baef..98c7f941e09 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -522,7 +522,7 @@ public function getRootEntities() * * @param string|int $key The parameter position or name. * @param mixed $value The parameter value. - * @param string|int|null $type PDO::PARAM_* or \Doctrine\DBAL\Types\Type::* constant + * @param string|int|null $type ParameterType::* or \Doctrine\DBAL\Types\Type::* constant * * @return self */ diff --git a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php index 1168fb12c1c..59575d2ae05 100644 --- a/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php +++ b/tests/Doctrine/Tests/Mocks/DriverConnectionMock.php @@ -5,6 +5,7 @@ namespace Doctrine\Tests\Mocks; use Doctrine\DBAL\Driver\Connection; +use Doctrine\DBAL\ParameterType; /** * Mock class for DriverConnection. @@ -51,7 +52,7 @@ public function query() /** * {@inheritdoc} */ - public function quote($input, $type=\PDO::PARAM_STR) + public function quote($input, $type = ParameterType::STRING) { } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php index 089d21cf2b8..477f4795ef2 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1225Test.php @@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; +use Doctrine\DBAL\DBALException; use Doctrine\ORM\Annotation as ORM; /** @@ -14,15 +15,12 @@ class DDC1225Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - try { - $this->schemaTool->createSchema( - [ + $this->schemaTool->createSchema( + [ $this->em->getClassMetadata(DDC1225_TestEntity1::class), $this->em->getClassMetadata(DDC1225_TestEntity2::class), - ] - ); - } catch (\PDOException $e) { - } + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php index 9b0a09a916f..4bf5f061959 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1250Test.php @@ -14,14 +14,11 @@ class DDC1250Test extends \Doctrine\Tests\OrmFunctionalTestCase public function setUp() { parent::setUp(); - try { - $this->schemaTool->createSchema( - [ + $this->schemaTool->createSchema( + [ $this->em->getClassMetadata(DDC1250ClientHistory::class), - ] - ); - } catch (\PDOException $e) { - } + ] + ); } public function testIssue() diff --git a/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php index 24b127cbae6..64e274a8e2b 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/CustomHydratorTest.php @@ -4,8 +4,8 @@ namespace Doctrine\Tests\ORM\Hydration; +use Doctrine\DBAL\FetchMode; use Doctrine\ORM\Internal\Hydration\AbstractHydrator; -use PDO; class CustomHydratorTest extends HydrationTestCase { @@ -25,6 +25,6 @@ class CustomHydrator extends AbstractHydrator { protected function hydrateAllData() { - return $this->stmt->fetchAll(PDO::FETCH_ASSOC); + return $this->stmt->fetchAll(FetchMode::ASSOCIATIVE); } } diff --git a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php index c184b364dc9..e7a76aacc67 100644 --- a/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php @@ -4,11 +4,11 @@ namespace Doctrine\Tests\ORM\Query; +use Doctrine\DBAL\ParameterType; use Doctrine\ORM\Query\ParameterTypeInferer; use Doctrine\DBAL\Connection; use Doctrine\DBAL\Types\Type; use Doctrine\Tests\OrmTestCase; -use PDO; class ParameterTypeInfererTest extends OrmTestCase { @@ -16,8 +16,8 @@ public function providerParameterTypeInferer() { $data = [ [1, Type::INTEGER], - ["bar", PDO::PARAM_STR], - ["1", PDO::PARAM_STR], + ["bar", ParameterType::STRING], + ["1", ParameterType::STRING], [new \DateTime, Type::DATETIME], [new \DateInterval('P1D'), Type::DATEINTERVAL], [[2], Connection::PARAM_INT_ARRAY], diff --git a/tests/Doctrine/Tests/ORM/Query/QueryTest.php b/tests/Doctrine/Tests/ORM/Query/QueryTest.php index a0a0e12452f..44695e5436d 100644 --- a/tests/Doctrine/Tests/ORM/Query/QueryTest.php +++ b/tests/Doctrine/Tests/ORM/Query/QueryTest.php @@ -6,6 +6,7 @@ use Doctrine\Common\Cache\ArrayCache; use Doctrine\Common\Collections\ArrayCollection; +use Doctrine\DBAL\ParameterType; use Doctrine\ORM\EntityManagerInterface; use Doctrine\ORM\Internal\Hydration\IterableResult; use Doctrine\ORM\Query\Parameter; @@ -62,7 +63,7 @@ public function testSetParameters() public function testFree() { $query = $this->em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1"); - $query->setParameter(2, 84, \PDO::PARAM_INT); + $query->setParameter(2, 84, ParameterType::INTEGER); $query->free(); @@ -74,7 +75,7 @@ public function testClone() $dql = "select u from Doctrine\Tests\Models\CMS\CmsUser u where u.username = ?1"; $query = $this->em->createQuery($dql); - $query->setParameter(2, 84, \PDO::PARAM_INT); + $query->setParameter(2, 84, ParameterType::INTEGER); $query->setHint('foo', 'bar'); $cloned = clone $query;