Commit c89b70f4 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge pull request #128 from gedrox/DBAL-249

[DBAL-249] result cache with fetch type PDO::FETCH_COLUMN
parents 86a0b520 5e4b1a20
......@@ -68,6 +68,10 @@ class ArrayStatement implements \IteratorAggregate, ResultStatement
return array_values($row);
} else if ($fetchStyle === PDO::FETCH_BOTH) {
return array_merge($row, array_values($row));
} else if ($fetchStyle === PDO::FETCH_COLUMN) {
return reset($row);
} else {
throw new \InvalidArgumentException("Invalid fetch-style given for fetching result.");
}
}
return false;
......
......@@ -169,6 +169,8 @@ class ResultCacheStatement implements \IteratorAggregate, ResultStatement
return array_values($row);
} else if ($fetchStyle == PDO::FETCH_BOTH) {
return array_merge($row, array_values($row));
} else if ($fetchStyle == PDO::FETCH_COLUMN) {
return reset($row);
} else {
throw new \InvalidArgumentException("Invalid fetch-style given for caching result.");
}
......
......@@ -65,6 +65,15 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
}
$this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_BOTH);
}
public function testFetchColumn()
{
$expectedResult = array();
foreach ($this->expectedResult AS $v) {
$expectedResult[] = array_shift($v);
}
$this->assertCacheNonCacheSelectSameFetchModeAreEqual($expectedResult, \PDO::FETCH_COLUMN);
}
public function testMixingFetch()
{
......@@ -180,7 +189,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
$data = array();
while ($row = $stmt->fetch($fetchStyle)) {
$data[] = array_change_key_case($row, CASE_LOWER);
$data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row;
}
$stmt->closeCursor();
return $data;
......@@ -191,7 +200,7 @@ class ResultCacheTest extends \Doctrine\Tests\DbalFunctionalTestCase
$data = array();
$stmt->setFetchMode($fetchStyle);
foreach ($stmt as $row) {
$data[] = array_change_key_case($row, CASE_LOWER);
$data[] = is_array($row) ? array_change_key_case($row, CASE_LOWER) : $row;
}
$stmt->closeCursor();
return $data;
......
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