Skip to content

Commit

Permalink
Dropped support for fetching objects and non-zero column
Browse files Browse the repository at this point in the history
1. `FetchMode::STANDARD_OBJECT` and `FetchMode::CUSTOM_OBJECT` are no longer supported.
2. `FetchMode::COLUMN` with a non-zero index is no longer supported.
3. Incompatible change in the `Connection::fetchColumn()` signature where the 3rd argument is now `$types`, not `$columnIndex`.
  • Loading branch information
morozov committed Jan 29, 2020
1 parent 77087e7 commit be09d0f
Show file tree
Hide file tree
Showing 24 changed files with 95 additions and 777 deletions.
8 changes: 8 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Upgrade to 3.0

## BC BREAK: Dropped support for `FetchMode::CUSTOM_OBJECT` and `::STANDARD_OBJECT`

Instead of fetching an object, fetch an array and map it to an object of the desired class.

## BC BREAK: Dropped support for the `$columnIndex` argument in `ResultStatement::fetchColumn()`, other `ResultStatement::fetch*()` methods invoked with `FetchMode::COLUMN` and `Connection::fetchColumn()`.

In order to fetch a column with an index other than `0`, use `FetchMode::NUMERIC` and the array element with the corresponding index.

## BC BREAK: Changes in the QueryBuilder API.

1. The `select()`, `addSelect()`, `groupBy()` and `addGroupBy()` methods no longer accept an array of arguments. Pass each expression as an individual argument or expand an array of expressions using the `...` operator.
Expand Down
25 changes: 6 additions & 19 deletions lib/Doctrine/DBAL/Cache/ArrayStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,9 @@

use ArrayIterator;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Exception\InvalidColumnIndex;
use Doctrine\DBAL\FetchMode;
use InvalidArgumentException;
use IteratorAggregate;
use function array_key_exists;
use function array_merge;
use function array_values;
use function count;
Expand Down Expand Up @@ -59,15 +57,8 @@ public function rowCount() : int
return count($this->data);
}

/**
* {@inheritdoc}
*/
public function setFetchMode(int $fetchMode, ...$args) : void
public function setFetchMode(int $fetchMode) : void
{
if (count($args) > 0) {
throw new InvalidArgumentException('Caching layer does not support 2nd/3rd argument to setFetchMode().');
}

$this->defaultFetchMode = $fetchMode;
}

Expand All @@ -84,7 +75,7 @@ public function getIterator()
/**
* {@inheritdoc}
*/
public function fetch(?int $fetchMode = null, ...$args)
public function fetch(?int $fetchMode = null)
{
if (! isset($this->data[$this->num])) {
return false;
Expand Down Expand Up @@ -117,10 +108,10 @@ public function fetch(?int $fetchMode = null, ...$args)
/**
* {@inheritdoc}
*/
public function fetchAll(?int $fetchMode = null, ...$args) : array
public function fetchAll(?int $fetchMode = null) : array
{
$rows = [];
while ($row = $this->fetch($fetchMode, ...$args)) {
while ($row = $this->fetch($fetchMode)) {
$rows[] = $row;
}

Expand All @@ -130,18 +121,14 @@ public function fetchAll(?int $fetchMode = null, ...$args) : array
/**
* {@inheritdoc}
*/
public function fetchColumn(int $columnIndex = 0)
public function fetchColumn()
{
$row = $this->fetch(FetchMode::NUMERIC);

if ($row === false) {
return false;
}

if (! array_key_exists($columnIndex, $row)) {
throw InvalidColumnIndex::new($columnIndex, count($row));
}

return $row[$columnIndex];
return $row[0];
}
}
22 changes: 6 additions & 16 deletions lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,11 @@
use ArrayIterator;
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Exception\InvalidColumnIndex;
use Doctrine\DBAL\FetchMode;
use InvalidArgumentException;
use IteratorAggregate;
use function array_key_exists;
use function array_merge;
use function array_values;
use function count;
use function reset;

/**
Expand Down Expand Up @@ -93,10 +90,7 @@ public function columnCount() : int
return $this->statement->columnCount();
}

/**
* {@inheritdoc}
*/
public function setFetchMode(int $fetchMode, ...$args) : void
public function setFetchMode(int $fetchMode) : void
{
$this->defaultFetchMode = $fetchMode;
}
Expand All @@ -114,7 +108,7 @@ public function getIterator()
/**
* {@inheritdoc}
*/
public function fetch(?int $fetchMode = null, ...$args)
public function fetch(?int $fetchMode = null)
{
if ($this->data === null) {
$this->data = [];
Expand Down Expand Up @@ -154,9 +148,9 @@ public function fetch(?int $fetchMode = null, ...$args)
/**
* {@inheritdoc}
*/
public function fetchAll(?int $fetchMode = null, ...$args) : array
public function fetchAll(?int $fetchMode = null) : array
{
$data = $this->statement->fetchAll($fetchMode, ...$args);
$data = $this->statement->fetchAll($fetchMode);

if ($fetchMode === FetchMode::COLUMN) {
foreach ($data as $key => $value) {
Expand All @@ -173,19 +167,15 @@ public function fetchAll(?int $fetchMode = null, ...$args) : array
/**
* {@inheritdoc}
*/
public function fetchColumn(int $columnIndex = 0)
public function fetchColumn()
{
$row = $this->fetch(FetchMode::NUMERIC);

if ($row === false) {
return false;
}

if (! array_key_exists($columnIndex, $row)) {
throw InvalidColumnIndex::new($columnIndex, count($row));
}

return $row[$columnIndex];
return $row[0];
}

/**
Expand Down
11 changes: 5 additions & 6 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,18 +491,17 @@ public function fetchArray(string $query, array $params = [], array $types = [])
* Prepares and executes an SQL query and returns the value of a single column
* of the first row of the result.
*
* @param string $query The SQL query to be executed.
* @param array<int, mixed>|array<string, mixed> $params The prepared statement params.
* @param int $column The 0-indexed column number to retrieve.
* @param array<int, int|string>|array<string, int|string> $types The query parameter types.
* @param string $query The SQL query to be executed.
* @param array<int, mixed>|array<string, mixed> $params The prepared statement params.
* @param array <int, int|string>|array<string, int|string> $types The query parameter types.
*
* @return mixed|false False is returned if no rows are found.
*
* @throws DBALException
*/
public function fetchColumn(string $query, array $params = [], int $column = 0, array $types = [])
public function fetchColumn(string $query, array $params = [], array $types = [])
{
return $this->executeQuery($query, $params, $types)->fetchColumn($column);
return $this->executeQuery($query, $params, $types)->fetchColumn();
}

/**
Expand Down
Loading

0 comments on commit be09d0f

Please sign in to comment.