Skip to content

Commit

Permalink
Drop support for DBAL 3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Nov 28, 2021
1 parent 0aadc45 commit 64b8d1f
Show file tree
Hide file tree
Showing 23 changed files with 52 additions and 77 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"doctrine/cache": "^1.12.1 || ^2.1.1",
"doctrine/collections": "^1.5",
"doctrine/common": "^3.0.3",
"doctrine/dbal": "^2.13.1 || ^3.1.1",
"doctrine/dbal": "^2.13.1 || ^3.2",
"doctrine/deprecations": "^0.5.3",
"doctrine/event-manager": "^1.1",
"doctrine/inflector": "^1.4 || ^2.0",
Expand Down
10 changes: 5 additions & 5 deletions lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ public function setHydrationCacheProfile(?QueryCacheProfile $profile = null)
return $this;
}

// DBAL < 3.2
// DBAL 2
if (! method_exists(QueryCacheProfile::class, 'setResultCache')) {
if (! $profile->getResultCacheDriver()) {
$defaultHydrationCacheImpl = $this->_em->getConfiguration()->getHydrationCache();
Expand Down Expand Up @@ -584,7 +584,7 @@ public function setResultCacheProfile(?QueryCacheProfile $profile = null)
return $this;
}

// DBAL < 3.2
// DBAL 2
if (! method_exists(QueryCacheProfile::class, 'setResultCache')) {
if (! $profile->getResultCacheDriver()) {
$defaultResultCacheDriver = $this->_em->getConfiguration()->getResultCache();
Expand Down Expand Up @@ -640,7 +640,7 @@ public function setResultCache(?CacheItemPoolInterface $resultCache = null)
return $this;
}

// DBAL < 3.2
// DBAL 2
if (! method_exists(QueryCacheProfile::class, 'setResultCache')) {
$resultCacheDriver = DoctrineProvider::wrap($resultCache);

Expand Down Expand Up @@ -746,7 +746,7 @@ public function setResultCacheLifetime($lifetime)
return $this;
}

// Compatibility for DBAL < 3.2
// Compatibility for DBAL 2
if (! method_exists($this->_queryCacheProfile, 'setResultCache')) {
$this->_queryCacheProfile = $this->_queryCacheProfile->setResultCacheDriver(DoctrineProvider::wrap($cache));

Expand Down Expand Up @@ -1177,7 +1177,7 @@ private function getHydrationCache(): CacheItemPoolInterface
{
assert($this->_hydrationCacheProfile !== null);

// Support for DBAL < 3.2
// Support for DBAL 2
if (! method_exists($this->_hydrationCacheProfile, 'getResultCache')) {
$cacheDriver = $this->_hydrationCacheProfile->getResultCacheDriver();
assert($cacheDriver !== null);
Expand Down
4 changes: 2 additions & 2 deletions lib/Doctrine/ORM/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ public function getMetadataDriverImpl()
*/
public function getResultCache(): ?CacheItemPoolInterface
{
// Compatibility with DBAL < 3.2
// Compatibility with DBAL 2
if (! method_exists(parent::class, 'getResultCache')) {
$cacheImpl = $this->getResultCacheImpl();

Expand All @@ -271,7 +271,7 @@ public function getResultCache(): ?CacheItemPoolInterface
*/
public function setResultCache(CacheItemPoolInterface $cache): void
{
// Compatibility with DBAL < 3.2
// Compatibility with DBAL 2
if (! method_exists(parent::class, 'setResultCache')) {
$this->setResultCacheImpl(DoctrineProvider::wrap($cache));

Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ORM/Internal/SQLResultCasing.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;

use function method_exists;
Expand All @@ -25,7 +24,7 @@ private function getSQLResultCasing(AbstractPlatform $platform, string $column):
return strtoupper($column);
}

if ($platform instanceof PostgreSQL94Platform || $platform instanceof PostgreSQLPlatform) {
if ($platform instanceof PostgreSQLPlatform) {
return strtolower($column);
}

Expand Down
1 change: 0 additions & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,6 @@ private function determineIdGeneratorStrategy(AbstractPlatform $platform): int
{
if (
$platform instanceof Platforms\OraclePlatform
|| $platform instanceof Platforms\PostgreSQL94Platform
|| $platform instanceof Platforms\PostgreSQLPlatform
) {
return ClassMetadata::GENERATOR_TYPE_SEQUENCE;
Expand Down
7 changes: 5 additions & 2 deletions lib/Doctrine/ORM/Query/AST/Functions/LowerFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;

use function sprintf;

/**
* "LOWER" "(" StringPrimary ")"
*
* @link www.doctrine-project.org
*/
class LowerFunction extends FunctionNode
{
/** @psalm-var Node */
/** @var Node */
public $stringPrimary;

/**
Expand All @@ -25,7 +27,8 @@ class LowerFunction extends FunctionNode
*/
public function getSql(SqlWalker $sqlWalker)
{
return $sqlWalker->getConnection()->getDatabasePlatform()->getLowerExpression(
return sprintf(
'LOWER(%s)',
$sqlWalker->walkSimpleArithmeticExpression($this->stringPrimary)
);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;

use function sprintf;

/**
* "SQRT" "(" SimpleArithmeticExpression ")"
*
Expand All @@ -25,7 +27,8 @@ class SqrtFunction extends FunctionNode
*/
public function getSql(SqlWalker $sqlWalker)
{
return $sqlWalker->getConnection()->getDatabasePlatform()->getSqrtExpression(
return sprintf(
'SQRT(%s)',
$sqlWalker->walkSimpleArithmeticExpression($this->simpleArithmeticExpression)
);
}
Expand Down
5 changes: 4 additions & 1 deletion lib/Doctrine/ORM/Query/AST/Functions/UpperFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
use Doctrine\ORM\Query\Parser;
use Doctrine\ORM\Query\SqlWalker;

use function sprintf;

/**
* "UPPER" "(" StringPrimary ")"
*
Expand All @@ -25,7 +27,8 @@ class UpperFunction extends FunctionNode
*/
public function getSql(SqlWalker $sqlWalker)
{
return $sqlWalker->getConnection()->getDatabasePlatform()->getUpperExpression(
return sprintf(
'UPPER(%s)',
$sqlWalker->walkSimpleArithmeticExpression($this->stringPrimary)
);
}
Expand Down
9 changes: 3 additions & 6 deletions lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\ORM\Tools\Pagination;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\ORM\Query;
use Doctrine\ORM\Query\AST\SelectStatement;
Expand Down Expand Up @@ -72,16 +71,15 @@ public function __construct($query, $parserResult, array $queryComponents)
*/
public function walkSelectStatement(SelectStatement $AST)
{
if ($this->platform instanceof SQLServer2012Platform || $this->platform instanceof SQLServerPlatform) {
if ($this->platform instanceof SQLServerPlatform) {
$AST->orderByClause = null;
}

$sql = parent::walkSelectStatement($AST);

if ($AST->groupByClause) {
return sprintf(
'SELECT %s AS dctrn_count FROM (%s) dctrn_table',
$this->platform->getCountExpression('*'),
'SELECT COUNT(*) AS dctrn_count FROM (%s) dctrn_table',
$sql
);
}
Expand Down Expand Up @@ -133,8 +131,7 @@ public function walkSelectStatement(SelectStatement $AST)

// Build the counter query
return sprintf(
'SELECT %s AS dctrn_count FROM (SELECT DISTINCT %s FROM (%s) dctrn_result) dctrn_table',
$this->platform->getCountExpression('*'),
'SELECT COUNT(*) AS dctrn_count FROM (SELECT DISTINCT %s FROM (%s) dctrn_result) dctrn_table',
implode(', ', $sqlIdentifier),
$sql
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Mapping\QuoteStrategy;
Expand Down Expand Up @@ -117,9 +115,7 @@ public function __construct($query, $parserResult, array $queryComponents)
*/
private function platformSupportsRowNumber(): bool
{
return $this->platform instanceof PostgreSQL94Platform // DBAL 3.1 compatibility
|| $this->platform instanceof PostgreSQLPlatform
|| $this->platform instanceof SQLServer2012Platform // DBAL 3.1 compatibility
return $this->platform instanceof PostgreSQLPlatform
|| $this->platform instanceof SQLServerPlatform
|| $this->platform instanceof OraclePlatform
|| $this->platform instanceof SQLAnywherePlatform
Expand Down
3 changes: 1 addition & 2 deletions lib/Doctrine/ORM/Tools/SchemaTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ public function getSchemaFromMetadata(array $classes)
$eventManager = $this->em->getEventManager();
$metadataSchemaConfig = $this->schemaManager->createSchemaConfig();

$metadataSchemaConfig->setExplicitForeignKeyIndexes(false);
$schema = new Schema([], [], $metadataSchemaConfig);

$addedFks = [];
Expand Down Expand Up @@ -931,7 +930,7 @@ public function getUpdateSchemaSql(array $classes, $saveMode = false)
$fromSchema = $this->createSchemaForComparison($toSchema);

$comparator = new Comparator();
$schemaDiff = $comparator->compare($fromSchema, $toSchema);
$schemaDiff = $comparator->compareSchemas($fromSchema, $toSchema);

if ($saveMode) {
return $schemaDiff->toSaveSql($this->platform);
Expand Down
17 changes: 1 addition & 16 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2181,9 +2181,6 @@
<ArgumentTypeCoercion occurrences="1">
<code>$this-&gt;stringPrimary</code>
</ArgumentTypeCoercion>
<DeprecatedMethod occurrences="1">
<code>getLowerExpression</code>
</DeprecatedMethod>
<PropertyNotSetInConstructor occurrences="1">
<code>$stringPrimary</code>
</PropertyNotSetInConstructor>
Expand Down Expand Up @@ -2213,9 +2210,6 @@
</PropertyNotSetInConstructor>
</file>
<file src="lib/Doctrine/ORM/Query/AST/Functions/SqrtFunction.php">
<DeprecatedMethod occurrences="1">
<code>getSqrtExpression</code>
</DeprecatedMethod>
<PropertyNotSetInConstructor occurrences="1">
<code>$simpleArithmeticExpression</code>
</PropertyNotSetInConstructor>
Expand Down Expand Up @@ -2254,9 +2248,6 @@
<ArgumentTypeCoercion occurrences="1">
<code>$this-&gt;stringPrimary</code>
</ArgumentTypeCoercion>
<DeprecatedMethod occurrences="1">
<code>getUpperExpression</code>
</DeprecatedMethod>
<PropertyNotSetInConstructor occurrences="1">
<code>$stringPrimary</code>
</PropertyNotSetInConstructor>
Expand Down Expand Up @@ -3650,10 +3641,6 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="lib/Doctrine/ORM/Tools/Pagination/CountOutputWalker.php">
<DeprecatedMethod occurrences="2">
<code>getCountExpression</code>
<code>getCountExpression</code>
</DeprecatedMethod>
<MoreSpecificImplementedParamType occurrences="1">
<code>$query</code>
</MoreSpecificImplementedParamType>
Expand Down Expand Up @@ -3723,10 +3710,8 @@
<RedundantConditionGivenDocblockType occurrences="1"/>
</file>
<file src="lib/Doctrine/ORM/Tools/SchemaTool.php">
<DeprecatedMethod occurrences="3">
<DeprecatedMethod occurrences="1">
<code>canEmulateSchemas</code>
<code>compare</code>
<code>setExplicitForeignKeyIndexes</code>
</DeprecatedMethod>
<DocblockTypeContradiction occurrences="2">
<code>! $definingClass</code>
Expand Down
6 changes: 1 addition & 5 deletions tests/Doctrine/Tests/ORM/Functional/DatabaseDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
namespace Doctrine\Tests\ORM\Functional;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Platforms\SQLServerPlatform;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Schema\Table;
Expand Down Expand Up @@ -231,9 +229,7 @@ private static function supportsUnsignedInteger(AbstractPlatform $platform): boo
// FIXME: Condition here is fugly.
// NOTE: PostgreSQL and SQL SERVER do not support UNSIGNED integer

return ! $platform instanceof SQLServer2012Platform
&& ! $platform instanceof SQLServerPlatform
&& ! $platform instanceof PostgreSQL94Platform
return ! $platform instanceof SQLServerPlatform
&& ! $platform instanceof PostgreSQLPlatform;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Doctrine\Tests\ORM\Functional\SchemaTool;

use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
Expand All @@ -29,7 +28,7 @@ protected function setUp(): void
parent::setUp();

$platform = $this->_em->getConnection()->getDatabasePlatform();
if (! $platform instanceof PostgreSQL94Platform && ! $platform instanceof PostgreSQLPlatform) {
if (! $platform instanceof PostgreSQLPlatform) {
self::markTestSkipped('The ' . self::class . ' requires the use of postgresql.');
}
}
Expand Down
3 changes: 1 addition & 2 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1151Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
Expand All @@ -23,7 +22,7 @@ class DDC1151Test extends OrmFunctionalTestCase
public function testQuoteForeignKey(): void
{
$platform = $this->_em->getConnection()->getDatabasePlatform();
if (! $platform instanceof PostgreSQL94Platform && ! $platform instanceof PostgreSQLPlatform) {
if (! $platform instanceof PostgreSQLPlatform) {
self::markTestSkipped('This test is useful for all databases, but designed only for postgresql.');
}

Expand Down
4 changes: 1 addition & 3 deletions tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1360Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@

namespace Doctrine\Tests\ORM\Functional\Ticket;

use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;
use Doctrine\Tests\OrmFunctionalTestCase;

/**
Expand All @@ -21,7 +19,7 @@ class DDC1360Test extends OrmFunctionalTestCase
public function testSchemaDoubleQuotedCreate(): void
{
$platform = $this->_em->getConnection()->getDatabasePlatform();
if (! $platform instanceof PostgreSQL94Platform && ! $platform instanceof PostgreSQLPlatform) {
if (! $platform instanceof PostgreSQLPlatform) {
self::markTestSkipped('PostgreSQL only test.');
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2012Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use function get_class;
use function implode;
use function is_array;
use function sprintf;
use function strtolower;

/**
Expand Down Expand Up @@ -176,7 +177,7 @@ public function convertToDatabaseValueSQL($sqlExpr, AbstractPlatform $platform)
// changed to upper expression to keep the test compatible with other Databases
//sprintf('to_tsvector(%s)', $sqlExpr);

return $platform->getUpperExpression($sqlExpr);
return sprintf('UPPER(%s)', $sqlExpr);
}

/**
Expand Down
Loading

0 comments on commit 64b8d1f

Please sign in to comment.