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
......@@ -2371,7 +2371,7 @@ TCAdefaults.sys_note.email = ' . $this->user['email'];
$queryBuilder->expr()->eq('admin', $queryBuilder->createNamedParameter(1, \PDO::PARAM_INT))
)
->execute()
->fetchColumn(0);
->fetchOne();
}
return $isUserAllowedToLogin;
}
......
......@@ -146,7 +146,7 @@ class CommandLineUserAuthentication extends BackendUserAuthentication
->from('be_users')
->where($queryBuilder->expr()->eq('username', $queryBuilder->createNamedParameter('_cli_')))
->execute()
->fetchColumn(0);
->fetchOne();
return (bool)$count;
}
......
......@@ -184,7 +184,7 @@ class Typo3DatabaseBackend extends AbstractBackend implements TaggableBackendInt
)
)
->execute()
->fetchColumn(0);
->fetchOne();
return (bool)$count;
}
......
......@@ -306,7 +306,7 @@ class FlexFormTools
$rowCount = $queryBuilder
->count('uid')
->execute()
->fetchColumn(0);
->fetchOne();
if ($rowCount !== 1) {
throw new InvalidParentRowException(
'The data structure for field "' . $fieldName . '" in table "' . $tableName . '" has to be looked up'
......@@ -647,7 +647,7 @@ class FlexFormTools
)
)
->execute()
->fetchColumn(0);
->fetchOne();
} elseif ($identifier['type'] === 'tca') {
// Handle "tca" type, see getDataStructureIdentifierFromTcaArray
if (empty($identifier['tableName']) || empty($identifier['fieldName']) || empty($identifier['dataStructureKey'])) {
......
......@@ -2325,7 +2325,7 @@ class DataHandler implements LoggerAwareInterface
$queryBuilder = $this->getUniqueCountStatement($newValue, $table, $field, (int)$id, (int)$newPid);
// For as long as records with the test-value existing, try again (with incremented numbers appended)
$statement = $queryBuilder->execute();
if ($statement->fetchColumn()) {
if ($statement->fetchOne()) {
for ($counter = 0; $counter <= 100; $counter++) {
$newValue = $value . $counter;
if (class_exists(\Doctrine\DBAL\ForwardCompatibility\Result::class) && $statement instanceof \Doctrine\DBAL\ForwardCompatibility\Result) {
......@@ -2333,7 +2333,7 @@ class DataHandler implements LoggerAwareInterface
}
$statement->bindValue(1, $newValue);
$statement->execute();
if (!$statement->fetchColumn()) {
if (!$statement->fetchOne()) {
break;
}
}
......@@ -6832,7 +6832,7 @@ class DataHandler implements LoggerAwareInterface
$queryBuilder->createNamedParameter($page_uid, \PDO::PARAM_INT)
))
->execute()
->fetchColumn(0);
->fetchOne();
if ($count) {
$tableList[] = $table;
}
......@@ -8246,7 +8246,7 @@ class DataHandler implements LoggerAwareInterface
$queryBuilder->expr()->eq($field, $queryBuilder->createNamedParameter($checkTitle, \PDO::PARAM_STR))
)
->execute()
->fetchColumn(0);
->fetchOne();
if ($rowCount) {
return $this->getCopyHeader($table, $pid, $field, $value, $count + 1, $checkTitle);
}
......@@ -8336,7 +8336,7 @@ class DataHandler implements LoggerAwareInterface
$query->createNamedParameter($pageIds, Connection::PARAM_INT_ARRAY)
))
->execute()
->fetchColumn(0);
->fetchOne();
if ($count && ($this->tableReadOnly($table) || !$this->checkModifyAccessList($table))) {
$disallowedTables[] = $table;
}
......
......@@ -365,7 +365,7 @@ class Connection extends \Doctrine\DBAL\Connection implements LoggerAwareInterfa
$query->andWhere($query->expr()->eq($identifier, $query->createNamedParameter($value)));
}
return (int)$query->execute()->fetchColumn(0);
return (int)$query->execute()->fetchOne();
}
/**
......
......@@ -70,7 +70,7 @@ class PDOStatement extends DoctrineDbalPDOStatement
/**
* {@inheritdoc}
*/
public function fetchColumn($columnIndex = 0)
public function fetchOne($columnIndex = 0)
{
try {
$record = parent::fetchColumn($columnIndex);
......@@ -80,4 +80,12 @@ class PDOStatement extends DoctrineDbalPDOStatement
throw new PDOException($exception);
}
}
/**
* {@inheritdoc}
*/
public function fetchColumn($columnIndex = 0)
{
return $this->fetchOne($columnIndex);
}
}
......@@ -259,7 +259,7 @@ class QueryView
$rowCount = $queryBuilder->count('*')
->from($queryGenerator->table)
->where(QueryHelper::stripLogicalOperatorPrefix($queryString))
->execute()->fetchColumn(0);
->execute()->fetchOne();
$t2DataValue = [
'qC' => $saveArr,
......@@ -454,7 +454,7 @@ class QueryView
->from($queryGenerator->table)
->where(QueryHelper::stripLogicalOperatorPrefix($queryString));
$fullQueryString = $queryBuilder->getSQL();
$dataRows = [$queryBuilder->execute()->fetchColumn(0)];
$dataRows = [$queryBuilder->execute()->fetchOne()];
} else {
$fullQueryString = $selectQueryString;
$dataRows = $connection->executeQuery($selectQueryString)->fetchAll();
......@@ -620,7 +620,7 @@ class QueryView
$queryBuilder->createNamedParameter($escapedLikeString, \PDO::PARAM_STR)
);
}
$count = $queryBuilder->orWhere(...$likes)->execute()->fetchColumn(0);
$count = $queryBuilder->orWhere(...$likes)->execute()->fetchOne();
if ($count > 0) {
$queryBuilder = $connection->createQueryBuilder();
......
......@@ -291,7 +291,7 @@ class ReferenceIndex implements LoggerAwareInterface
'ref_uid',
$queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT)
)
)->execute()->fetchColumn(0);
)->execute()->fetchOne();
}
/**
......@@ -996,7 +996,7 @@ class ReferenceIndex implements LoggerAwareInterface
'NOT EXISTS (' . $subQueryBuilder->getSQL() . ')'
)
->execute()
->fetchColumn(0);
->fetchOne();
if ($lostIndexes > 0) {
$error = 'Table ' . $tableName . ' has ' . $lostIndexes . ' lost indexes which are now deleted';
......@@ -1061,7 +1061,7 @@ class ReferenceIndex implements LoggerAwareInterface
$queryBuilder->createNamedParameter($tableNames, Connection::PARAM_STR_ARRAY)
)
)->execute()
->fetchColumn(0);
->fetchOne();
return (int)$lostTables;
}
......
......@@ -940,7 +940,7 @@ class PageRepository implements LoggerAwareInterface
QueryHelper::stripLogicalOperatorPrefix($additionalWhereClause)
)
->execute()
->fetchColumn();
->fetchOne();
if (!$count) {
$page = [];
......@@ -1245,7 +1245,7 @@ class PageRepository implements LoggerAwareInterface
)
)
->execute()
->fetchColumn();
->fetchOne();
if ($numRows > 0) {
return $row;
}
......@@ -1766,7 +1766,7 @@ class PageRepository implements LoggerAwareInterface
)
)
);
if ($bypassEnableFieldsCheck || $queryBuilder->execute()->fetchColumn()) {
if ($bypassEnableFieldsCheck || $queryBuilder->execute()->fetchOne()) {
// Return offline version, tested for its enableFields.
return $newrow;
}
......@@ -1778,7 +1778,7 @@ class PageRepository implements LoggerAwareInterface
$queryBuilder->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, \PDO::PARAM_INT))
);
if ($bypassEnableFieldsCheck || $queryBuilder->execute()->fetchColumn()) {
if ($bypassEnableFieldsCheck || $queryBuilder->execute()->fetchOne()) {
// Means search was done, but no version found.
return 1;
}
......
......@@ -371,7 +371,7 @@ class FileIndexRepository implements SingletonInterface
->from($this->table)
->where(...$constraints)
->execute()
->fetchColumn(0);
->fetchOne();
return (bool)$count;
}
......
......@@ -164,7 +164,7 @@ class ProcessedFileRepository extends AbstractRepository implements LoggerAwareI
)
)
->execute()
->fetchColumn(0);
->fetchOne();
}
/**
......
......@@ -59,7 +59,7 @@ class FileSearchResult implements FileSearchResultInterface
return $this->resultCount;
}
$this->resultCount = (int)FileSearchQuery::createCountForSearchDemand($this->searchDemand)->execute()->fetchColumn(0);
$this->resultCount = (int)FileSearchQuery::createCountForSearchDemand($this->searchDemand)->execute()->fetchOne();
return $this->resultCount;
}
......
......@@ -547,7 +547,7 @@ class ExtendedFileUtility extends BasicFileUtility
'tablename',
$queryBuilder->createNamedParameter('sys_file_metadata', \PDO::PARAM_STR)
)
)->execute()->fetchColumn(0);
)->execute()->fetchOne();
$hasReferences = $numberOfReferences > 0;
if ($hasReferences) {
......
......@@ -562,7 +562,7 @@ class RootlineUtility
)
->execute();
$movePointerId = $statement->fetchColumn();
$movePointerId = $statement->fetchOne();
return $movePointerId ? (int)$movePointerId : null;
}
......
......@@ -256,7 +256,7 @@ abstract class AbstractDataHandlerActionTestCase extends FunctionalTestCase
$actualErrorLogEntries = (int)$queryBuilder
->count('uid')
->execute()
->fetchColumn(0);
->fetchOne();
$entryMessages = array_map(
function (array $entry) {
......
......@@ -104,7 +104,7 @@ class ActionTest extends AbstractDataHandlerActionTestCase
->from('tt_content')
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(self::VALUE_ContentId, \PDO::PARAM_INT)))
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($expected, $flexFormContent);
}
......@@ -186,7 +186,7 @@ class ActionTest extends AbstractDataHandlerActionTestCase
->from('tt_content')
->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(self::VALUE_ContentId, \PDO::PARAM_INT)))
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals($expected, $flexFormContent);
}
......
......@@ -61,7 +61,7 @@ class ActionTest extends AbstractDataHandlerActionTestCase
->from('sys_file_reference')
->where($queryBuilder->expr()->eq('uid_local', $queryBuilder->createNamedParameter(20, \PDO::PARAM_INT)))
->execute()
->fetchColumn(0);
->fetchOne();
self::assertEquals(2, $referenceCount);
}
......
......@@ -17,7 +17,7 @@ declare(strict_types=1);
namespace TYPO3\CMS\Core\Tests\Unit\Configuration\FlexForm;
use Doctrine\DBAL\Driver\Statement;
use Doctrine\DBAL\Statement;
use Prophecy\Argument;
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
use TYPO3\CMS\Core\Cache\CacheManager;
......@@ -657,7 +657,7 @@ class FlexFormToolsTest extends UnitTestCase
$queryBuilderProphecy->count('uid')->shouldBeCalled()->willReturn($queryBuilderProphecy);
// First db call returns $secondRow, second returns $thirdRow, which points back to $initialRow -> exception
$statementProphecy->fetchColumn(0)->willReturn(1);
$statementProphecy->fetchOne()->willReturn(1);
$statementProphecy->fetch()->willReturn($secondRow, $thirdRow);
$this->expectException(InvalidParentRowLoopException::class);
......@@ -724,7 +724,7 @@ class FlexFormToolsTest extends UnitTestCase
$queryBuilderProphecy->where('uid = 1')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
$queryBuilderProphecy->count('uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow, second returns $thirdRow. $thirdRow has pid 0 and still no ds -> exception
$statementProphecy->fetch()->willReturn($secondRow, $thirdRow);
......@@ -866,7 +866,7 @@ class FlexFormToolsTest extends UnitTestCase
$queryBuilderProphecy->where('uid = 1')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
$queryBuilderProphecy->count('uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow, second returns $thirdRow. $thirdRow resolves ds
$statementProphecy->fetch()->willReturn($secondRow, $thirdRow);
......@@ -925,7 +925,7 @@ class FlexFormToolsTest extends UnitTestCase
$queryBuilderProphecy->where('uid = 2')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$queryBuilderProphecy->count('uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
$statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow. $secondRow resolves DS and does not look further up
$statementProphecy->fetch()->willReturn($secondRow);
......@@ -988,7 +988,7 @@ class FlexFormToolsTest extends UnitTestCase
$queryBuilderProphecy->where('uid = 2')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$queryBuilderProphecy->count('uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
$statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow. $secondRow resolves DS and does not look further up
$statementProphecy->fetch()->willReturn($secondRow);
......@@ -1072,7 +1072,7 @@ class FlexFormToolsTest extends UnitTestCase
$queryBuilderProphecy->where('uid = 2')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
$queryBuilderProphecy->count('uid')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$statementProphecy->fetchColumn(0)->shouldBeCalled()->willReturn(1);
$statementProphecy->fetchOne()->shouldBeCalled()->willReturn(1);
// First db call returns $secondRow. $secondRow resolves DS and does not look further up
$statementProphecy->fetch()->willReturn($secondRow);
......@@ -1268,7 +1268,7 @@ class FlexFormToolsTest extends UnitTestCase
$expressionBuilderProphecy->eq('uid', 42)->shouldBeCalled()->willReturn('uid = 42');
$queryBuilderProphecy->where('uid = 42')->shouldBeCalled()->willReturn($queryBuilderRevelation);
$queryBuilderProphecy->execute()->shouldBeCalled()->willReturn($statementProphecy->reveal());
$statementProphecy->fetchColumn(0)->willReturn('
$statementProphecy->fetchOne()->willReturn('
<T3DataStructure>
<sheets></sheets>
</T3DataStructure>
......
......@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Core\Tests\Unit\Database;
use Doctrine\DBAL\Configuration;
use Doctrine\DBAL\Driver\Mysqli\Driver;
use Doctrine\DBAL\Driver\Mysqli\MysqliConnection;
use Doctrine\DBAL\Driver\ResultStatement;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Statement;
......@@ -493,18 +494,16 @@ class ConnectionTest extends UnitTestCase
*/
public function countQueries(array $args, string $expectedQuery, array $expectedParameters)
{
$resultStatement = $this->createMock(Statement::class);
$resultStatement = $this->createMock(ResultStatement::class);
$resultStatement->expects(self::once())
->method('fetchColumn')
->with(0)
->willReturn(0);
->method('fetch')
->with(\PDO::FETCH_NUM)
->willReturn(false);
$this->connection->expects(self::once())
->method('executeQuery')
->with($expectedQuery, $expectedParameters)
->willReturn($resultStatement);
$this->connection->count(...$args);
}
......
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