From 6d2a3ce939dbc5058ef29926e9d52d227a7b9e9f Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 24 Jan 2019 10:46:28 -0800 Subject: [PATCH] Moved rowCount() from Statement to ResultStatement --- UPGRADE.md | 8 ++++++-- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 12 ++++++++++++ lib/Doctrine/DBAL/Cache/ResultCacheStatement.php | 4 ---- lib/Doctrine/DBAL/Driver/ResultStatement.php | 11 +++++++++++ lib/Doctrine/DBAL/Driver/Statement.php | 13 ------------- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 8ee715f65fd..1ac66888165 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -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. @@ -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` @@ -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 diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index 27ca4a83ccb..18d660be1ca 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -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} */ diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 66461976f75..c0b28bb8740 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -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; @@ -206,8 +204,6 @@ public function fetchColumn($columnIndex = 0) */ public function rowCount() : int { - assert($this->statement instanceof Statement); - return $this->statement->rowCount(); } } diff --git a/lib/Doctrine/DBAL/Driver/ResultStatement.php b/lib/Doctrine/DBAL/Driver/ResultStatement.php index 17bc28e37ef..321778e1c60 100644 --- a/lib/Doctrine/DBAL/Driver/ResultStatement.php +++ b/lib/Doctrine/DBAL/Driver/ResultStatement.php @@ -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. * diff --git a/lib/Doctrine/DBAL/Driver/Statement.php b/lib/Doctrine/DBAL/Driver/Statement.php index fd3c0bd0bf6..c5f2e3e2546 100644 --- a/lib/Doctrine/DBAL/Driver/Statement.php +++ b/lib/Doctrine/DBAL/Driver/Statement.php @@ -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; }