Commit 2f0eb0d7 authored by Benjamin Eberlei's avatar Benjamin Eberlei

[DBAL-257] Fix fetchColumn() on empty result for OCI8 to return false

parent c3626225
......@@ -245,7 +245,7 @@ class OCI8Statement implements \IteratorAggregate, Statement
public function fetchColumn($columnIndex = 0)
{
$row = oci_fetch_array($this->_sth, OCI_NUM | OCI_RETURN_NULLS | OCI_RETURN_LOBS);
return $row[$columnIndex];
return isset($row[$columnIndex]) ? $row[$columnIndex] : false;
}
/**
......
......@@ -407,9 +407,7 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
*/
public function testFetchAllSupportFetchClass()
{
if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] == "oci8") {
$this->markTestSkipped("Not supported by OCI8");
}
$this->skipOci8AndMysqli();
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
$this->_conn->insert('fetch_table', array(
......@@ -432,7 +430,44 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$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);
$this->assertStringStartsWith('2010-01-01 10:10:10', $results[0]->test_datetime);
}
/**
* @group DBAL-241
*/
public function testFetchAllStyleColumn()
{
$sql = "DELETE FROM fetch_table";
$this->_conn->executeUpdate($sql);
$this->_conn->insert('fetch_table', array('test_int' => 1, 'test_string' => 'foo'));
$this->_conn->insert('fetch_table', array('test_int' => 10, 'test_string' => 'foo'));
$sql = "SELECT test_int FROM fetch_table";
$rows = $this->_conn->query($sql)->fetchAll(\PDO::FETCH_COLUMN);
$this->assertEquals(array(1, 10), $rows);
}
/**
* @group DBAL-257
*/
public function testEmptyFetchColumnReturnsFalse()
{
$this->_conn->executeQuery('DELETE FROM fetch_table')->execute();
$this->assertFalse($this->_conn->fetchColumn('SELECT test_int FROM fetch_table'));
$this->assertFalse($this->_conn->query('SELECT test_int FROM fetch_table')->fetchColumn());
}
private function skipOci8AndMysqli()
{
if (isset($GLOBALS['db_type']) && $GLOBALS['db_type'] == "oci8") {
$this->markTestSkipped("Not supported by OCI8");
}
if ('mysqli' == $this->_conn->getDriver()->getName()) {
$this->markTestSkipped('Mysqli driver dont support this feature.');
}
}
}
......
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