Skip to content

Commit 3cfb57d

Browse files
authored
Merge pull request #4049 from morozov/result
Replace forward-compatible ResultStatement interfaces with Result
2 parents 11e8ed4 + e7c7cb1 commit 3cfb57d

20 files changed

+295
-168
lines changed

UPGRADE.md

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
# Upgrade to 2.11
22

3+
## Deprecated `ArrayStatement` and `ResultCacheStatement` classes.
4+
5+
The `ArrayStatement` and `ResultCacheStatement` classes are deprecated. In a future major release they will be renamed and marked internal as implementation details of the caching layer.
6+
7+
## Deprecated `ResultStatement` interface
8+
9+
1. The `ResultStatement` interface is deprecated. Use the `Driver\Result` and `Abstraction\Result` interfaces instead.
10+
2. `ResultStatement::closeCursor()` is deprecated in favor of `Result::free()`.
11+
312
## Deprecated `FetchMode` and the corresponding methods
413

514
1. The `FetchMode` class and the `setFetchMode()` method of the `Connection` and `Statement` interfaces are deprecated.
6-
2. The `Statement::fetch()` method is deprecated in favor of `fetchNumeric()`, `fetchAssociative()` and `fetchOne()`.
7-
3. The `Statement::fetchAll()` method is deprecated in favor of `fetchAllNumeric()`, `fetchAllAssociative()` and `fetchFirstColumn()`.
8-
4. The `Statement::fetchColumn()` method is deprecated in favor of `fetchOne()`.
15+
2. The `Statement::fetch()` method is deprecated in favor of `Result::fetchNumeric()`, `::fetchAssociative()` and `::fetchOne()`.
16+
3. The `Statement::fetchAll()` method is deprecated in favor of `Result::fetchAllNumeric()`, `::fetchAllAssociative()` and `::fetchFirstColumn()`.
17+
4. The `Statement::fetchColumn()` method is deprecated in favor of `Result::fetchOne()`.
918
5. The `Connection::fetchArray()` and `fetchAssoc()` method are deprecated in favor of `fetchNumeric()` and `fetchAssociative()` respectively.
10-
6. The `StatementIterator` class and the usage of a `Statement` object as `Traversable` is deprecated in favor of `iterateNumeric()`, `iterateAssociative()` and `iterateColumn()`.
19+
6. The `StatementIterator` class and the usage of a `Statement` object as `Traversable` is deprecated in favor of `Result::iterateNumeric()`, `::iterateAssociative()` and `::iterateColumn()`.
1120
7. Fetching data in mixed mode (`FetchMode::MIXED`) is deprecated.
1221

1322
## Deprecated `Connection::project()`

lib/Doctrine/DBAL/ForwardCompatibility/ResultStatement.php renamed to lib/Doctrine/DBAL/Abstraction/Result.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
declare(strict_types=1);
44

5-
namespace Doctrine\DBAL\ForwardCompatibility;
5+
namespace Doctrine\DBAL\Abstraction;
66

77
use Doctrine\DBAL\DBALException;
8-
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as BaseResultStatement;
8+
use Doctrine\DBAL\Driver\Result as DriverResult;
99
use Traversable;
1010

1111
/**
12-
* Forward compatibility extension for the DBAL ResultStatement interface.
12+
* Abstraction-level result statement execution result. Provides additional methods on top
13+
* of the driver-level interface.
1314
*/
14-
interface ResultStatement extends BaseResultStatement
15+
interface Result extends DriverResult
1516
{
1617
/**
1718
* Returns an iterator over the result set rows represented as numeric arrays.

lib/Doctrine/DBAL/Cache/ArrayStatement.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
use ArrayIterator;
66
use Doctrine\DBAL\Driver\FetchUtils;
7+
use Doctrine\DBAL\Driver\Result;
78
use Doctrine\DBAL\Driver\ResultStatement;
89
use Doctrine\DBAL\FetchMode;
9-
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
1010
use InvalidArgumentException;
1111
use IteratorAggregate;
1212
use PDO;
@@ -16,7 +16,10 @@
1616
use function count;
1717
use function reset;
1818

19-
class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompatibleResultStatement
19+
/**
20+
* @deprecated
21+
*/
22+
class ArrayStatement implements IteratorAggregate, ResultStatement, Result
2023
{
2124
/** @var mixed[] */
2225
private $data;
@@ -45,14 +48,24 @@ public function __construct(array $data)
4548

4649
/**
4750
* {@inheritdoc}
51+
*
52+
* @deprecated Use free() instead.
4853
*/
4954
public function closeCursor()
5055
{
51-
unset($this->data);
56+
$this->free();
5257

5358
return true;
5459
}
5560

61+
/**
62+
* {@inheritdoc}
63+
*/
64+
public function rowCount()
65+
{
66+
return count($this->data);
67+
}
68+
5669
/**
5770
* {@inheritdoc}
5871
*/
@@ -210,6 +223,11 @@ public function fetchFirstColumn(): array
210223
return FetchUtils::fetchFirstColumn($this);
211224
}
212225

226+
public function free(): void
227+
{
228+
$this->data = [];
229+
}
230+
213231
/**
214232
* @return mixed|false
215233
*/

lib/Doctrine/DBAL/Cache/ResultCacheStatement.php

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66
use Doctrine\Common\Cache\Cache;
77
use Doctrine\DBAL\Driver\DriverException;
88
use Doctrine\DBAL\Driver\FetchUtils;
9+
use Doctrine\DBAL\Driver\Result;
910
use Doctrine\DBAL\Driver\ResultStatement;
1011
use Doctrine\DBAL\Driver\Statement;
1112
use Doctrine\DBAL\FetchMode;
12-
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
1313
use InvalidArgumentException;
1414
use IteratorAggregate;
1515
use PDO;
@@ -32,8 +32,10 @@
3232
*
3333
* Also you have to realize that the cache will load the whole result into memory at once to ensure 2.
3434
* This means that the memory usage for cached results might increase by using this feature.
35+
*
36+
* @deprecated
3537
*/
36-
class ResultCacheStatement implements IteratorAggregate, ResultStatement, ForwardCompatibleResultStatement
38+
class ResultCacheStatement implements IteratorAggregate, ResultStatement, Result
3739
{
3840
/** @var Cache */
3941
private $resultCache;
@@ -72,12 +74,12 @@ public function __construct(ResultStatement $stmt, Cache $resultCache, $cacheKey
7274

7375
/**
7476
* {@inheritdoc}
77+
*
78+
* @deprecated Use free() instead.
7579
*/
7680
public function closeCursor()
7781
{
78-
$this->statement->closeCursor();
79-
80-
$this->data = null;
82+
$this->free();
8183

8284
return true;
8385
}
@@ -234,7 +236,7 @@ public function fetchOne()
234236
*/
235237
public function fetchAllNumeric(): array
236238
{
237-
if ($this->statement instanceof ForwardCompatibleResultStatement) {
239+
if ($this->statement instanceof Result) {
238240
$data = $this->statement->fetchAllAssociative();
239241
} else {
240242
$data = $this->statement->fetchAll(FetchMode::ASSOCIATIVE);
@@ -250,7 +252,7 @@ public function fetchAllNumeric(): array
250252
*/
251253
public function fetchAllAssociative(): array
252254
{
253-
if ($this->statement instanceof ForwardCompatibleResultStatement) {
255+
if ($this->statement instanceof Result) {
254256
$data = $this->statement->fetchAllAssociative();
255257
} else {
256258
$data = $this->statement->fetchAll(FetchMode::ASSOCIATIVE);
@@ -287,6 +289,11 @@ public function rowCount()
287289
return $this->statement->rowCount();
288290
}
289291

292+
public function free(): void
293+
{
294+
$this->data = null;
295+
}
296+
290297
/**
291298
* @return array<string,mixed>|false
292299
*
@@ -298,7 +305,7 @@ private function doFetch()
298305
$this->data = [];
299306
}
300307

301-
if ($this->statement instanceof ForwardCompatibleResultStatement) {
308+
if ($this->statement instanceof Result) {
302309
$row = $this->statement->fetchAssociative();
303310
} else {
304311
$row = $this->statement->fetch(FetchMode::ASSOCIATIVE);

lib/Doctrine/DBAL/Connection.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Closure;
66
use Doctrine\Common\EventManager;
7+
use Doctrine\DBAL\Abstraction\Result;
78
use Doctrine\DBAL\Cache\ArrayStatement;
89
use Doctrine\DBAL\Cache\CacheException;
910
use Doctrine\DBAL\Cache\QueryCacheProfile;
@@ -14,7 +15,6 @@
1415
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
1516
use Doctrine\DBAL\Driver\Statement as DriverStatement;
1617
use Doctrine\DBAL\Exception\InvalidArgumentException;
17-
use Doctrine\DBAL\ForwardCompatibility\ResultStatement as ForwardCompatibleResultStatement;
1818
use Doctrine\DBAL\Platforms\AbstractPlatform;
1919
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
2020
use Doctrine\DBAL\Query\QueryBuilder;
@@ -616,7 +616,7 @@ public function fetchAssociative(string $query, array $params = [], array $types
616616
try {
617617
$stmt = $this->executeQuery($query, $params, $types);
618618

619-
if ($stmt instanceof ForwardCompatibleResultStatement) {
619+
if ($stmt instanceof Result) {
620620
return $stmt->fetchAssociative();
621621
}
622622

@@ -643,7 +643,7 @@ public function fetchNumeric(string $query, array $params = [], array $types = [
643643
try {
644644
$stmt = $this->executeQuery($query, $params, $types);
645645

646-
if ($stmt instanceof ForwardCompatibleResultStatement) {
646+
if ($stmt instanceof Result) {
647647
return $stmt->fetchNumeric();
648648
}
649649

@@ -670,7 +670,7 @@ public function fetchOne(string $query, array $params = [], array $types = [])
670670
try {
671671
$stmt = $this->executeQuery($query, $params, $types);
672672

673-
if ($stmt instanceof ForwardCompatibleResultStatement) {
673+
if ($stmt instanceof Result) {
674674
return $stmt->fetchOne();
675675
}
676676

@@ -956,7 +956,7 @@ public function fetchAllNumeric(string $query, array $params = [], array $types
956956
try {
957957
$stmt = $this->executeQuery($query, $params, $types);
958958

959-
if ($stmt instanceof ForwardCompatibleResultStatement) {
959+
if ($stmt instanceof Result) {
960960
return $stmt->fetchAllNumeric();
961961
}
962962

@@ -982,7 +982,7 @@ public function fetchAllAssociative(string $query, array $params = [], array $ty
982982
try {
983983
$stmt = $this->executeQuery($query, $params, $types);
984984

985-
if ($stmt instanceof ForwardCompatibleResultStatement) {
985+
if ($stmt instanceof Result) {
986986
return $stmt->fetchAllAssociative();
987987
}
988988

@@ -1008,7 +1008,7 @@ public function fetchFirstColumn(string $query, array $params = [], array $types
10081008
try {
10091009
$stmt = $this->executeQuery($query, $params, $types);
10101010

1011-
if ($stmt instanceof ForwardCompatibleResultStatement) {
1011+
if ($stmt instanceof Result) {
10121012
return $stmt->fetchFirstColumn();
10131013
}
10141014

@@ -1034,7 +1034,7 @@ public function iterateNumeric(string $query, array $params = [], array $types =
10341034
try {
10351035
$stmt = $this->executeQuery($query, $params, $types);
10361036

1037-
if ($stmt instanceof ForwardCompatibleResultStatement) {
1037+
if ($stmt instanceof Result) {
10381038
yield from $stmt->iterateNumeric();
10391039
} else {
10401040
while (($row = $stmt->fetch(FetchMode::NUMERIC)) !== false) {
@@ -1062,7 +1062,7 @@ public function iterateAssociative(string $query, array $params = [], array $typ
10621062
try {
10631063
$stmt = $this->executeQuery($query, $params, $types);
10641064

1065-
if ($stmt instanceof ForwardCompatibleResultStatement) {
1065+
if ($stmt instanceof Result) {
10661066
yield from $stmt->iterateAssociative();
10671067
} else {
10681068
while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE)) !== false) {
@@ -1090,7 +1090,7 @@ public function iterateColumn(string $query, array $params = [], array $types =
10901090
try {
10911091
$stmt = $this->executeQuery($query, $params, $types);
10921092

1093-
if ($stmt instanceof ForwardCompatibleResultStatement) {
1093+
if ($stmt instanceof Result) {
10941094
yield from $stmt->iterateColumn();
10951095
} else {
10961096
while (($value = $stmt->fetch(FetchMode::COLUMN)) !== false) {

lib/Doctrine/DBAL/Driver/FetchUtils.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
namespace Doctrine\DBAL\Driver;
66

7-
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement;
8-
97
/**
108
* @internal
119
*/
@@ -16,9 +14,9 @@ final class FetchUtils
1614
*
1715
* @throws DriverException
1816
*/
19-
public static function fetchOne(ResultStatement $stmt)
17+
public static function fetchOne(Result $result)
2018
{
21-
$row = $stmt->fetchNumeric();
19+
$row = $result->fetchNumeric();
2220

2321
if ($row === false) {
2422
return false;
@@ -32,11 +30,11 @@ public static function fetchOne(ResultStatement $stmt)
3230
*
3331
* @throws DriverException
3432
*/
35-
public static function fetchAllNumeric(ResultStatement $stmt): array
33+
public static function fetchAllNumeric(Result $result): array
3634
{
3735
$rows = [];
3836

39-
while (($row = $stmt->fetchNumeric()) !== false) {
37+
while (($row = $result->fetchNumeric()) !== false) {
4038
$rows[] = $row;
4139
}
4240

@@ -48,11 +46,11 @@ public static function fetchAllNumeric(ResultStatement $stmt): array
4846
*
4947
* @throws DriverException
5048
*/
51-
public static function fetchAllAssociative(ResultStatement $stmt): array
49+
public static function fetchAllAssociative(Result $result): array
5250
{
5351
$rows = [];
5452

55-
while (($row = $stmt->fetchAssociative()) !== false) {
53+
while (($row = $result->fetchAssociative()) !== false) {
5654
$rows[] = $row;
5755
}
5856

@@ -64,11 +62,11 @@ public static function fetchAllAssociative(ResultStatement $stmt): array
6462
*
6563
* @throws DriverException
6664
*/
67-
public static function fetchFirstColumn(ResultStatement $stmt): array
65+
public static function fetchFirstColumn(Result $result): array
6866
{
6967
$rows = [];
7068

71-
while (($row = $stmt->fetchOne()) !== false) {
69+
while (($row = $result->fetchOne()) !== false) {
7270
$rows[] = $row;
7371
}
7472

lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
namespace Doctrine\DBAL\Driver\IBMDB2;
44

55
use Doctrine\DBAL\Driver\FetchUtils;
6+
use Doctrine\DBAL\Driver\Result;
67
use Doctrine\DBAL\Driver\Statement;
78
use Doctrine\DBAL\Driver\StatementIterator;
89
use Doctrine\DBAL\FetchMode;
9-
use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement;
1010
use Doctrine\DBAL\ParameterType;
1111
use IteratorAggregate;
1212
use PDO;
@@ -50,7 +50,7 @@
5050
use const DB2_PARAM_FILE;
5151
use const DB2_PARAM_IN;
5252

53-
class DB2Statement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement
53+
class DB2Statement implements IteratorAggregate, Statement, Result
5454
{
5555
/** @var resource */
5656
private $stmt;
@@ -147,6 +147,8 @@ private function bind($position, &$variable, int $parameterType, int $dataType):
147147

148148
/**
149149
* {@inheritdoc}
150+
*
151+
* @deprecated Use free() instead.
150152
*/
151153
public function closeCursor()
152154
{
@@ -426,6 +428,15 @@ public function rowCount()
426428
return @db2_num_rows($this->stmt) ? : 0;
427429
}
428430

431+
public function free(): void
432+
{
433+
$this->bindParam = [];
434+
435+
db2_free_result($this->stmt);
436+
437+
$this->result = false;
438+
}
439+
429440
/**
430441
* Casts a stdClass object to the given class name mapping its' properties.
431442
*

0 commit comments

Comments
 (0)