Skip to content

Commit

Permalink
Merge pull request #3686 from morozov/issues/3597
Browse files Browse the repository at this point in the history
Fixed query result caching when FetchMode::COLUMN is used
  • Loading branch information
Ocramius authored Oct 8, 2019
2 parents e3cefb0 + 7a99133 commit 81922a2
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 @@ -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;
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 @@ -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<int, array<int, int|string>> $expectedResult
*/
Expand Down

0 comments on commit 81922a2

Please sign in to comment.