Skip to content

Commit

Permalink
Merge pull request #4091 from morozov/portability-get-params
Browse files Browse the repository at this point in the history
Get rid of the call to Connection::getParams() in Portability\Statement
  • Loading branch information
morozov authored Jun 19, 2020
2 parents af36950 + f97b3e1 commit 20f2dee
Showing 1 changed file with 39 additions and 14 deletions.
53 changes: 39 additions & 14 deletions src/Portability/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

namespace Doctrine\DBAL\Portability;

use Doctrine\Common\EventManager;
use Doctrine\DBAL\Abstraction\Result as AbstractionResult;
use Doctrine\DBAL\Cache\QueryCacheProfile;
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\Result as DriverResult;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
Expand All @@ -17,42 +21,63 @@
/**
* Portability wrapper for a Connection.
*/
class Connection extends \Doctrine\DBAL\Connection
class Connection extends BaseConnection
{
public const PORTABILITY_ALL = 255;
public const PORTABILITY_NONE = 0;
public const PORTABILITY_RTRIM = 1;
public const PORTABILITY_EMPTY_TO_NULL = 4;
public const PORTABILITY_FIX_CASE = 8;

/** @var int */
private $portability = self::PORTABILITY_NONE;

/** @var int */
private $case = 0;

/** @var 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}
*/
public function connect()
{
$ret = parent::connect();
if ($ret) {
$params = $this->getParams();
$portability = self::PORTABILITY_NONE;

if (isset($params['portability'])) {
$portability = $params['portability'] = (new OptimizeFlags())(
$this->getDatabasePlatform(),
$params['portability']
);
}
$portability = (new OptimizeFlags())(
$this->getDatabasePlatform(),
$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) {
// 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 {
$case = $params['fetch_case'] === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER;
$case = $this->case === ColumnCase::LOWER ? CASE_LOWER : CASE_UPPER;
}
}

Expand Down

0 comments on commit 20f2dee

Please sign in to comment.