Skip to content

Queries in FormDataRepository failing when sql_mode=only_full_group_by is enabled #12

@samsauter

Description

@samsauter

Hello there,

the queries build in FormDataRepository.php which are using a GROUP BY statement are causing exceptions to be thrown if sql_mode=only_full_group_by is configured (which seems to be the case in many server setups).

SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db-1.p0_.persistence_object_identifier' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

I added addGroupBy() statements for every column in this table to get it to work. There are two affected methods:

    public function findAllUniqueForms(): iterable
    {
        $queryBuilder = $this->createQueryBuilder('form');
        return $queryBuilder
            ->groupBy('form.formIdentifier')
	    ->addGroupBy('form.Persistence_Object_Identifier')
            ->addGroupBy('form.hash')
            ->addGroupBy('form.formData')
	    ->addGroupBy('form.date')
	    ->addGroupBy('form.siteName')
	    ->addGroupBy('form.contentDimensions')
            ->addSelect('count(form) AS entryCount')
            ->addSelect('MAX(form.date) as latestDate')
            ->orderBy('latestDate', 'DESC')
            ->getQuery()->execute();
    }
protected function findAllUniqueSiteNames(): array
    {
        $queryBuilder = parent::createQueryBuilder('form');
        $formDataGroupedBySite = $queryBuilder
            ->groupBy('form.siteName')
	    ->addGroupBy('form.Persistence_Object_Identifier')
	    ->addGroupBy('form.formIdentifier')
	    ->addGroupBy('form.hash')
	    ->addGroupBy('form.formData')
	    ->addGroupBy('form.date')
	    ->addGroupBy('form.contentDimensions')
            ->getQuery()->execute();
        …
    }

Do you think this is fine? It seems like it, though.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions