From 5df51cb367d4e1d766d4cf2830e847fb7cea3693 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 27 May 2020 21:17:56 -0700 Subject: [PATCH] Moved rowCount() from Statement to ResultStatement --- UPGRADE.md | 4 ++++ src/Cache/ArrayStatement.php | 9 +++++++++ src/Cache/ResultCacheStatement.php | 5 +++++ src/Driver/ResultStatement.php | 11 +++++++++++ src/Driver/Statement.php | 13 ------------- 5 files changed, 29 insertions(+), 13 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 970d8b9a110..6048a702d30 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. + ## Removed `FetchMode` and the corresponding methods 1. The `FetchMode` class and the `setFetchMode()` method of the `Connection` and `Statement` interfaces are removed. diff --git a/src/Cache/ArrayStatement.php b/src/Cache/ArrayStatement.php index f7098df0f07..8a48074bb3b 100644 --- a/src/Cache/ArrayStatement.php +++ b/src/Cache/ArrayStatement.php @@ -50,6 +50,15 @@ public function columnCount() return $this->columnCount; } + public function rowCount() : int + { + if ($this->data === null) { + return 0; + } + + return count($this->data); + } + /** * {@inheritdoc} */ diff --git a/src/Cache/ResultCacheStatement.php b/src/Cache/ResultCacheStatement.php index cf46779a143..bc41f739087 100644 --- a/src/Cache/ResultCacheStatement.php +++ b/src/Cache/ResultCacheStatement.php @@ -94,6 +94,11 @@ public function columnCount() return $this->statement->columnCount(); } + public function rowCount() : int + { + return $this->statement->rowCount(); + } + /** * {@inheritdoc} */ diff --git a/src/Driver/ResultStatement.php b/src/Driver/ResultStatement.php index 8fe6be076b4..3a065ec6318 100644 --- a/src/Driver/ResultStatement.php +++ b/src/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; + /** * Returns the next row of a result set as a numeric array or FALSE if there are no more rows. * diff --git a/src/Driver/Statement.php b/src/Driver/Statement.php index 4fb7865e28f..2bd1e879470 100644 --- a/src/Driver/Statement.php +++ b/src/Driver/Statement.php @@ -72,17 +72,4 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l * @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; }