Skip to content

Commit

Permalink
[GH-4554] Deprecate all Statement::fetch* in favor of Result::fetch*
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Mar 28, 2021
1 parent ad31968 commit 6c367ff
Showing 1 changed file with 135 additions and 5 deletions.
140 changes: 135 additions & 5 deletions lib/Doctrine/DBAL/Statement.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null)
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::setFetchMode() is deprecated, use explicit Statement::fetch*() APIs instead.'
'Statement::setFetchMode() is deprecated, use explicit Result::fetch*() APIs instead.'
);

if ($arg2 === null) {
Expand All @@ -279,7 +279,7 @@ public function getIterator()
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::getIterator() is deprecated, use Statement::iterateNumeric(), iterateAssociative() ' .
'Statement::getIterator() is deprecated, use Result::iterateNumeric(), iterateAssociative() ' .
'or iterateColumn() instead.'
);

Expand All @@ -296,7 +296,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::fetch() is deprecated, use Statement::fetchNumeric(), fetchAssociative() or fetchOne() instead.'
'Statement::fetch() is deprecated, use Result::fetchNumeric(), fetchAssociative() or fetchOne() instead.'
);

return $this->stmt->fetch($fetchMode);
Expand All @@ -312,7 +312,7 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::fetchAll() is deprecated, use Statement::fetchAllNumeric(), fetchAllAssociative() or ' .
'Statement::fetchAll() is deprecated, use Result::fetchAllNumeric(), fetchAllAssociative() or ' .
'fetchFirstColumn() instead.'
);

Expand All @@ -337,7 +337,7 @@ public function fetchColumn($columnIndex = 0)
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4019',
'Statement::fetchColumn() is deprecated, use Statement::fetchOne() instead.'
'Statement::fetchColumn() is deprecated, use Result::fetchOne() instead.'
);

return $this->stmt->fetchColumn($columnIndex);
Expand All @@ -346,10 +346,20 @@ public function fetchColumn($columnIndex = 0)
/**
* {@inheritdoc}
*
* @deprecated Use Result::fetchNumeric() instead
*
* @throws Exception
*/
public function fetchNumeric()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

try {
if ($this->stmt instanceof Result) {
return $this->stmt->fetchNumeric();
Expand All @@ -364,10 +374,20 @@ public function fetchNumeric()
/**
* {@inheritdoc}
*
* @deprecated Use Result::fetchAssociative() instead
*
* @throws Exception
*/
public function fetchAssociative()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

try {
if ($this->stmt instanceof Result) {
return $this->stmt->fetchAssociative();
Expand All @@ -382,10 +402,20 @@ public function fetchAssociative()
/**
* {@inheritDoc}
*
* @deprecated Use Result::fetchOne() instead
*
* @throws Exception
*/
public function fetchOne()
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

try {
if ($this->stmt instanceof Result) {
return $this->stmt->fetchOne();
Expand All @@ -400,10 +430,20 @@ public function fetchOne()
/**
* {@inheritdoc}
*
* @deprecated Use Result::fetchAllNumeric() instead
*
* @throws Exception
*/
public function fetchAllNumeric(): array
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

try {
if ($this->stmt instanceof Result) {
return $this->stmt->fetchAllNumeric();
Expand All @@ -418,10 +458,20 @@ public function fetchAllNumeric(): array
/**
* {@inheritdoc}
*
* @deprecated Use Result::fetchAllAssociative() instead
*
* @throws Exception
*/
public function fetchAllAssociative(): array
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

try {
if ($this->stmt instanceof Result) {
return $this->stmt->fetchAllAssociative();
Expand All @@ -438,12 +488,22 @@ public function fetchAllAssociative(): array
*
* The result must contain at least two columns.
*
* @deprecated Use Result::fetchAllKeyValue() instead
*
* @return array<mixed,mixed>
*
* @throws Exception
*/
public function fetchAllKeyValue(): array
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

$this->ensureHasKeyValue();

$data = [];
Expand All @@ -459,12 +519,22 @@ public function fetchAllKeyValue(): array
* Returns an associative array with the keys mapped to the first column and the values being
* an associative array representing the rest of the columns and their values.
*
* @deprecated Use Result::fetchAllAssociativeIndexed() instead
*
* @return array<mixed,array<string,mixed>>
*
* @throws Exception
*/
public function fetchAllAssociativeIndexed(): array
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

$data = [];

foreach ($this->fetchAll(FetchMode::ASSOCIATIVE) as $row) {
Expand All @@ -477,10 +547,20 @@ public function fetchAllAssociativeIndexed(): array
/**
* {@inheritdoc}
*
* @deprecated Use Result::fetchFirstColumn() instead
*
* @throws Exception
*/
public function fetchFirstColumn(): array
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

try {
if ($this->stmt instanceof Result) {
return $this->stmt->fetchFirstColumn();
Expand All @@ -495,12 +575,22 @@ public function fetchFirstColumn(): array
/**
* {@inheritDoc}
*
* @deprecated Use Result::iterateNumeric() instead
*
* @return Traversable<int,array<int,mixed>>
*
* @throws Exception
*/
public function iterateNumeric(): Traversable
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

try {
if ($this->stmt instanceof Result) {
while (($row = $this->stmt->fetchNumeric()) !== false) {
Expand All @@ -519,12 +609,22 @@ public function iterateNumeric(): Traversable
/**
* {@inheritDoc}
*
* @deprecated Use Result::iterateAssociative() instead
*
* @return Traversable<int,array<string,mixed>>
*
* @throws Exception
*/
public function iterateAssociative(): Traversable
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

try {
if ($this->stmt instanceof Result) {
while (($row = $this->stmt->fetchAssociative()) !== false) {
Expand All @@ -546,12 +646,22 @@ public function iterateAssociative(): Traversable
*
* The result must contain at least two columns.
*
* @deprecated Use Result::iterateKeyValue() instead
*
* @return Traversable<mixed,mixed>
*
* @throws Exception
*/
public function iterateKeyValue(): Traversable
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

$this->ensureHasKeyValue();

foreach ($this->iterateNumeric() as [$key, $value]) {
Expand All @@ -563,12 +673,22 @@ public function iterateKeyValue(): Traversable
* Returns an iterator over the result set with the keys mapped to the first column and the values being
* an associative array representing the rest of the columns and their values.
*
* @deprecated Use Result::iterateAssociativeIndexed() instead
*
* @return Traversable<mixed,array<string,mixed>>
*
* @throws Exception
*/
public function iterateAssociativeIndexed(): Traversable
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

while (($row = $this->stmt->fetch(FetchMode::ASSOCIATIVE)) !== false) {
yield array_shift($row) => $row;
}
Expand All @@ -577,12 +697,22 @@ public function iterateAssociativeIndexed(): Traversable
/**
* {@inheritDoc}
*
* @deprecated Use Result::iterateColumn() instead
*
* @return Traversable<int,mixed>
*
* @throws Exception
*/
public function iterateColumn(): Traversable
{
Deprecation::triggerIfCalledFromOutside(
'doctrine/dbal',
'https://github.com/doctrine/dbal/issues/4554',
'Statement::%s() is deprecated, use Result::%s() instead.',
__FUNCTION__,
__FUNCTION__
);

try {
if ($this->stmt instanceof Result) {
while (($value = $this->stmt->fetchOne()) !== false) {
Expand Down

0 comments on commit 6c367ff

Please sign in to comment.