Skip to content

Commit

Permalink
ResultCacheStatement should always fetch in associative mode
Browse files Browse the repository at this point in the history
This will allow for subsequent fetches in different modes.
  • Loading branch information
morozov committed May 27, 2020
1 parent 3eb6f0a commit e74b97c
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,18 +180,26 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
{
$data = $this->statement->fetchAll($fetchMode, $fetchArgument, $ctorArgs);

if ($fetchMode === FetchMode::COLUMN) {
foreach ($data as $key => $value) {
$data[$key] = [$value];
}
}
$data = $this->statement->fetchAll(FetchMode::ASSOCIATIVE, $fetchArgument, $ctorArgs);

$this->data = $data;
$this->emptied = true;

return $this->data;
if ($fetchMode === FetchMode::NUMERIC) {
foreach ($data as $i => $row) {
$data[$i] = array_values($row);
}
} elseif ($fetchMode === FetchMode::MIXED) {
foreach ($data as $i => $row) {
$data[$i] = array_merge($row, array_values($row));
}
} elseif ($fetchMode === FetchMode::COLUMN) {
foreach ($data as $i => $row) {
$data[$i] = reset($row);
}
}

return $data;
}

/**
Expand Down

0 comments on commit e74b97c

Please sign in to comment.