Deprecated platform-specific portability mode constants

parent 7047798f
# Upgrade to 2.11 # Upgrade to 2.11
## Deprecated `Portability\Connection::PORTABILITY_{PLATFORM}` constants`
The platform-specific portability mode flags are meant to be used only by the portability layer internally to optimize
the user-provided mode for the current database platform.
## Deprecated `MasterSlaveConnection` use `PrimaryReadReplicaConnection` ## Deprecated `MasterSlaveConnection` use `PrimaryReadReplicaConnection`
The `Doctrine\DBAL\Connections\MasterSlaveConnection` class is renamed to `Doctrine\DBAL\Connections\PrimaryReadReplicaConnection`. The `Doctrine\DBAL\Connections\MasterSlaveConnection` class is renamed to `Doctrine\DBAL\Connections\PrimaryReadReplicaConnection`.
......
...@@ -23,6 +23,10 @@ class Connection extends \Doctrine\DBAL\Connection ...@@ -23,6 +23,10 @@ class Connection extends \Doctrine\DBAL\Connection
public const PORTABILITY_EMPTY_TO_NULL = 4; public const PORTABILITY_EMPTY_TO_NULL = 4;
public const PORTABILITY_FIX_CASE = 8; public const PORTABILITY_FIX_CASE = 8;
/**#@+
*
* @deprecated Will be removed as internal implementation details.
*/
public const PORTABILITY_DB2 = 13; public const PORTABILITY_DB2 = 13;
public const PORTABILITY_ORACLE = 9; public const PORTABILITY_ORACLE = 9;
public const PORTABILITY_POSTGRESQL = 13; public const PORTABILITY_POSTGRESQL = 13;
...@@ -31,6 +35,7 @@ class Connection extends \Doctrine\DBAL\Connection ...@@ -31,6 +35,7 @@ class Connection extends \Doctrine\DBAL\Connection
public const PORTABILITY_DRIZZLE = 13; public const PORTABILITY_DRIZZLE = 13;
public const PORTABILITY_SQLANYWHERE = 13; public const PORTABILITY_SQLANYWHERE = 13;
public const PORTABILITY_SQLSRV = 13; public const PORTABILITY_SQLSRV = 13;
/**#@-*/
/** @var int */ /** @var int */
private $portability = self::PORTABILITY_NONE; private $portability = self::PORTABILITY_NONE;
...@@ -47,25 +52,10 @@ class Connection extends \Doctrine\DBAL\Connection ...@@ -47,25 +52,10 @@ class Connection extends \Doctrine\DBAL\Connection
if ($ret) { if ($ret) {
$params = $this->getParams(); $params = $this->getParams();
if (isset($params['portability'])) { if (isset($params['portability'])) {
if ($this->getDatabasePlatform()->getName() === 'oracle') { $this->portability = $params['portability'] = (new OptimizeFlags())(
$params['portability'] &= self::PORTABILITY_ORACLE; $this->getDatabasePlatform(),
} elseif ($this->getDatabasePlatform()->getName() === 'postgresql') { $params['portability']
$params['portability'] &= self::PORTABILITY_POSTGRESQL; );
} elseif ($this->getDatabasePlatform()->getName() === 'sqlite') {
$params['portability'] &= self::PORTABILITY_SQLITE;
} elseif ($this->getDatabasePlatform()->getName() === 'drizzle') {
$params['portability'] &= self::PORTABILITY_DRIZZLE;
} elseif ($this->getDatabasePlatform()->getName() === 'sqlanywhere') {
$params['portability'] &= self::PORTABILITY_SQLANYWHERE;
} elseif ($this->getDatabasePlatform()->getName() === 'db2') {
$params['portability'] &= self::PORTABILITY_DB2;
} elseif ($this->getDatabasePlatform()->getName() === 'mssql') {
$params['portability'] &= self::PORTABILITY_SQLSRV;
} else {
$params['portability'] &= self::PORTABILITY_OTHERVENDORS;
}
$this->portability = $params['portability'];
} }
if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) { if (isset($params['fetch_case']) && $this->portability & self::PORTABILITY_FIX_CASE) {
......
<?php
declare(strict_types=1);
namespace Doctrine\DBAL\Portability;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\PostgreSQL94Platform;
use Doctrine\DBAL\Platforms\SQLAnywhere16Platform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Platforms\SQLServer2012Platform;
final class OptimizeFlags
{
/**
* Platform-specific portability flags that need to be excluded from the user-provided mode
* since the platform already operates in this mode to avoid unnecessary conversion overhead.
*
* @var array<string,int>
*/
private static $platforms = [
DB2Platform::class => 0,
OraclePlatform::class => Connection::PORTABILITY_EMPTY_TO_NULL,
PostgreSQL94Platform::class => 0,
SQLAnywhere16Platform::class => 0,
SqlitePlatform::class => 0,
SQLServer2012Platform::class => 0,
];
public function __invoke(AbstractPlatform $platform, int $flags): int
{
foreach (self::$platforms as $class => $mask) {
if ($platform instanceof $class) {
$flags &= ~$mask;
break;
}
}
return $flags;
}
}
<?php
declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Portability;
use Doctrine\DBAL\Platforms\OraclePlatform;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Portability\Connection;
use Doctrine\DBAL\Portability\OptimizeFlags;
use PHPUnit\Framework\TestCase;
class OptimizeFlagsTest extends TestCase
{
/** @var OptimizeFlags */
private $optimizeFlags;
protected function setUp(): void
{
$this->optimizeFlags = new OptimizeFlags();
}
public function testOracle(): void
{
$flags = ($this->optimizeFlags)(new OraclePlatform(), Connection::PORTABILITY_ALL);
self::assertSame(0, $flags & Connection::PORTABILITY_EMPTY_TO_NULL);
}
public function testAnotherPlatform(): void
{
$flags = ($this->optimizeFlags)(new SqlitePlatform(), Connection::PORTABILITY_ALL);
self::assertSame(Connection::PORTABILITY_ALL, $flags);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment