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 66f28111
......@@ -166,7 +166,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;
......
......@@ -176,6 +176,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));
}
public function assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, $fetchMode)
{
$stmt = $this->connection->executeQuery('SELECT * FROM caching ORDER BY test_int ASC', [], [], new QueryCacheProfile(10, 'testcachekey'));
......
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