Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DBAL-196 #95

Merged
merged 2 commits into from Jan 21, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}