Skip to content

Commit

Permalink
[BUGFIX] Fix for sql_mode=only_full_group_by
Browse files Browse the repository at this point in the history
In newer MySQL versions the query in GlossaryRepository::findAllForIndex()
will fail if sql_mode contains only_full_group_by.

The problem is the ORDER BY clause which does not match the GROUP BY.

Resolves: #10
  • Loading branch information
sypets committed Jan 14, 2020
1 parent 1c820e6 commit 51bc260
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions Classes/Domain/Repository/GlossaryRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
namespace SveWap\A21glossary\Domain\Repository;

use SveWap\A21glossary\Domain\Model\Glossary;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\QueryBuilder;
use TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException;
use TYPO3\CMS\Extbase\Persistence\Generic\Query;
use TYPO3\CMS\Extbase\Persistence\Generic\Storage\Typo3DbQueryParser;
Expand All @@ -21,6 +24,8 @@ class GlossaryRepository extends Repository
*/
public function findAllForIndex()
{
$previousOrderings = $this->defaultOrderings;
$this->defaultOrderings = [];
/** @var Query $query */
$query = $this->createQuery();
// Get the query parser via object manager to use dependency injection
Expand All @@ -30,8 +35,9 @@ public function findAllForIndex()
// Add our select and group by
$queryBuilder->selectLiteral('substr(' . $queryBuilder->quoteIdentifier('short') . ', 1, 1) AS ' . $queryBuilder->quoteIdentifier('char'))
->groupBy('char');

return $query->statement($queryBuilder)->execute(true);
$result = $query->statement($queryBuilder)->execute(true);
$this->defaultOrderings = $previousOrderings;
return $result;
}

/**
Expand Down

0 comments on commit 51bc260

Please sign in to comment.