Skip to content

Commit

Permalink
Merge pull request #3483 from morozov/row-count
Browse files Browse the repository at this point in the history
Moved rowCount() from Statement to ResultStatement
  • Loading branch information
morozov authored Mar 15, 2019
2 parents 56546b9 + 6d2a3ce commit 6d95941
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 19 deletions.
8 changes: 6 additions & 2 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Upgrade to 3.0

## BC BREAK `Statement::rowCount()` is moved.

`Statement::rowCount()` has been moved to the `ResultStatement` interface where it belongs by definition.

## BC BREAK Transaction-related `Statement` methods return `void`.

`Statement::beginTransaction()`, `::commit()` and `::rollBack()` no longer return a boolean value. They will throw a `DriverException` in case of failure.
Expand Down Expand Up @@ -61,7 +65,7 @@ The following classes have been removed:

* `Doctrine\DBAL\Platforms\SQLAnywhere11Platform`
* `Doctrine\DBAL\Platforms\SQLAnywhere12Platform`
* `Doctrine\DBAL\Platforms\SQLAnywhere16Platform`
* `Doctrine\DBAL\Platforms\SQLAnywhere16Platform`
* `Doctrine\DBAL\Platforms\Keywords\SQLAnywhere11Keywords`
* `Doctrine\DBAL\Platforms\Keywords\SQLAnywhere12Keywords`
* `Doctrine\DBAL\Platforms\Keywords\SQLAnywhere16Keywords`
Expand Down Expand Up @@ -215,7 +219,7 @@ This method now throws SPL ``UnexpectedValueException`` instead of accidentally

## Doctrine\DBAL\Connection::TRANSACTION_* constants deprecated

``Doctrine\DBAL\Connection::TRANSACTION_*`` were moved into ``Doctrine\DBAL\TransactionIsolationLevel`` class without the ``TRANSACTION_`` prefix.
``Doctrine\DBAL\Connection::TRANSACTION_*`` were moved into ``Doctrine\DBAL\TransactionIsolationLevel`` class without the ``TRANSACTION_`` prefix.

## DEPRECATION: direct usage of the PDO APIs in the DBAL API

Expand Down
12 changes: 12 additions & 0 deletions lib/Doctrine/DBAL/Cache/ArrayStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public function columnCount()
return $this->columnCount;
}

/**
* {@inheritdoc}
*/
public function rowCount() : int
{
if ($this->data === null) {
return 0;
}

return count($this->data);
}

/**
* {@inheritdoc}
*/
Expand Down
4 changes: 0 additions & 4 deletions lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
use Doctrine\Common\Cache\Cache;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\FetchMode;
use InvalidArgumentException;
use IteratorAggregate;
use function array_key_exists;
use function array_merge;
use function array_values;
use function assert;
use function count;
use function reset;

Expand Down Expand Up @@ -206,8 +204,6 @@ public function fetchColumn($columnIndex = 0)
*/
public function rowCount() : int
{
assert($this->statement instanceof Statement);

return $this->statement->rowCount();
}
}
11 changes: 11 additions & 0 deletions lib/Doctrine/DBAL/Driver/ResultStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@ public function closeCursor();
*/
public function columnCount();

/**
* Returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
* executed by the corresponding object.
*
* If the last SQL statement executed by the associated Statement object was a SELECT statement,
* some databases may return the number of rows returned by that statement. However,
* this behaviour is not guaranteed for all databases and should not be
* relied on for portable applications.
*/
public function rowCount() : int;

/**
* Sets the fetch mode to use while iterating this statement.
*
Expand Down
13 changes: 0 additions & 13 deletions lib/Doctrine/DBAL/Driver/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,4 @@ public function errorInfo();
* @return bool TRUE on success or FALSE on failure.
*/
public function execute($params = null);

/**
* Returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
* executed by the corresponding object.
*
* If the last SQL statement executed by the associated Statement object was a SELECT statement,
* some databases may return the number of rows returned by that statement. However,
* this behaviour is not guaranteed for all databases and should not be
* relied on for portable applications.
*
* @return int The number of rows.
*/
public function rowCount() : int;
}

0 comments on commit 6d95941

Please sign in to comment.