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

[DBAL-2644] Fix fetchAll(PDO::FETCH_COLUMN) on DB2 with Portability wrapper #2647

Merged
merged 1 commit into from
Feb 16, 2017
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Doctrine/DBAL/Portability/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ public function connect()
} elseif ($this->getDatabasePlatform()->getName() === "sqlite") {
$params['portability'] = $params['portability'] & self::PORTABILITY_SQLITE;
} elseif ($this->getDatabasePlatform()->getName() === "drizzle") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note for the next person that has to maintain this: we're sorry about this massive chain of doom and elseif :-(

$params['portability'] = self::PORTABILITY_DRIZZLE;
$params['portability'] = $params['portability'] & self::PORTABILITY_DRIZZLE;
} elseif ($this->getDatabasePlatform()->getName() === 'sqlanywhere') {
$params['portability'] = self::PORTABILITY_SQLANYWHERE;
$params['portability'] = $params['portability'] & self::PORTABILITY_SQLANYWHERE;
} elseif ($this->getDatabasePlatform()->getName() === 'db2') {
$params['portability'] = self::PORTABILITY_DB2;
$params['portability'] = $params['portability'] & self::PORTABILITY_DB2;
} elseif ($this->getDatabasePlatform()->getName() === 'mssql') {
$params['portability'] = $params['portability'] & self::PORTABILITY_SQLSRV;
} else {
Expand Down
12 changes: 12 additions & 0 deletions lib/Doctrine/DBAL/Portability/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,22 @@ public function fetchAll($fetchMode = null, $columnIndex = 0)
return $rows;
}

if ($fetchMode === PDO::FETCH_COLUMN) {
foreach ($rows as $num => $row) {
$rows[$num] = array($row);
}
}

foreach ($rows as $num => $row) {
$rows[$num] = $this->fixRow($row, $iterateRow, $fixCase);
}

if ($fetchMode === PDO::FETCH_COLUMN) {
foreach ($rows as $num => $row) {
$rows[$num] = $row[0];
}
}

return $rows;
}

Expand Down
35 changes: 35 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/PortabilityTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,39 @@ public function testPortabilitySqlServer()

$this->assertEquals($portability, $connection->getPortability());
}

/**
* @dataProvider fetchAllColumnProvider
*/
public function testFetchAllColumn($field, array $expected)
{
$conn = $this->getPortableConnection();
$stmt = $conn->query('SELECT ' . $field . ' FROM portability_table');

$column = $stmt->fetchAll(PDO::FETCH_COLUMN);
$this->assertEquals($expected, $column);
}

public static function fetchAllColumnProvider()
{
return array(
'int' => array(
'Test_Int',
array(1, 2),
),
'string' => array(
'Test_String',
array('foo', 'foo'),
),
);
}

public function testFetchAllNullColumn()
{
$conn = $this->getPortableConnection();
$stmt = $conn->query('SELECT Test_Null FROM portability_table');

$column = $stmt->fetchAll(PDO::FETCH_COLUMN);
$this->assertSame(array(null, null), $column);
}
}