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 #3082: Add BC for PDO-only fetch modes #3088

Merged
merged 2 commits into from
Apr 7, 2018
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
20 changes: 18 additions & 2 deletions lib/Doctrine/DBAL/Driver/PDOStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
use Doctrine\DBAL\FetchMode;
use Doctrine\DBAL\ParameterType;
use PDO;
use const E_USER_DEPRECATED;
use function sprintf;
use function trigger_error;

/**
* The PDO implementation of the Statement interface.
Expand Down Expand Up @@ -213,7 +216,13 @@ public function fetchColumn($columnIndex = 0)
private function convertParamType(int $type) : int
{
if (! isset(self::PARAM_TYPE_MAP[$type])) {
throw new \InvalidArgumentException('Invalid parameter type: ' . $type);
// TODO: next major: throw an exception
@trigger_error(sprintf(
'Using a PDO parameter type (%d given) is deprecated and will cause an error in Doctrine 3.0',
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have a test for this one too? 🙏

Copy link
Member

Choose a reason for hiding this comment

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

I cannot come up with a reasonable example. Ideas?

Copy link
Member

Choose a reason for hiding this comment

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

PostgeSQL doesn't like PDO::PARAM_INPUT_OUTPUT (see https://travis-ci.org/doctrine/dbal/jobs/363396885).

$type
), E_USER_DEPRECATED);

return $type;
}

return self::PARAM_TYPE_MAP[$type];
Expand All @@ -231,7 +240,14 @@ private function convertFetchMode(?int $fetchMode) : ?int
}

if (! isset(self::FETCH_MODE_MAP[$fetchMode])) {
throw new \InvalidArgumentException('Invalid fetch mode: ' . $fetchMode);
// TODO: next major: throw an exception
@trigger_error(sprintf(
'Using a PDO fetch mode or their combination (%d given)' .
' is deprecated and will cause an error in Doctrine 3.0',
$fetchMode
), E_USER_DEPRECATED);

return $fetchMode;
}

return self::FETCH_MODE_MAP[$fetchMode];
Expand Down
54 changes: 54 additions & 0 deletions tests/Doctrine/Tests/DBAL/Functional/PDOStatementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Doctrine\Tests\DBAL\Functional;

use Doctrine\DBAL\Driver\PDOConnection;
use Doctrine\DBAL\Schema\Table;
use Doctrine\Tests\DbalFunctionalTestCase;
use PDO;
use function extension_loaded;

class PDOStatementTest extends DbalFunctionalTestCase
{
protected function setUp()
{
if (! extension_loaded('pdo')) {
$this->markTestSkipped('PDO is not installed');
}

parent::setUp();

if (! $this->_conn->getWrappedConnection() instanceof PDOConnection) {
$this->markTestSkipped('PDO-only test');
}

$table = new Table('stmt_test');
$table->addColumn('id', 'integer');
$table->addColumn('name', 'text');
$this->_conn->getSchemaManager()->dropAndCreateTable($table);
}

/**
* @group legacy
* @expectedDeprecation Using a PDO fetch mode or their combination (%d given) is deprecated and will cause an error in Doctrine 3.0
*/
public function testPDOSpecificModeIsAccepted()
{
$this->_conn->insert('stmt_test', [
'id' => 1,
'name' => 'Alice',
]);
$this->_conn->insert('stmt_test', [
'id' => 2,
'name' => 'Bob',
]);

$data = $this->_conn->query('SELECT id, name FROM stmt_test ORDER BY id')
->fetchAll(PDO::FETCH_KEY_PAIR);

self::assertSame([
1 => 'Alice',
2 => 'Bob',
], $data);
}
}