Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get rid of the call to Connection::getParams() in Portability\Statement #4091

Merged
merged 1 commit into from
Jun 19, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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