Skip to content

Commit

Permalink
Merge pull request #95 from FabioBatSilva/DDC196
Browse files Browse the repository at this point in the history
Fix DBAL-196
  • Loading branch information
beberlei committed Jan 21, 2012
2 parents 8e870a6 + 08c514f commit e11164a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/Doctrine/DBAL/Statement.php
Expand Up @@ -203,13 +203,13 @@ public function fetch($fetchStyle = PDO::FETCH_BOTH)
* Returns an array containing all of the result set rows.
*
* @param integer $fetchStyle
* @param integer $columnIndex
* @param mixed $fetchArgument
* @return array An array containing all of the remaining rows in the result set.
*/
public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $columnIndex = 0)
public function fetchAll($fetchStyle = PDO::FETCH_BOTH, $fetchArgument = 0)
{
if ($columnIndex != 0) {
return $this->stmt->fetchAll($fetchStyle, $columnIndex);
if ($fetchArgument !== 0) {
return $this->stmt->fetchAll($fetchStyle, $fetchArgument);
}
return $this->stmt->fetchAll($fetchStyle);
}
Expand Down
34 changes: 34 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
Expand Up @@ -380,4 +380,38 @@ public function testSetDefaultFetchMode()
$row = array_keys($stmt->fetch());
$this->assertEquals(0, count( array_filter($row, function($v) { return ! is_numeric($v); })), "should be no non-numerical elements in the result.");
}

/**
* @group DBAL-196
*/
public function testFetchAllSupportFetchClass()
{
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
$this->_conn->insert('fetch_table', array(
'test_int' => 1,
'test_string' => 'foo',
'test_datetime' => '2010-01-01 10:10:10'
));

$sql = "SELECT test_int, test_string, test_datetime FROM fetch_table";
$stmt = $this->_conn->prepare($sql);
$stmt->execute();

$results = $stmt->fetchAll(
\PDO::FETCH_CLASS,
__NAMESPACE__.'\\MyFetchClass'
);

$this->assertEquals(1, count($results));
$this->assertInstanceOf(__NAMESPACE__.'\\MyFetchClass', $results[0]);

$this->assertEquals(1, $results[0]->test_int);
$this->assertEquals('foo', $results[0]->test_string);
$this->assertEquals('2010-01-01 10:10:10', $results[0]->test_datetime);
}
}

class MyFetchClass
{
public $test_int, $test_string, $test_datetime;
}

0 comments on commit e11164a

Please sign in to comment.