Fixed query result caching when FetchMode::COLUMN is used

Internally, ArrayStatement expects every row to be represented as an array regardless of the fetch mode, however FetchMode::COLUMN produces one value per row.
parent 065fb78c
......@@ -167,7 +167,15 @@ class ResultCacheStatement implements IteratorAggregate, ResultStatement
*/
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;
......
......@@ -177,6 +177,22 @@ class ResultCacheTest extends DbalFunctionalTestCase
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
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment