Skip to content

Commit 6d95941

Browse files
authored
Merge pull request #3483 from morozov/row-count
Moved rowCount() from Statement to ResultStatement
2 parents 56546b9 + 6d2a3ce commit 6d95941

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

UPGRADE.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Upgrade to 3.0
22

3+
## BC BREAK `Statement::rowCount()` is moved.
4+
5+
`Statement::rowCount()` has been moved to the `ResultStatement` interface where it belongs by definition.
6+
37
## BC BREAK Transaction-related `Statement` methods return `void`.
48

59
`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:
6165

6266
* `Doctrine\DBAL\Platforms\SQLAnywhere11Platform`
6367
* `Doctrine\DBAL\Platforms\SQLAnywhere12Platform`
64-
* `Doctrine\DBAL\Platforms\SQLAnywhere16Platform`
68+
* `Doctrine\DBAL\Platforms\SQLAnywhere16Platform`
6569
* `Doctrine\DBAL\Platforms\Keywords\SQLAnywhere11Keywords`
6670
* `Doctrine\DBAL\Platforms\Keywords\SQLAnywhere12Keywords`
6771
* `Doctrine\DBAL\Platforms\Keywords\SQLAnywhere16Keywords`
@@ -215,7 +219,7 @@ This method now throws SPL ``UnexpectedValueException`` instead of accidentally
215219

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

218-
``Doctrine\DBAL\Connection::TRANSACTION_*`` were moved into ``Doctrine\DBAL\TransactionIsolationLevel`` class without the ``TRANSACTION_`` prefix.
222+
``Doctrine\DBAL\Connection::TRANSACTION_*`` were moved into ``Doctrine\DBAL\TransactionIsolationLevel`` class without the ``TRANSACTION_`` prefix.
219223

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

lib/Doctrine/DBAL/Cache/ArrayStatement.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ public function columnCount()
5757
return $this->columnCount;
5858
}
5959

60+
/**
61+
* {@inheritdoc}
62+
*/
63+
public function rowCount() : int
64+
{
65+
if ($this->data === null) {
66+
return 0;
67+
}
68+
69+
return count($this->data);
70+
}
71+
6072
/**
6173
* {@inheritdoc}
6274
*/

lib/Doctrine/DBAL/Cache/ResultCacheStatement.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,12 @@
66
use Doctrine\Common\Cache\Cache;
77
use Doctrine\DBAL\DBALException;
88
use Doctrine\DBAL\Driver\ResultStatement;
9-
use Doctrine\DBAL\Driver\Statement;
109
use Doctrine\DBAL\FetchMode;
1110
use InvalidArgumentException;
1211
use IteratorAggregate;
1312
use function array_key_exists;
1413
use function array_merge;
1514
use function array_values;
16-
use function assert;
1715
use function count;
1816
use function reset;
1917

@@ -206,8 +204,6 @@ public function fetchColumn($columnIndex = 0)
206204
*/
207205
public function rowCount() : int
208206
{
209-
assert($this->statement instanceof Statement);
210-
211207
return $this->statement->rowCount();
212208
}
213209
}

lib/Doctrine/DBAL/Driver/ResultStatement.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,17 @@ public function closeCursor();
2525
*/
2626
public function columnCount();
2727

28+
/**
29+
* Returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
30+
* executed by the corresponding object.
31+
*
32+
* If the last SQL statement executed by the associated Statement object was a SELECT statement,
33+
* some databases may return the number of rows returned by that statement. However,
34+
* this behaviour is not guaranteed for all databases and should not be
35+
* relied on for portable applications.
36+
*/
37+
public function rowCount() : int;
38+
2839
/**
2940
* Sets the fetch mode to use while iterating this statement.
3041
*

lib/Doctrine/DBAL/Driver/Statement.php

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,4 @@ public function errorInfo();
8888
* @return bool TRUE on success or FALSE on failure.
8989
*/
9090
public function execute($params = null);
91-
92-
/**
93-
* Returns the number of rows affected by the last DELETE, INSERT, or UPDATE statement
94-
* executed by the corresponding object.
95-
*
96-
* If the last SQL statement executed by the associated Statement object was a SELECT statement,
97-
* some databases may return the number of rows returned by that statement. However,
98-
* this behaviour is not guaranteed for all databases and should not be
99-
* relied on for portable applications.
100-
*
101-
* @return int The number of rows.
102-
*/
103-
public function rowCount() : int;
10491
}

0 commit comments

Comments
 (0)