Skip to content

Commit

Permalink
Add dbal3 support
Browse files Browse the repository at this point in the history
  • Loading branch information
acasademont committed Nov 24, 2020
1 parent 3d46e07 commit a5b0ed9
Show file tree
Hide file tree
Showing 83 changed files with 2,417 additions and 1,395 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.9.1",
"doctrine/collections": "^1.5",
"doctrine/common": "^3.0",
"doctrine/dbal": "^2.10.0",
"doctrine/dbal": "^2.12.0 || ^3.0",
"doctrine/event-manager": "^1.1",
"doctrine/inflector": "^1.4|^2.0",
"doctrine/instantiator": "^1.3",
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Id/SequenceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function generate(EntityManager $em, $entity)
$sql = $conn->getDatabasePlatform()->getSequenceNextValSQL($this->_sequenceName);

// Using `query` to force usage of the master server in MasterSlaveConnection
$this->_nextValue = (int) $conn->query($sql)->fetchColumn();
$this->_nextValue = (int) $conn->query($sql)->fetchOne();
$this->_maxValue = $this->_nextValue + $this->_allocationSize;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Id/TableGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function generate(
if ($conn->getTransactionNestingLevel() === 0) {
// use select for update
$sql = $conn->getDatabasePlatform()->getTableHiLoCurrentValSql($this->_tableName, $this->_sequenceName);
$currentLevel = $conn->fetchColumn($sql);
$currentLevel = $conn->fetchOne($sql);

if ($currentLevel != null) {
$this->_nextValue = $currentLevel;
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Id/UuidGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ public function generate(EntityManager $em, $entity)
$conn = $em->getConnection();
$sql = 'SELECT ' . $conn->getDatabasePlatform()->getGuidExpression();

return $conn->query($sql)->fetchColumn(0);
return $conn->query($sql)->fetchOne();
}
}
16 changes: 11 additions & 5 deletions lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\Types\Type;
Expand Down Expand Up @@ -90,7 +91,7 @@ abstract class AbstractHydrator
/**
* The statement that provides the data to hydrate.
*
* @var \Doctrine\DBAL\Driver\Statement
* @var Statement|Result
*/
protected $_stmt;

Expand Down Expand Up @@ -147,11 +148,12 @@ public function iterate($stmt, $resultSetMapping, array $hints = [])
/**
* Initiates a row-by-row hydration.
*
* @param Statement|Result $stmt
* @param mixed[] $hints
*
* @return iterable<mixed>
*/
public function toIterable(Statement $stmt, ResultSetMapping $resultSetMapping, array $hints = []) : iterable
public function toIterable($stmt, ResultSetMapping $resultSetMapping, array $hints = []): iterable
{
$this->_stmt = $stmt;
$this->_rsm = $resultSetMapping;
Expand All @@ -166,7 +168,7 @@ public function toIterable(Statement $stmt, ResultSetMapping $resultSetMapping,
$result = [];

while (true) {
$row = $this->_stmt->fetch(FetchMode::ASSOCIATIVE);
$row = $this->_stmt->fetchAssociative();

if ($row === false || $row === null) {
$this->cleanup();
Expand Down Expand Up @@ -214,7 +216,7 @@ public function hydrateAll($stmt, $resultSetMapping, array $hints = [])
*/
public function hydrateRow()
{
$row = $this->_stmt->fetch(PDO::FETCH_ASSOC);
$row = $this->_stmt->fetchAssociative();

if ($row === false || $row === null) {
$this->cleanup();
Expand Down Expand Up @@ -259,7 +261,11 @@ protected function prepare()
*/
protected function cleanup()
{
$this->_stmt->closeCursor();
if ($this->_stmt instanceof Statement) {
$this->_stmt->closeCursor();
} else {
$this->_stmt->free();
}

$this->_stmt = null;
$this->_rsm = null;
Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Internal/Hydration/ArrayHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ protected function hydrateAllData()
{
$result = [];

while ($data = $this->_stmt->fetch(PDO::FETCH_ASSOC)) {
while ($data = $this->_stmt->fetchAssociative()) {
$this->hydrateRowData($data, $result);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Internal/Hydration/ObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ protected function hydrateAllData()
{
$result = [];

while ($row = $this->_stmt->fetch(PDO::FETCH_ASSOC)) {
while ($row = $this->_stmt->fetchAssociative()) {
$this->hydrateRowData($row, $result);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Internal/Hydration/ScalarHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ protected function hydrateAllData()
{
$result = [];

while ($data = $this->_stmt->fetch(\PDO::FETCH_ASSOC)) {
while ($data = $this->_stmt->fetchAssociative()) {
$this->hydrateRowData($data, $result);
}

Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

namespace Doctrine\ORM\Internal\Hydration;

use Doctrine\ORM\Utility\SQLResultCaser;
use PDO;
use Doctrine\ORM\Mapping\ClassMetadata;
use Doctrine\ORM\Query;
Expand Down Expand Up @@ -66,7 +67,7 @@ protected function hydrateAllData()
{
$result = [];

while ($row = $this->_stmt->fetch(PDO::FETCH_ASSOC)) {
while ($row = $this->_stmt->fetchAssociative()) {
$this->hydrateRowData($row, $result);
}

Expand All @@ -86,7 +87,7 @@ protected function hydrateRowData(array $row, array &$result)

// We need to find the correct entity class name if we have inheritance in resultset
if ($this->class->inheritanceType !== ClassMetadata::INHERITANCE_TYPE_NONE) {
$discrColumnName = $this->_platform->getSQLResultCasing($this->class->discriminatorColumn['name']);
$discrColumnName = SQLResultCaser::casing($this->_platform, $this->class->discriminatorColumn['name']);

// Find mapped discriminator column from the result set.
if ($metaMappingDiscrColumnName = array_search($discrColumnName, $this->_rsm->metaMappings)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class SingleScalarHydrator extends AbstractHydrator
*/
protected function hydrateAllData()
{
$data = $this->_stmt->fetchAll(\PDO::FETCH_ASSOC);
$data = $this->_stmt->fetchAllAssociative();
$numRows = count($data);

if ($numRows === 0) {
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Mapping/AnsiQuoteStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Doctrine\ORM\Mapping;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\ORM\Utility\SQLResultCaser;

/**
* ANSI compliant quote strategy, this strategy does not apply any quote.
Expand Down Expand Up @@ -91,6 +92,6 @@ public function getIdentifierColumnNames(ClassMetadata $class, AbstractPlatform
*/
public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null)
{
return $platform->getSQLResultCasing($columnName . '_' . $counter);
return SQLResultCaser::casing($platform, $columnName . '_' . $counter);
}
}
11 changes: 10 additions & 1 deletion lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,22 @@ private function completeIdGeneratorMapping(ClassMetadataInfo $class)
{
$idGenType = $class->generatorType;
if ($idGenType == ClassMetadata::GENERATOR_TYPE_AUTO) {
if ($this->getTargetPlatform()->supportsIdentityColumns()) {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
} elseif ($this->getTargetPlatform()->supportsSequences()) {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
} else {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE);
}
/*
* @todo WIP
if ($this->getTargetPlatform()->prefersSequences()) {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_SEQUENCE);
} else if ($this->getTargetPlatform()->prefersIdentityColumns()) {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_IDENTITY);
} else {
$class->setIdGeneratorType(ClassMetadata::GENERATOR_TYPE_TABLE);
}
}*/
}

// Create & assign an appropriate ID generator instance
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Doctrine\ORM\Mapping;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\ORM\Utility\SQLResultCaser;

/**
* A set of rules for determining the physical column, alias and table quotes
Expand Down Expand Up @@ -159,6 +160,6 @@ public function getColumnAlias($columnName, $counter, AbstractPlatform $platform
$columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName);
$columnName = is_numeric($columnName) ? '_' . $columnName : $columnName;

return $platform->getSQLResultCasing($columnName);
return SQLResultCaser::casing($platform, $columnName);
}
}
27 changes: 14 additions & 13 deletions lib/Doctrine/ORM/Mapping/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Types\Types;
use Doctrine\Inflector\Inflector;
use Doctrine\Inflector\InflectorFactory;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
Expand Down Expand Up @@ -428,27 +429,27 @@ private function buildFieldMapping($tableName, Column $column)

// Type specific elements
switch ($fieldMapping['type']) {
case Type::TARRAY:
case Type::BLOB:
case Type::GUID:
case Type::JSON_ARRAY:
case Type::OBJECT:
case Type::SIMPLE_ARRAY:
case Type::STRING:
case Type::TEXT:
case Types::ARRAY:
case Types::BLOB:
case Types::GUID:
case Types::JSON:
case Types::OBJECT:
case Types::SIMPLE_ARRAY:
case Types::STRING:
case Types::TEXT:
$fieldMapping['length'] = $column->getLength();
$fieldMapping['options']['fixed'] = $column->getFixed();
break;

case Type::DECIMAL:
case Type::FLOAT:
case Types::DECIMAL:
case Types::FLOAT:
$fieldMapping['precision'] = $column->getPrecision();
$fieldMapping['scale'] = $column->getScale();
break;

case Type::INTEGER:
case Type::BIGINT:
case Type::SMALLINT:
case Types::INTEGER:
case Types::BIGINT:
case Types::SMALLINT:
$fieldMapping['options']['unsigned'] = $column->getUnsigned();
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ public function count(PersistentCollection $collection)
. $joinTargetEntitySQL
. ' WHERE ' . implode(' AND ', $conditions);

return $this->conn->fetchColumn($sql, $params, 0, $types);
return $this->conn->fetchOne($sql, $params, $types);
}

/**
Expand Down Expand Up @@ -196,7 +196,7 @@ public function containsKey(PersistentCollection $collection, $key)

$sql = 'SELECT 1 FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses);

return (bool) $this->conn->fetchColumn($sql, $params, 0, $types);
return (bool) $this->conn->fetchOne($sql, $params, $types);
}

/**
Expand All @@ -216,7 +216,7 @@ public function contains(PersistentCollection $collection, $element)

$sql = 'SELECT 1 FROM ' . $quotedJoinTable . ' WHERE ' . implode(' AND ', $whereClauses);

return (bool) $this->conn->fetchColumn($sql, $params, 0, $types);
return (bool) $this->conn->fetchOne($sql, $params, $types);
}

/**
Expand Down Expand Up @@ -780,7 +780,7 @@ private function getOrderingSql(Criteria $criteria, ClassMetadata $targetClass)
/**
* @param Criteria $criteria
* @return string
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Exception
*/
private function getLimitSql(Criteria $criteria)
{
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/Persisters/Collection/OneToManyPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
namespace Doctrine\ORM\Persisters\Collection;

use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Types\Type;
use Doctrine\ORM\PersistentCollection;
use Doctrine\ORM\Utility\PersisterHelper;
Expand Down Expand Up @@ -181,7 +182,7 @@ public function loadCriteria(PersistentCollection $collection, Criteria $criteri
*
* @return int
*
* @throws \Doctrine\DBAL\DBALException
* @throws Exception
*/
private function deleteEntityCollection(PersistentCollection $collection)
{
Expand Down Expand Up @@ -213,7 +214,7 @@ private function deleteEntityCollection(PersistentCollection $collection)
*
* @return int
*
* @throws \Doctrine\DBAL\DBALException
* @throws Exception
*/
private function deleteJoinedEntityCollection(PersistentCollection $collection)
{
Expand Down
Loading

0 comments on commit a5b0ed9

Please sign in to comment.