Skip to content
Browse files

Merge pull request #128 from gedrox/DBAL-249

[DBAL-249] result cache with fetch type PDO::FETCH_COLUMN
  • Loading branch information...
2 parents 86a0b52 + 5e4b1a2 commit c89b70f41854193c45bdda577ca9116cd09bb71b @beberlei beberlei committed May 4, 2012
View
4 lib/Doctrine/DBAL/Cache/ArrayStatement.php
@@ -68,6 +68,10 @@ public function fetch($fetchStyle = PDO::FETCH_BOTH)
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;
View
2 lib/Doctrine/DBAL/Cache/ResultCacheStatement.php
@@ -169,6 +169,8 @@ public function fetch($fetchStyle = PDO::FETCH_BOTH)
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.");
}
View
13 tests/Doctrine/Tests/DBAL/Functional/ResultCacheTest.php
@@ -65,6 +65,15 @@ public function testFetchBoth()
}
$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 @@ private function hydrateStmt($stmt, $fetchStyle = \PDO::FETCH_ASSOC)
{
$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 @@ private function hydrateStmtIterator($stmt, $fetchStyle = \PDO::FETCH_ASSOC)
$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;

0 comments on commit c89b70f

Please sign in to comment.
Something went wrong with that request. Please try again.