diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index 8fbae62de29..f04c8524974 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -167,7 +167,15 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX */ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null) { - $this->data = $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs); + $data = $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs); + + if ($fetchMode === FetchMode::COLUMN) { + foreach ($data as $key => $value) { + $data[$key] = [$value]; + } + } + + $this->data = $data; $this->emptied = true; return $this->data; diff --git a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php index 35ce061b5b9..8d0a17c9b43 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php @@ -177,6 +177,22 @@ public function testFetchAllAndFinishSavesCache() : void self::assertCount(1, $layerCache->fetch('testcachekey')); } + public function testFetchAllColumn() : void + { + $query = $this->connection->getDatabasePlatform() + ->getDummySelectSQL('1'); + + $qcp = new QueryCacheProfile(0, 0, new ArrayCache()); + + $stmt = $this->connection->executeCacheQuery($query, [], [], $qcp); + $stmt->fetchAll(FetchMode::COLUMN); + $stmt->closeCursor(); + + $stmt = $this->connection->executeCacheQuery($query, [], [], $qcp); + + self::assertEquals([1], $stmt->fetchAll(FetchMode::COLUMN)); + } + /** * @param array> $expectedResult */