Skip to content

Commit

Permalink
[doctrineGH-4019] Trigger deprecations for fetch mode deprecation to …
Browse files Browse the repository at this point in the history
…fetch* APIs.
  • Loading branch information
beberlei committed Mar 7, 2021
1 parent 304a537 commit d7f55e2
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"php": "^7.3 || ^8",
"ext-pdo": "*",
"doctrine/cache": "^1.0",
"doctrine/deprecations": "^0.2.0",
"doctrine/event-manager": "^1.0"
},
"require-dev": {
Expand Down
25 changes: 25 additions & 0 deletions lib/Doctrine/DBAL/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;
use Throwable;
use Traversable;

Expand Down Expand Up @@ -542,6 +543,12 @@ public function setAutoCommit($autoCommit)
*/
public function setFetchMode($fetchMode)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Default Fetch Mode configuration is deprecated, use explicit Connection::fetch*() APIs instead.'
);

$this->defaultFetchMode = $fetchMode;
}

Expand All @@ -561,6 +568,12 @@ public function setFetchMode($fetchMode)
*/
public function fetchAssoc($sql, array $params = [], array $types = [])
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Connection::fetchAssoc() is deprecated, use Connection::fetchAssociative() API instead.'
);

return $this->executeQuery($sql, $params, $types)->fetch(FetchMode::ASSOCIATIVE);
}

Expand All @@ -578,6 +591,12 @@ public function fetchAssoc($sql, array $params = [], array $types = [])
*/
public function fetchArray($sql, array $params = [], array $types = [])
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Connection::fetchArray() is deprecated, use Connection::fetchNumeric() API instead.'
);

return $this->executeQuery($sql, $params, $types)->fetch(FetchMode::NUMERIC);
}

Expand All @@ -598,6 +617,12 @@ public function fetchArray($sql, array $params = [], array $types = [])
*/
public function fetchColumn($sql, array $params = [], $column = 0, array $types = [])
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Connection::fetchColumn() is deprecated, use Connection::fetchOne() API instead.'
);

return $this->executeQuery($sql, $params, $types)->fetchColumn($column);
}

Expand Down
33 changes: 33 additions & 0 deletions lib/Doctrine/DBAL/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Doctrine\DBAL\Exception\NoKeyValue;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\Deprecations\Deprecation;
use IteratorAggregate;
use PDO;
use PDOStatement;
Expand Down Expand Up @@ -231,6 +232,12 @@ public function errorInfo()
*/
public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::setFetchMode() is deprecated, use explicit Statement::fetch*() APIs instead.'
);

if ($arg2 === null) {
return $this->stmt->setFetchMode($fetchMode);
}
Expand All @@ -251,6 +258,13 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
*/
public function getIterator()
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::getIterator() is deprecated, use Statement::iterateNumeric(), iterateAssociative() ' .
'or iterateColumn() instead.'
);

return $this->stmt;
}

Expand All @@ -261,6 +275,12 @@ public function getIterator()
*/
public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEXT, $cursorOffset = 0)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::fetch() is deprecated, use Statement::fetchNumeric(), fetchAssociative() or fetchOne() instead.'
);

return $this->stmt->fetch($fetchMode);
}

Expand All @@ -271,6 +291,13 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX
*/
public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = null)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::fetchAll() is deprecated, use Statement::fetchAllNumeric(), fetchAllAssociative() or ' .
'fetchFirstColumn() instead.'
);

if ($ctorArgs !== null) {
return $this->stmt->fetchAll($fetchMode, $fetchArgument, $ctorArgs);
}
Expand All @@ -289,6 +316,12 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n
*/
public function fetchColumn($columnIndex = 0)
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::fetchColumn() is deprecated, use Statement::fetchOne() instead.'
);

return $this->stmt->fetchColumn($columnIndex);
}

Expand Down

0 comments on commit d7f55e2

Please sign in to comment.