Skip to content

Commit

Permalink
Merge branch 'bpo/2.9/#3686' into 2.9
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Oct 8, 2019
2 parents 66f2811 + 08dca0d commit e738a71
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,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;
Expand Down
16 changes: 16 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,22 @@ public function testFetchAllAndFinishSavesCache()
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));
}

public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchMode)
{
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey'));
Expand Down

0 comments on commit e738a71

Please sign in to comment.