Unverified Commit 20f2deed authored by Sergei Morozov's avatar Sergei Morozov Committed by GitHub

Merge pull request #4091 from morozov/portability-get-params

Get rid of the call to Connection::getParams() in Portability\Statement
parents af36950a f97b3e19
...@@ -2,9 +2,13 @@ ...@@ -2,9 +2,13 @@
namespace Doctrine\DBAL\Portability; namespace Doctrine\DBAL\Portability;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Abstraction\Result as AbstractionResult; use Doctrine\DBAL\Abstraction\Result as AbstractionResult;
use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\Cache\QueryCacheProfile;
use Doctrine\DBAL\ColumnCase; use Doctrine\DBAL\ColumnCase;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Connection as BaseConnection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Driver\Result as DriverResult; use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement;
...@@ -17,7 +21,7 @@ use const CASE_UPPER; ...@@ -17,7 +21,7 @@ use const CASE_UPPER;
/** /**
* Portability wrapper for a Connection. * Portability wrapper for a Connection.
*/ */
class Connection extends \Doctrine\DBAL\Connection class Connection extends BaseConnection
{ {
public const PORTABILITY_ALL = 255; public const PORTABILITY_ALL = 255;
public const PORTABILITY_NONE = 0; public const PORTABILITY_NONE = 0;
...@@ -25,9 +29,35 @@ class Connection extends \Doctrine\DBAL\Connection ...@@ -25,9 +29,35 @@ 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;
/** @var int */
private $portability = self::PORTABILITY_NONE;
/** @var int */
private $case = 0;
/** @var Converter */ /** @var Converter */
private $converter; private $converter;
/** {@inheritDoc} */
public function __construct(
array $params,
Driver $driver,
?Configuration $config = null,
?EventManager $eventManager = null
) {
if (isset($params['portability'])) {
$this->portability = $params['portability'];
}
if (isset($params['fetch_case'])) {
$this->case = $params['fetch_case'];
}
unset($params['portability'], $params['fetch_case']);
parent::__construct($params, $driver, $config, $eventManager);
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -35,24 +65,19 @@ class Connection extends \Doctrine\DBAL\Connection ...@@ -35,24 +65,19 @@ class Connection extends \Doctrine\DBAL\Connection
{ {
$ret = parent::connect(); $ret = parent::connect();
if ($ret) { if ($ret) {
$params = $this->getParams(); $portability = (new OptimizeFlags())(
$portability = self::PORTABILITY_NONE;
if (isset($params['portability'])) {
$portability = $params['portability'] = (new OptimizeFlags())(
$this->getDatabasePlatform(), $this->getDatabasePlatform(),
$params['portability'] $this->portability
); );
}
$case = null; $case = 0;
if (isset($params['fetch_case']) && ($portability & self::PORTABILITY_FIX_CASE) !== 0) { if ($this->case !== 0 && ($portability & self::PORTABILITY_FIX_CASE) !== 0) {
if ($this->_conn instanceof PDOConnection) { if ($this->_conn instanceof PDOConnection) {
// make use of c-level support for case handling // make use of c-level support for case handling
$this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_CASE, $params['fetch_case']); $this->_conn->getWrappedConnection()->setAttribute(PDO::ATTR_CASE, $this->case);
} else { } else {
$case = $params['fetch_case'] === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER; $case = $this->case === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER;
} }
} }
......
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