From 52241e9554ef25c9acd147f3d92ea5c6a9cda6cf Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 15 Jan 2020 20:48:45 -0800 Subject: [PATCH] Removed Connection::project() The methods has more limitations and caveats than provides real use: 1. It fetches all data in memory which is often inefficient (see #2718). 2. It fetches rows in memory one by one instead of using `fetchAll()`. 4. It doesn't allow to specify the statement fetch mode since it's instantiated internally. 5. It can be easily replaced with: ```php foreach ($conn->executeQuery($query, $params, $types) as $value) { yield $function($value); } ``` --- UPGRADE.md | 1 + lib/Doctrine/DBAL/Connection.php | 26 -------------------------- 2 files changed, 1 insertion(+), 26 deletions(-) diff --git a/UPGRADE.md b/UPGRADE.md index 9da8928d7fc..66363dd2aac 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -103,6 +103,7 @@ Table columns are no longer indexed by column name. Use the `name` attribute of - The following methods have been removed as leaking internal implementation details: `::getHost()`, `::getPort()`, `::getUsername()`, `::getPassword()`. - The `::getDatabase()` method can now return null which means that no database is currently selected. +- The `::project()` method has been removed. Use `::executeQuery()` and fetch the data from the statement using one of the `Statement::fetch*()` methods instead. ## BC BREAK: Changes in `Doctrine\DBAL\Driver\SQLSrv\LastInsertId` diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index ecb999154e5..67578a70cfc 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -868,32 +868,6 @@ public function executeCacheQuery(string $query, array $params, array $types, Qu return $stmt; } - /** - * Executes an, optionally parametrized, SQL query and returns the result, - * applying a given projection/transformation function on each row of the result. - * - * @param string $query The SQL query to execute. - * @param array|array $params The parameters, if any. - * @param Closure $function The transformation function that is applied on each row. - * The function receives a single parameter, an array, that - * represents a row of the result set. - * - * @return array The projected result of the query. - */ - public function project(string $query, array $params, Closure $function) : array - { - $result = []; - $stmt = $this->executeQuery($query, $params); - - while ($row = $stmt->fetch()) { - $result[] = $function($row); - } - - $stmt->closeCursor(); - - return $result; - } - /** * {@inheritDoc} */