Commit d6fa37ea authored by Benni Mack's avatar Benni Mack Committed by Oliver Bartsch
Browse files

[TASK] Replace fetchColumn with fetchOne for Doctrine DBAL

This change replaces all query results from the
database from fetchColumn() to fetchOne(), as this
is the new API used in Doctrine DBAL.

This change is one of a few to prepare for
Doctrine DBAL 3.0 compatibility.

Resolves: #94605
Releases: master
Change-Id: Ia9ca2bbb7b2c16a230c5946941cc3023203f494d
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/69917


Tested-by: core-ci's avatarcore-ci <typo3@b13.com>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Oliver Bartsch's avatarOliver Bartsch <bo@cedev.de>
parent b6c2a5ea
......@@ -15,7 +15,7 @@
namespace TYPO3\CMS\Core\Tests\Unit\Resource\Repository;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Statement;
use Prophecy\Argument;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
......
......@@ -15,7 +15,7 @@
namespace TYPO3\CMS\Core\Tests\Unit\Tree\TableConfiguration;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Statement;
use Prophecy\Argument;
use TYPO3\CMS\Backend\Tree\TreeNode;
use TYPO3\CMS\Backend\Tree\TreeNodeCollection;
......
......@@ -15,7 +15,7 @@
namespace TYPO3\CMS\Core\Tests\Unit\Utility\File;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Statement;
use Prophecy\Argument;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Expression\ExpressionBuilder;
......@@ -78,7 +78,7 @@ class ExtendedFileUtilityTest extends UnitTestCase
$expressionBuilderProphet->neq(Argument::cetera())->willReturn('1 != 1');
$expressionBuilderProphet->in(Argument::cetera())->willReturn('uid IN (1)');
$databaseStatementProphet = $this->prophesize(Statement::class);
$databaseStatementProphet->fetchColumn(Argument::cetera())->willReturn(1);
$databaseStatementProphet->fetchOne(Argument::cetera())->willReturn(1);
$queryBuilderProphet = $this->prophesize(QueryBuilder::class);
$queryBuilderProphet->getRestrictions()->willReturn(GeneralUtility::makeInstance(DefaultRestrictionContainer::class));
$queryBuilderProphet->count(Argument::cetera())->willReturn($queryBuilderProphet);
......
......@@ -17,7 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Dashboard;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Statement;
use Psr\Container\ContainerInterface;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
......
......@@ -53,6 +53,6 @@ class NumberOfFailedLoginsDataProvider implements NumberWithIconDataProviderInte
)
)
->execute()
->fetchColumn();
->fetchOne();
}
}
......@@ -93,7 +93,7 @@ class SysLogErrorsDataProvider implements ChartDataProviderInterface
)
)
->execute()
->fetchColumn();
->fetchOne();
}
protected function calculateDataForLastDays(): void
......
......@@ -71,6 +71,6 @@ class TypeOfUsersChartDataProvider implements ChartDataProviderInterface
)
)
->execute()
->fetchColumn();
->fetchOne();
}
}
......@@ -346,7 +346,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
}
try {
$count = $queryBuilder->execute()->fetchColumn(0);
$count = $queryBuilder->execute()->fetchOne();
} catch (DBALException $e) {
throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074379, $e);
}
......@@ -402,7 +402,7 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
try {
$uid = (int)$queryBuilder
->execute()
->fetchColumn(0);
->fetchOne();
if ($uid > 0) {
return $uid;
}
......
......@@ -76,7 +76,7 @@ class AddTest extends FunctionalTestCase
)
)
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals(1, $newBlogCount);
}
......
......@@ -88,7 +88,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->createNamedParameter($this->blog->getUid(), \PDO::PARAM_INT)
)
)->execute()
->fetchColumn(0);
->fetchOne();
$newPostTitle = 'sdufhisdhuf';
$newPost = new Post();
......@@ -109,7 +109,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->createNamedParameter($this->blog->getUid(), \PDO::PARAM_INT)
)
)->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($countPostsOriginal + 1, $countPosts);
$queryBuilder->resetQueryParts();
......@@ -142,7 +142,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_post')
->execute()
->fetchColumn(0);
->fetchOne();
$queryBuilder->resetQueryParts();
$post = $queryBuilder
......@@ -172,7 +172,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_post')
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($countPostsOriginal - 1, $countPosts);
$queryBuilder->resetQueryParts();
......@@ -219,7 +219,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_post')
->execute()
->fetchColumn(0);
->fetchOne();
/** @var Post $newPost */
$newPost = new Post();
......@@ -245,7 +245,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_post')
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($countPostsOriginal + 1, $countPosts);
//last post
......@@ -295,7 +295,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_post')
->execute()
->fetchColumn(0);
->fetchOne();
$posts = clone $this->blog->getPosts();
$counter = 1;
......@@ -312,7 +312,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_post')
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($countPostsOriginal - 1, $countPosts);
$queryBuilder->resetQueryParts();
......@@ -345,7 +345,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_post')
->execute()
->fetchColumn(0);
->fetchOne();
$posts = clone $this->blog->getPosts();
$postsArray = $posts->toArray();
......@@ -371,7 +371,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_post')
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($countPostsOriginal, $countPosts);
$queryBuilder->getRestrictions()->removeAll();
......@@ -422,7 +422,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_tag')
->execute()
->fetchColumn(0);
->fetchOne();
$newTagTitle = 'sdufhisdhuf';
......@@ -440,7 +440,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_tag')
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($countOriginal + 1, $count);
$queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_post_tag_mm');
......@@ -474,7 +474,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_tag')
->execute()
->fetchColumn(0);
->fetchOne();
$postRepository = $this->getContainer()->get(PostRepository::class);
$post = $postRepository->findByUid(1);
......@@ -494,7 +494,7 @@ class RelationTest extends FunctionalTestCase
->count('*')
->from('tx_blogexample_domain_model_tag')
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($countOriginal, $countTags);
$queryBuilder = (new ConnectionPool())->getQueryBuilderForTable('tx_blogexample_post_tag_mm');
......@@ -551,7 +551,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->expr()->eq('uid_local', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->execute()
->fetchColumn(0);
->fetchOne();
$postRepository = $this->getContainer()->get(PostRepository::class);
$post = $postRepository->findByUid(1);
......@@ -580,7 +580,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->expr()->eq('uid_local', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($countTagsOriginal + 1, $countTags);
$queryBuilder->resetQueryParts();
......@@ -632,7 +632,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->expr()->eq('uid_local', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals(10, $countTags);
$postRepository = $this->getContainer()->get(PostRepository::class);
......@@ -657,7 +657,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->expr()->eq('uid_local', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals(9, $countTags);
$queryBuilder->resetQueryParts();
......@@ -710,7 +710,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->expr()->eq('uid_local', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals(10, $countTags);
$postRepository = $this->getContainer()->get(PostRepository::class);
......@@ -745,7 +745,7 @@ class RelationTest extends FunctionalTestCase
$queryBuilder->expr()->eq('uid_local', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals(10, $countTags);
$queryBuilder->resetQueryParts();
......@@ -860,7 +860,7 @@ class RelationTest extends FunctionalTestCase
)
)
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals(4, $countCategories);
$postRepository = $this->getContainer()->get(PostRepository::class);
......@@ -908,7 +908,7 @@ class RelationTest extends FunctionalTestCase
)
)
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals(4, $countCategories);
$postRepository = $this->getContainer()->get(PostRepository::class);
......@@ -940,7 +940,7 @@ class RelationTest extends FunctionalTestCase
)
)
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals(5, $countCategories);
}
......@@ -986,7 +986,7 @@ class RelationTest extends FunctionalTestCase
)
)
->execute()
->fetchColumn(0);
->fetchOne();
// one category is hidden, so the expected count has to be one less
$newBlogCategoryCount--;
......
......@@ -15,7 +15,7 @@
namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Storage;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Statement;
use Prophecy\Argument;
use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\WorkspaceAspect;
......@@ -97,7 +97,7 @@ class Typo3DbBackendTest extends UnitTestCase
$expressionBuilderProphet = $this->prophesize(ExpressionBuilder::class);
$expressionBuilderProphet->eq(Argument::cetera())->willReturn('1 = 1');
$queryResultProphet = $this->prophesize(Statement::class);
$queryResultProphet->fetchColumn(Argument::cetera())->willReturn($expectedUid);
$queryResultProphet->fetchOne(Argument::cetera())->willReturn($expectedUid);
$queryBuilderProphet = $this->prophesize(QueryBuilder::class);
$queryBuilderProphet->execute()->willReturn($queryResultProphet->reveal());
$queryBuilderProphet->expr()->willReturn($expressionBuilderProphet->reveal());
......
......@@ -73,7 +73,7 @@ class FrontendUserGroupRepository
->setMaxResults(1)
;
$column = $query->execute()->fetchColumn();
$column = $query->execute()->fetchOne();
return $column === false ? null : (int)$column;
}
}
......@@ -103,7 +103,7 @@ class FrontendUserRepository
)
;
return (bool)$query->execute()->fetchColumn();
return (bool)$query->execute()->fetchOne();
}
/**
......@@ -184,7 +184,7 @@ class FrontendUserRepository
$query->andWhere($queryBuilder->expr()->in('pid', $pages));
}
$column = $query->execute()->fetchColumn();
$column = $query->execute()->fetchOne();
return $column === false || $column === '' ? null : (string)$column;
}
......@@ -239,7 +239,7 @@ class FrontendUserRepository
->setMaxResults(1)
;
$column = $query->execute()->fetchColumn();
$column = $query->execute()->fetchOne();
return $column === false ? null : (int)$column;
}
}
......@@ -155,7 +155,7 @@ final class MigrateFeloginPlugins implements UpgradeWizardInterface
$this->getFlexformConstraints($queryBuilder)
);
return (bool)$queryBuilder->execute()->fetchColumn();
return (bool)$queryBuilder->execute()->fetchOne();
}
/**
......
......@@ -110,7 +110,7 @@ final class MigrateFeloginPluginsCtype implements UpgradeWizardInterface, Repeat
->where(
$queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter($this->getOldCType()))
)
->execute()->fetchColumn();
->execute()->fetchOne();
return (bool)$elementCount;
}
......
......@@ -173,7 +173,7 @@ class FrontendUserRepositoryTest extends FunctionalTestCase
))
;
self::assertSame($newPasswordHash, $query->execute()->fetchColumn());
self::assertSame($newPasswordHash, $query->execute()->fetchOne());
}
/**
......
......@@ -1191,7 +1191,7 @@ class FileList
)
)
->execute()
->fetchColumn();
->fetchOne();
return $this->generateReferenceToolTip($referenceCount, $fileOrFolderObject);
}
......
......@@ -15,8 +15,8 @@
namespace TYPO3\CMS\Frontend\ContentObject;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Exception as DBALException;
use Doctrine\DBAL\Statement;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Log\LoggerAwareInterface;
......@@ -2642,7 +2642,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
$conf['select.']['selectFields'] = 'count(*)';
$statement = $this->exec_getQuery($conf['table'], $conf['select.']);
return (int)$statement->fetchColumn(0);
return (int)$statement->fetchOne();
}
/**
......@@ -5854,7 +5854,7 @@ class ContentObjectRenderer implements LoggerAwareInterface
}
try {
$count = $countQueryBuilder->execute()->fetchColumn(0);
$count = $countQueryBuilder->execute()->fetchOne();
$conf['max'] = str_ireplace('total', $count, $conf['max']);
$conf['begin'] = str_ireplace('total', $count, $conf['begin']);
} catch (DBALException $e) {
......
......@@ -15,7 +15,7 @@
namespace TYPO3\CMS\Frontend\Plugin;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Statement;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\QueryHelper;
......
......@@ -17,7 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Frontend\Tests\Unit\ContentObject\Menu;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Statement;
use Prophecy\Argument;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Cache\Frontend\FrontendInterface;
......
Supports Markdown
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