From 0d9ea40ab628078d5635afc6287a04c1c7f10a65 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 5 Jun 2020 17:54:05 -0700 Subject: [PATCH 1/5] Rename forward-compatible ResultStatement interfaces to Result --- UPGRADE.md | 12 ++++++---- .../Result.php} | 9 ++++---- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 4 ++-- .../DBAL/Cache/ResultCacheStatement.php | 10 ++++----- lib/Doctrine/DBAL/Connection.php | 20 ++++++++--------- lib/Doctrine/DBAL/Driver/FetchUtils.php | 18 +++++++-------- .../DBAL/Driver/IBMDB2/DB2Statement.php | 4 ++-- .../DBAL/Driver/Mysqli/MysqliStatement.php | 4 ++-- .../DBAL/Driver/OCI8/OCI8Statement.php | 4 ++-- .../DBAL/Driver/PDOSqlsrv/Connection.php | 4 ++-- lib/Doctrine/DBAL/Driver/PDOStatement.php | 3 +-- .../ResultStatement.php => Driver/Result.php} | 19 ++++++++-------- .../SQLAnywhere/SQLAnywhereConnection.php | 6 ++--- .../SQLAnywhere/SQLAnywhereStatement.php | 4 ++-- .../DBAL/Driver/SQLSrv/SQLSrvConnection.php | 4 ++-- .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 4 ++-- lib/Doctrine/DBAL/Portability/Statement.php | 16 +++++++------- lib/Doctrine/DBAL/Statement.php | 22 +++++++++---------- 18 files changed, 84 insertions(+), 83 deletions(-) rename lib/Doctrine/DBAL/{ForwardCompatibility/ResultStatement.php => Abstraction/Result.php} (75%) rename lib/Doctrine/DBAL/{ForwardCompatibility/Driver/ResultStatement.php => Driver/Result.php} (58%) diff --git a/UPGRADE.md b/UPGRADE.md index 15f11853f02..46e4666b21c 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,13 +1,17 @@ # Upgrade to 2.11 +## Deprecated `ResultStatement` interface + +The `ResultStatement` interface is deprecated. Use the `Driver\Result` and `Abstraction\Result` interfaces instead. + ## Deprecated `FetchMode` and the corresponding methods 1. The `FetchMode` class and the `setFetchMode()` method of the `Connection` and `Statement` interfaces are deprecated. -2. The `Statement::fetch()` method is deprecated in favor of `fetchNumeric()`, `fetchAssociative()` and `fetchOne()`. -3. The `Statement::fetchAll()` method is deprecated in favor of `fetchAllNumeric()`, `fetchAllAssociative()` and `fetchFirstColumn()`. -4. The `Statement::fetchColumn()` method is deprecated in favor of `fetchOne()`. +2. The `Statement::fetch()` method is deprecated in favor of `Result::fetchNumeric()`, `::fetchAssociative()` and `::fetchOne()`. +3. The `Statement::fetchAll()` method is deprecated in favor of `Result::fetchAllNumeric()`, `::fetchAllAssociative()` and `::fetchFirstColumn()`. +4. The `Statement::fetchColumn()` method is deprecated in favor of `Result::fetchOne()`. 5. The `Connection::fetchArray()` and `fetchAssoc()` method are deprecated in favor of `fetchNumeric()` and `fetchAssociative()` respectively. -6. The `StatementIterator` class and the usage of a `Statement` object as `Traversable` is deprecated in favor of `iterateNumeric()`, `iterateAssociative()` and `iterateColumn()`. +6. The `StatementIterator` class and the usage of a `Statement` object as `Traversable` is deprecated in favor of `Result::iterateNumeric()`, `::iterateAssociative()` and `::iterateColumn()`. 7. Fetching data in mixed mode (`FetchMode::MIXED`) is deprecated. ## Deprecated `Connection::project()` diff --git a/lib/Doctrine/DBAL/ForwardCompatibility/ResultStatement.php b/lib/Doctrine/DBAL/Abstraction/Result.php similarity index 75% rename from lib/Doctrine/DBAL/ForwardCompatibility/ResultStatement.php rename to lib/Doctrine/DBAL/Abstraction/Result.php index 041c4098419..5e163785405 100644 --- a/lib/Doctrine/DBAL/ForwardCompatibility/ResultStatement.php +++ b/lib/Doctrine/DBAL/Abstraction/Result.php @@ -2,16 +2,17 @@ declare(strict_types=1); -namespace Doctrine\DBAL\ForwardCompatibility; +namespace Doctrine\DBAL\Abstraction; use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as BaseResultStatement; +use Doctrine\DBAL\Driver\Result as DriverResult; use Traversable; /** - * Forward compatibility extension for the DBAL ResultStatement interface. + * Abstraction-level result statement execution result. Provides additional methods on top + * of the driver-level interface. */ -interface ResultStatement extends BaseResultStatement +interface Result extends DriverResult { /** * Returns an iterator over the result set rows represented as numeric arrays. diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index 50c4edae861..f9bef8d73d7 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -4,9 +4,9 @@ use ArrayIterator; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\FetchMode; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use InvalidArgumentException; use IteratorAggregate; use PDO; @@ -16,7 +16,7 @@ use function count; use function reset; -class ArrayStatement implements IteratorAggregate, ResultStatement, ForwardCompatibleResultStatement +class ArrayStatement implements IteratorAggregate, ResultStatement, Result { /** @var mixed[] */ private $data; diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index dd8d62fde83..78d97d25cdf 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -6,10 +6,10 @@ use Doctrine\Common\Cache\Cache; use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\FetchMode; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use InvalidArgumentException; use IteratorAggregate; use PDO; @@ -33,7 +33,7 @@ * Also you have to realize that the cache will load the whole result into memory at once to ensure 2. * This means that the memory usage for cached results might increase by using this feature. */ -class ResultCacheStatement implements IteratorAggregate, ResultStatement, ForwardCompatibleResultStatement +class ResultCacheStatement implements IteratorAggregate, ResultStatement, Result { /** @var Cache */ private $resultCache; @@ -234,7 +234,7 @@ public function fetchOne() */ public function fetchAllNumeric(): array { - if ($this->statement instanceof ForwardCompatibleResultStatement) { + if ($this->statement instanceof Result) { $data = $this->statement->fetchAllAssociative(); } else { $data = $this->statement->fetchAll(FetchMode::ASSOCIATIVE); @@ -250,7 +250,7 @@ public function fetchAllNumeric(): array */ public function fetchAllAssociative(): array { - if ($this->statement instanceof ForwardCompatibleResultStatement) { + if ($this->statement instanceof Result) { $data = $this->statement->fetchAllAssociative(); } else { $data = $this->statement->fetchAll(FetchMode::ASSOCIATIVE); @@ -298,7 +298,7 @@ private function doFetch() $this->data = []; } - if ($this->statement instanceof ForwardCompatibleResultStatement) { + if ($this->statement instanceof Result) { $row = $this->statement->fetchAssociative(); } else { $row = $this->statement->fetch(FetchMode::ASSOCIATIVE); diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 32a97d85809..0a0c8c40d99 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -4,6 +4,7 @@ use Closure; use Doctrine\Common\EventManager; +use Doctrine\DBAL\Abstraction\Result; use Doctrine\DBAL\Cache\ArrayStatement; use Doctrine\DBAL\Cache\CacheException; use Doctrine\DBAL\Cache\QueryCacheProfile; @@ -14,7 +15,6 @@ use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Exception\InvalidArgumentException; -use Doctrine\DBAL\ForwardCompatibility\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\QueryBuilder; @@ -616,7 +616,7 @@ public function fetchAssociative(string $query, array $params = [], array $types try { $stmt = $this->executeQuery($query, $params, $types); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { return $stmt->fetchAssociative(); } @@ -643,7 +643,7 @@ public function fetchNumeric(string $query, array $params = [], array $types = [ try { $stmt = $this->executeQuery($query, $params, $types); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { return $stmt->fetchNumeric(); } @@ -670,7 +670,7 @@ public function fetchOne(string $query, array $params = [], array $types = []) try { $stmt = $this->executeQuery($query, $params, $types); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { return $stmt->fetchOne(); } @@ -956,7 +956,7 @@ public function fetchAllNumeric(string $query, array $params = [], array $types try { $stmt = $this->executeQuery($query, $params, $types); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { return $stmt->fetchAllNumeric(); } @@ -982,7 +982,7 @@ public function fetchAllAssociative(string $query, array $params = [], array $ty try { $stmt = $this->executeQuery($query, $params, $types); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { return $stmt->fetchAllAssociative(); } @@ -1008,7 +1008,7 @@ public function fetchFirstColumn(string $query, array $params = [], array $types try { $stmt = $this->executeQuery($query, $params, $types); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { return $stmt->fetchFirstColumn(); } @@ -1034,7 +1034,7 @@ public function iterateNumeric(string $query, array $params = [], array $types = try { $stmt = $this->executeQuery($query, $params, $types); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { yield from $stmt->iterateNumeric(); } else { while (($row = $stmt->fetch(FetchMode::NUMERIC)) !== false) { @@ -1062,7 +1062,7 @@ public function iterateAssociative(string $query, array $params = [], array $typ try { $stmt = $this->executeQuery($query, $params, $types); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { yield from $stmt->iterateAssociative(); } else { while (($row = $stmt->fetch(FetchMode::ASSOCIATIVE)) !== false) { @@ -1090,7 +1090,7 @@ public function iterateColumn(string $query, array $params = [], array $types = try { $stmt = $this->executeQuery($query, $params, $types); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { yield from $stmt->iterateColumn(); } else { while (($value = $stmt->fetch(FetchMode::COLUMN)) !== false) { diff --git a/lib/Doctrine/DBAL/Driver/FetchUtils.php b/lib/Doctrine/DBAL/Driver/FetchUtils.php index 428b8174397..a94793e1157 100644 --- a/lib/Doctrine/DBAL/Driver/FetchUtils.php +++ b/lib/Doctrine/DBAL/Driver/FetchUtils.php @@ -4,8 +4,6 @@ namespace Doctrine\DBAL\Driver; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement; - /** * @internal */ @@ -16,9 +14,9 @@ final class FetchUtils * * @throws DriverException */ - public static function fetchOne(ResultStatement $stmt) + public static function fetchOne(Result $result) { - $row = $stmt->fetchNumeric(); + $row = $result->fetchNumeric(); if ($row === false) { return false; @@ -32,11 +30,11 @@ public static function fetchOne(ResultStatement $stmt) * * @throws DriverException */ - public static function fetchAllNumeric(ResultStatement $stmt): array + public static function fetchAllNumeric(Result $result): array { $rows = []; - while (($row = $stmt->fetchNumeric()) !== false) { + while (($row = $result->fetchNumeric()) !== false) { $rows[] = $row; } @@ -48,11 +46,11 @@ public static function fetchAllNumeric(ResultStatement $stmt): array * * @throws DriverException */ - public static function fetchAllAssociative(ResultStatement $stmt): array + public static function fetchAllAssociative(Result $result): array { $rows = []; - while (($row = $stmt->fetchAssociative()) !== false) { + while (($row = $result->fetchAssociative()) !== false) { $rows[] = $row; } @@ -64,11 +62,11 @@ public static function fetchAllAssociative(ResultStatement $stmt): array * * @throws DriverException */ - public static function fetchFirstColumn(ResultStatement $stmt): array + public static function fetchFirstColumn(Result $result): array { $rows = []; - while (($row = $stmt->fetchOne()) !== false) { + while (($row = $result->fetchOne()) !== false) { $rows[] = $row; } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 45959bdc35e..163accb5a70 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -3,10 +3,10 @@ namespace Doctrine\DBAL\Driver\IBMDB2; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ParameterType; use IteratorAggregate; use PDO; @@ -50,7 +50,7 @@ use const DB2_PARAM_FILE; use const DB2_PARAM_IN; -class DB2Statement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement +class DB2Statement implements IteratorAggregate, Statement, Result { /** @var resource */ private $stmt; diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 16a0cf767f1..4f912fa1f5b 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -3,11 +3,11 @@ namespace Doctrine\DBAL\Driver\Mysqli; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\FetchMode; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ParameterType; use IteratorAggregate; use mysqli; @@ -27,7 +27,7 @@ use function sprintf; use function str_repeat; -class MysqliStatement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement +class MysqliStatement implements IteratorAggregate, Statement, Result { /** @var string[] */ protected static $_paramTypeMap = [ diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 38a5a14bafe..e31f42d5f4c 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -3,10 +3,10 @@ namespace Doctrine\DBAL\Driver\OCI8; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ParameterType; use InvalidArgumentException; use IteratorAggregate; @@ -51,7 +51,7 @@ /** * The OCI8 implementation of the Statement interface. */ -class OCI8Statement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement +class OCI8Statement implements IteratorAggregate, Statement, Result { /** @var resource */ protected $_dbh; diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php index ab4078e05a9..bc5ae131778 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; use Doctrine\DBAL\Driver\PDOConnection; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\ParameterType; use PDO; @@ -36,7 +36,7 @@ public function lastInsertId($name = null) $stmt = $this->prepare('SELECT CONVERT(VARCHAR(MAX), current_value) FROM sys.sequences WHERE name = ?'); $stmt->execute([$name]); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { return $stmt->fetchOne(); } diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index c55a79925d7..4ff31dfc702 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -3,7 +3,6 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\FetchMode; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ParameterType; use PDO; @@ -20,7 +19,7 @@ * The PDO implementation of the Statement interface. * Used by all PDO-based drivers. */ -class PDOStatement extends \PDOStatement implements Statement, ForwardCompatibleResultStatement +class PDOStatement extends \PDOStatement implements Statement, Result { private const PARAM_TYPE_MAP = [ ParameterType::NULL => PDO::PARAM_NULL, diff --git a/lib/Doctrine/DBAL/ForwardCompatibility/Driver/ResultStatement.php b/lib/Doctrine/DBAL/Driver/Result.php similarity index 58% rename from lib/Doctrine/DBAL/ForwardCompatibility/Driver/ResultStatement.php rename to lib/Doctrine/DBAL/Driver/Result.php index c0c7dffc667..49487249914 100644 --- a/lib/Doctrine/DBAL/ForwardCompatibility/Driver/ResultStatement.php +++ b/lib/Doctrine/DBAL/Driver/Result.php @@ -2,18 +2,17 @@ declare(strict_types=1); -namespace Doctrine\DBAL\ForwardCompatibility\Driver; +namespace Doctrine\DBAL\Driver; -use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\ResultStatement as BaseResultStatement; /** - * Forward compatibility extension for the ResultStatement interface. + * Driver-level result statement execution result. */ -interface ResultStatement extends BaseResultStatement +interface Result extends BaseResultStatement { /** - * Returns the next row of a result set as a numeric array or FALSE if there are no more rows. + * Returns the next row of the result as a numeric array or FALSE if there are no more rows. * * @return array|false * @@ -22,7 +21,7 @@ interface ResultStatement extends BaseResultStatement public function fetchNumeric(); /** - * Returns the next row of a result set as an associative array or FALSE if there are no more rows. + * Returns the next row of the result as an associative array or FALSE if there are no more rows. * * @return array|false * @@ -31,7 +30,7 @@ public function fetchNumeric(); public function fetchAssociative(); /** - * Returns the first value of the next row of a result set or FALSE if there are no more rows. + * Returns the first value of the next row of the result or FALSE if there are no more rows. * * @return mixed|false * @@ -40,7 +39,7 @@ public function fetchAssociative(); public function fetchOne(); /** - * Returns an array containing all of the result set rows represented as numeric arrays. + * Returns an array containing all of the result rows represented as numeric arrays. * * @return array> * @@ -49,7 +48,7 @@ public function fetchOne(); public function fetchAllNumeric(): array; /** - * Returns an array containing all of the result set rows represented as associative arrays. + * Returns an array containing all of the result rows represented as associative arrays. * * @return array> * @@ -58,7 +57,7 @@ public function fetchAllNumeric(): array; public function fetchAllAssociative(): array; /** - * Returns an array containing the values of the first column of the result set. + * Returns an array containing the values of the first column of the result. * * @return array * diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php index b3657e41350..b56fd61ff2d 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereConnection.php @@ -3,8 +3,8 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere; use Doctrine\DBAL\Driver\Connection; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ParameterType; use function assert; @@ -129,7 +129,7 @@ public function getServerVersion() { $stmt = $this->query("SELECT PROPERTY('ProductVersion')"); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { $version = $stmt->fetchOne(); } else { $version = $stmt->fetchColumn(); @@ -151,7 +151,7 @@ public function lastInsertId($name = null) $stmt = $this->query('SELECT ' . $name . '.CURRVAL'); - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { return $stmt->fetchOne(); } diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index a8eddb7fdad..de8d60cd42c 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -4,10 +4,10 @@ use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ParameterType; use IteratorAggregate; use PDO; @@ -44,7 +44,7 @@ /** * SAP SQL Anywhere implementation of the Statement interface. */ -class SQLAnywhereStatement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement +class SQLAnywhereStatement implements IteratorAggregate, Statement, Result { /** @var resource The connection resource. */ private $conn; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php index 912b63336a7..cb38400182f 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvConnection.php @@ -3,8 +3,8 @@ namespace Doctrine\DBAL\Driver\SQLSrv; use Doctrine\DBAL\Driver\Connection; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ParameterType; use function func_get_args; @@ -144,7 +144,7 @@ public function lastInsertId($name = null) $stmt = $this->query('SELECT @@IDENTITY'); } - if ($stmt instanceof ForwardCompatibleResultStatement) { + if ($stmt instanceof Result) { return $stmt->fetchOne(); } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 1042bb18cb5..3e059a1c85d 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -3,10 +3,10 @@ namespace Doctrine\DBAL\Driver\SQLSrv; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ParameterType; use IteratorAggregate; use PDO; @@ -42,7 +42,7 @@ /** * SQL Server Statement. */ -class SQLSrvStatement implements IteratorAggregate, Statement, ForwardCompatibleResultStatement +class SQLSrvStatement implements IteratorAggregate, Statement, Result { /** * The SQLSRV Resource. diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index 02b598fc9ee..34d07343748 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -2,11 +2,11 @@ namespace Doctrine\DBAL\Portability; +use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\ResultStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; -use Doctrine\DBAL\ForwardCompatibility\Driver\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\ParameterType; use IteratorAggregate; use PDO; @@ -19,7 +19,7 @@ /** * Portability wrapper for a Statement. */ -class Statement implements IteratorAggregate, DriverStatement, ForwardCompatibleResultStatement +class Statement implements IteratorAggregate, DriverStatement, Result { /** @var int */ private $portability; @@ -185,7 +185,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n */ public function fetchNumeric() { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { $row = $this->stmt->fetchNumeric(); } else { $row = $this->stmt->fetch(FetchMode::NUMERIC); @@ -199,7 +199,7 @@ public function fetchNumeric() */ public function fetchAssociative() { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { $row = $this->stmt->fetchAssociative(); } else { $row = $this->stmt->fetch(FetchMode::ASSOCIATIVE); @@ -213,7 +213,7 @@ public function fetchAssociative() */ public function fetchOne() { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { $value = $this->stmt->fetchOne(); } else { $value = $this->stmt->fetch(FetchMode::COLUMN); @@ -233,7 +233,7 @@ public function fetchOne() */ public function fetchAllNumeric(): array { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { $data = $this->stmt->fetchAllNumeric(); } else { $data = $this->stmt->fetchAll(FetchMode::NUMERIC); @@ -247,7 +247,7 @@ public function fetchAllNumeric(): array */ public function fetchAllAssociative(): array { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { $data = $this->stmt->fetchAllAssociative(); } else { $data = $this->stmt->fetchAll(FetchMode::ASSOCIATIVE); @@ -261,7 +261,7 @@ public function fetchAllAssociative(): array */ public function fetchFirstColumn(): array { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { $data = $this->stmt->fetchFirstColumn(); } else { $data = $this->stmt->fetchAll(FetchMode::COLUMN); diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 907e631d064..6f329048c81 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -2,9 +2,9 @@ namespace Doctrine\DBAL; +use Doctrine\DBAL\Abstraction\Result; use Doctrine\DBAL\Driver\DriverException; use Doctrine\DBAL\Driver\Statement as DriverStatement; -use Doctrine\DBAL\ForwardCompatibility\ResultStatement as ForwardCompatibleResultStatement; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; use IteratorAggregate; @@ -19,7 +19,7 @@ * A thin wrapper around a Doctrine\DBAL\Driver\Statement that adds support * for logging, DBAL mapping types, etc. */ -class Statement implements IteratorAggregate, DriverStatement, ForwardCompatibleResultStatement +class Statement implements IteratorAggregate, DriverStatement, Result { /** * The SQL statement. @@ -289,7 +289,7 @@ public function fetchColumn($columnIndex = 0) public function fetchNumeric() { try { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { return $this->stmt->fetchNumeric(); } @@ -307,7 +307,7 @@ public function fetchNumeric() public function fetchAssociative() { try { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { return $this->stmt->fetchAssociative(); } @@ -325,7 +325,7 @@ public function fetchAssociative() public function fetchOne() { try { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { return $this->stmt->fetchOne(); } @@ -343,7 +343,7 @@ public function fetchOne() public function fetchAllNumeric(): array { try { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { return $this->stmt->fetchAllNumeric(); } @@ -361,7 +361,7 @@ public function fetchAllNumeric(): array public function fetchAllAssociative(): array { try { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { return $this->stmt->fetchAllAssociative(); } @@ -379,7 +379,7 @@ public function fetchAllAssociative(): array public function fetchFirstColumn(): array { try { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { return $this->stmt->fetchFirstColumn(); } @@ -399,7 +399,7 @@ public function fetchFirstColumn(): array public function iterateNumeric(): Traversable { try { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { while (($row = $this->stmt->fetchNumeric()) !== false) { yield $row; } @@ -423,7 +423,7 @@ public function iterateNumeric(): Traversable public function iterateAssociative(): Traversable { try { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { while (($row = $this->stmt->fetchAssociative()) !== false) { yield $row; } @@ -447,7 +447,7 @@ public function iterateAssociative(): Traversable public function iterateColumn(): Traversable { try { - if ($this->stmt instanceof ForwardCompatibleResultStatement) { + if ($this->stmt instanceof Result) { while (($value = $this->stmt->fetchOne()) !== false) { yield $value; } From cc5bbd015a45df9012eb69b7805d6ab16db6dd15 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 5 Jun 2020 22:47:01 -0700 Subject: [PATCH 2/5] Do not extend ResultStetement by Result --- lib/Doctrine/DBAL/Driver/Result.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/Result.php b/lib/Doctrine/DBAL/Driver/Result.php index 49487249914..cb450c9cc7b 100644 --- a/lib/Doctrine/DBAL/Driver/Result.php +++ b/lib/Doctrine/DBAL/Driver/Result.php @@ -4,12 +4,10 @@ namespace Doctrine\DBAL\Driver; -use Doctrine\DBAL\Driver\ResultStatement as BaseResultStatement; - /** * Driver-level result statement execution result. */ -interface Result extends BaseResultStatement +interface Result { /** * Returns the next row of the result as a numeric array or FALSE if there are no more rows. @@ -64,4 +62,19 @@ public function fetchAllAssociative(): array; * @throws DriverException */ public function fetchFirstColumn(): array; + + /** + * Returns the number of columns in the result + * + * @return int The number of columns in the result. If the columns cannot be counted, + * this method must return 0. + */ + public function columnCount(); + + /** + * Closes the cursor, enabling the statement to be executed again. + * + * @return bool TRUE on success or FALSE on failure. + */ + public function closeCursor(); } From 94d5321e7c1a7deaa5e5d189abbceee4bd5809aa Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 5 Jun 2020 22:53:20 -0700 Subject: [PATCH 3/5] Add rowCount() to the Result interface --- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 10 +++++++++- lib/Doctrine/DBAL/Driver/Result.php | 11 +++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index f9bef8d73d7..b9e19036a84 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -48,11 +48,19 @@ public function __construct(array $data) */ public function closeCursor() { - unset($this->data); + $this->data = []; return true; } + /** + * {@inheritdoc} + */ + public function rowCount() + { + return count($this->data); + } + /** * {@inheritdoc} */ diff --git a/lib/Doctrine/DBAL/Driver/Result.php b/lib/Doctrine/DBAL/Driver/Result.php index cb450c9cc7b..ad23d693c40 100644 --- a/lib/Doctrine/DBAL/Driver/Result.php +++ b/lib/Doctrine/DBAL/Driver/Result.php @@ -63,6 +63,17 @@ public function fetchAllAssociative(): array; */ public function fetchFirstColumn(): array; + /** + * Returns the number of rows affected by the DELETE, INSERT, or UPDATE statement that produced the result. + * + * If the statement executed a SELECT query or a similar platform-specific SQL (e.g. DESCRIBE, SHOW, etc.), + * some database drivers may return the number of rows returned by that query. However, this behaviour + * is not guaranteed for all drivers and should not be relied on in portable applications. + * + * @return int The number of rows. + */ + public function rowCount(); + /** * Returns the number of columns in the result * From f8ae949ff9deb7f610c9ba211d9813f9b53189f5 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 5 Jun 2020 23:01:47 -0700 Subject: [PATCH 4/5] Deprecate ResultStatement::closeCursor() in favor of Result::free() --- UPGRADE.md | 3 +- lib/Doctrine/DBAL/Cache/ArrayStatement.php | 9 ++++- .../DBAL/Cache/ResultCacheStatement.php | 11 +++++-- .../DBAL/Driver/IBMDB2/DB2Statement.php | 11 +++++++ .../DBAL/Driver/Mysqli/MysqliStatement.php | 11 +++++-- .../DBAL/Driver/OCI8/OCI8Statement.php | 23 ++++++++----- lib/Doctrine/DBAL/Driver/PDOStatement.php | 7 ++++ lib/Doctrine/DBAL/Driver/Result.php | 6 ++-- lib/Doctrine/DBAL/Driver/ResultStatement.php | 2 ++ .../SQLAnywhere/SQLAnywhereStatement.php | 7 ++++ .../DBAL/Driver/SQLSrv/SQLSrvStatement.php | 33 +++++++++++-------- lib/Doctrine/DBAL/Portability/Statement.php | 13 ++++++++ lib/Doctrine/DBAL/Statement.php | 13 ++++++++ 13 files changed, 117 insertions(+), 32 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 46e4666b21c..5485f61d2bc 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -2,7 +2,8 @@ ## Deprecated `ResultStatement` interface -The `ResultStatement` interface is deprecated. Use the `Driver\Result` and `Abstraction\Result` interfaces instead. +1. The `ResultStatement` interface is deprecated. Use the `Driver\Result` and `Abstraction\Result` interfaces instead. +2. `ResultStatement::closeCursor()` is deprecated in favor of `Result::free()`. ## Deprecated `FetchMode` and the corresponding methods diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index b9e19036a84..98d545727f5 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -45,10 +45,12 @@ public function __construct(array $data) /** * {@inheritdoc} + * + * @deprecated Use free() instead. */ public function closeCursor() { - $this->data = []; + $this->free(); return true; } @@ -218,6 +220,11 @@ public function fetchFirstColumn(): array return FetchUtils::fetchFirstColumn($this); } + public function free(): void + { + $this->data = []; + } + /** * @return mixed|false */ diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 78d97d25cdf..79151279aad 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -72,12 +72,12 @@ public function __construct(ResultStatement $stmt, Cache $resultCache, $cacheKey /** * {@inheritdoc} + * + * @deprecated Use free() instead. */ public function closeCursor() { - $this->statement->closeCursor(); - - $this->data = null; + $this->free(); return true; } @@ -287,6 +287,11 @@ public function rowCount() return $this->statement->rowCount(); } + public function free(): void + { + $this->data = null; + } + /** * @return array|false * diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 163accb5a70..7c97017099d 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -147,6 +147,8 @@ private function bind($position, &$variable, int $parameterType, int $dataType): /** * {@inheritdoc} + * + * @deprecated Use free() instead. */ public function closeCursor() { @@ -426,6 +428,15 @@ public function rowCount() return @db2_num_rows($this->stmt) ? : 0; } + public function free(): void + { + $this->bindParam = []; + + db2_free_result($this->stmt); + + $this->result = false; + } + /** * Casts a stdClass object to the given class name mapping its' properties. * diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index 4f912fa1f5b..c3f893fc127 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -498,11 +498,12 @@ public function errorInfo() /** * {@inheritdoc} + * + * @deprecated Use free() instead. */ public function closeCursor() { - $this->_stmt->free_result(); - $this->result = false; + $this->free(); return true; } @@ -527,6 +528,12 @@ public function columnCount() return $this->_stmt->field_count; } + public function free(): void + { + $this->_stmt->free_result(); + $this->result = false; + } + /** * {@inheritdoc} * diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index e31f42d5f4c..4f04a46a5cf 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -331,17 +331,12 @@ private function convertParameterType(int $type): int /** * {@inheritdoc} + * + * @deprecated Use free() instead. */ public function closeCursor() { - // not having the result means there's nothing to close - if (! $this->result) { - return true; - } - - oci_cancel($this->_sth); - - $this->result = false; + $this->free(); return true; } @@ -601,6 +596,18 @@ public function fetchFirstColumn(): array return $this->doFetchAll(OCI_NUM, OCI_FETCHSTATEMENT_BY_COLUMN)[0]; } + public function free(): void + { + // not having the result means there's nothing to close + if (! $this->result) { + return; + } + + oci_cancel($this->_sth); + + $this->result = false; + } + /** * @return mixed|false */ diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 4ff31dfc702..911f5d49665 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -110,6 +110,8 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l /** * {@inheritdoc} + * + * @deprecated Use free() instead. */ public function closeCursor() { @@ -249,6 +251,11 @@ public function fetchFirstColumn(): array return $this->fetchAll(PDO::FETCH_COLUMN); } + public function free(): void + { + parent::closeCursor(); + } + /** * Converts DBAL parameter type to PDO parameter type * diff --git a/lib/Doctrine/DBAL/Driver/Result.php b/lib/Doctrine/DBAL/Driver/Result.php index ad23d693c40..65be0f03c49 100644 --- a/lib/Doctrine/DBAL/Driver/Result.php +++ b/lib/Doctrine/DBAL/Driver/Result.php @@ -83,9 +83,7 @@ public function rowCount(); public function columnCount(); /** - * Closes the cursor, enabling the statement to be executed again. - * - * @return bool TRUE on success or FALSE on failure. + * Discards the non-fetched portion of the result, enabling the originating statement to be executed again. */ - public function closeCursor(); + public function free(): void; } diff --git a/lib/Doctrine/DBAL/Driver/ResultStatement.php b/lib/Doctrine/DBAL/Driver/ResultStatement.php index 442552040cc..601e28dba41 100644 --- a/lib/Doctrine/DBAL/Driver/ResultStatement.php +++ b/lib/Doctrine/DBAL/Driver/ResultStatement.php @@ -13,6 +13,8 @@ interface ResultStatement extends Traversable /** * Closes the cursor, enabling the statement to be executed again. * + * @deprecated Use Result::free() instead. + * * @return bool TRUE on success or FALSE on failure. */ public function closeCursor(); diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index de8d60cd42c..6a67072e266 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -136,6 +136,8 @@ public function bindValue($param, $value, $type = ParameterType::STRING) /** * {@inheritdoc} * + * @deprecated Use free() instead. + * * @throws SQLAnywhereException */ public function closeCursor() @@ -388,6 +390,11 @@ public function rowCount() return sasql_stmt_affected_rows($this->stmt); } + public function free(): void + { + sasql_stmt_reset($this->stmt); + } + /** * {@inheritdoc} * diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 3e059a1c85d..886faf55bcc 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -186,22 +186,12 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l /** * {@inheritdoc} + * + * @deprecated Use free() instead. */ public function closeCursor() { - // not having the result means there's nothing to close - if ($this->stmt === null || ! $this->result) { - return true; - } - - // emulate it by fetching and discarding rows, similarly to what PDO does in this case - // @link http://php.net/manual/en/pdostatement.closecursor.php - // @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075 - // deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them - while (sqlsrv_fetch($this->stmt)) { - } - - $this->result = false; + $this->free(); return true; } @@ -498,6 +488,23 @@ public function rowCount() return sqlsrv_rows_affected($this->stmt) ?: 0; } + public function free(): void + { + // not having the result means there's nothing to close + if ($this->stmt === null || ! $this->result) { + return; + } + + // emulate it by fetching and discarding rows, similarly to what PDO does in this case + // @link http://php.net/manual/en/pdostatement.closecursor.php + // @link https://github.com/php/php-src/blob/php-7.0.11/ext/pdo/pdo_stmt.c#L2075 + // deliberately do not consider multiple result sets, since doctrine/dbal doesn't support them + while (sqlsrv_fetch($this->stmt)) { + } + + $this->result = false; + } + /** * @return mixed|false */ diff --git a/lib/Doctrine/DBAL/Portability/Statement.php b/lib/Doctrine/DBAL/Portability/Statement.php index 34d07343748..cafee72b71f 100644 --- a/lib/Doctrine/DBAL/Portability/Statement.php +++ b/lib/Doctrine/DBAL/Portability/Statement.php @@ -67,6 +67,8 @@ public function bindValue($param, $value, $type = ParameterType::STRING) /** * {@inheritdoc} + * + * @deprecated Use free() instead. */ public function closeCursor() { @@ -270,6 +272,17 @@ public function fetchFirstColumn(): array return $this->fixResultSet($data, true, false); } + public function free(): void + { + if ($this->stmt instanceof Result) { + $this->stmt->free(); + + return; + } + + $this->stmt->closeCursor(); + } + /** * @param mixed $result * diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 6f329048c81..3d6dfc27f26 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -182,6 +182,8 @@ public function execute($params = null) /** * Closes the cursor, freeing the database resources used by this statement. * + * @deprecated Use Result::free() instead. + * * @return bool TRUE on success, FALSE on failure. */ public function closeCursor() @@ -471,6 +473,17 @@ public function rowCount() return $this->stmt->rowCount(); } + public function free(): void + { + if ($this->stmt instanceof Result) { + $this->stmt->free(); + + return; + } + + $this->stmt->closeCursor(); + } + /** * Gets the wrapped driver statement. * From e7c7cb1788353d8d57f6e416819dc4461b7dd467 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Fri, 5 Jun 2020 17:54:05 -0700 Subject: [PATCH 5/5] Deprecate ArrayStatement and ResultCacheStatement --- UPGRADE.md | 4 ++++ lib/Doctrine/DBAL/Cache/ArrayStatement.php | 3 +++ lib/Doctrine/DBAL/Cache/ResultCacheStatement.php | 2 ++ 3 files changed, 9 insertions(+) diff --git a/UPGRADE.md b/UPGRADE.md index 5485f61d2bc..2d1f52303a6 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,9 @@ # Upgrade to 2.11 +## Deprecated `ArrayStatement` and `ResultCacheStatement` classes. + +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. + ## Deprecated `ResultStatement` interface 1. The `ResultStatement` interface is deprecated. Use the `Driver\Result` and `Abstraction\Result` interfaces instead. diff --git a/lib/Doctrine/DBAL/Cache/ArrayStatement.php b/lib/Doctrine/DBAL/Cache/ArrayStatement.php index 98d545727f5..58d0a59e361 100644 --- a/lib/Doctrine/DBAL/Cache/ArrayStatement.php +++ b/lib/Doctrine/DBAL/Cache/ArrayStatement.php @@ -16,6 +16,9 @@ use function count; use function reset; +/** + * @deprecated + */ class ArrayStatement implements IteratorAggregate, ResultStatement, Result { /** @var mixed[] */ diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 79151279aad..d990b15fefd 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -32,6 +32,8 @@ * * Also you have to realize that the cache will load the whole result into memory at once to ensure 2. * This means that the memory usage for cached results might increase by using this feature. + * + * @deprecated */ class ResultCacheStatement implements IteratorAggregate, ResultStatement, Result {