Skip to content

Commit

Permalink
[DBAL-339] Prevent PDO API failure in setFetchMode()
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Sep 5, 2012
1 parent 7a657fa commit 2c10252
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions lib/Doctrine/DBAL/Statement.php
Expand Up @@ -190,6 +190,12 @@ public function errorInfo()

public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
{
if ($arg2 === null) {
return $this->stmt->setFetchMode($fetchMode);
} else if ($arg3 === null) {
return $this->stmt->setFetchMode($fetchMode, $arg2);
}

return $this->stmt->setFetchMode($fetchMode, $arg2, $arg3);
}

Expand Down
15 changes: 15 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
Expand Up @@ -501,6 +501,21 @@ public function testEmptyFetchColumnReturnsFalse()
$this->assertFalse($this->_conn->query('SELECT test_int FROM fetch_table')->fetchColumn());
}

/**
* @group DBAL-339
*/
public function testSetFetchModeOnDbalStatement()
{
$sql = "SELECT test_int, test_string FROM fetch_table WHERE test_int = ? AND test_string = ?";
$stmt = $this->_conn->executeQuery($sql, array(1, "foo"));
$stmt->setFetchMode(\PDO::FETCH_NUM);

while ($row = $stmt->fetch()) {
$this->assertTrue(isset($row[0]));
$this->assertTrue(isset($row[1]));
}
}

private function setupFixture()
{
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
Expand Down

0 comments on commit 2c10252

Please sign in to comment.