Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
samsauter opened this issue Jun 23, 2021 · 8 comments · May be fixed by #13
Open

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

samsauter opened this issue Jun 23, 2021 · 8 comments · May be fixed by #13

Comments

@samsauter
Copy link

samsauter commented Jun 23, 2021

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.

@daniellienert
Copy link
Member

@samsauter, thanks for the issue. Sadly your approach won't work. When grouping by anything, the grouping has no effect anymore. I currently try to get my mariaDB into that mode.

@samsauter
Copy link
Author

@daniellienert Oh, of course … I did not check with multiple sites or just different forms and look and the actual results. I just wanted the query to not throw an error anymore. Thank you for looking into it!

@paavo
Copy link
Contributor

paavo commented Mar 4, 2022

Any plans if and when this will be fixed @daniellienert?
I'd love to use this package.

@paavo
Copy link
Contributor

paavo commented Apr 25, 2022

Is there a known workaround @daniellienert or @samsauter?
disabling sql_mode=only_full_group_by maybe?

@paavo
Copy link
Contributor

paavo commented Oct 11, 2022

Looks like we need to reopen this bug @daniellienert @samsauter 🙈
When using privilegeTargets this throws an Error SELECT list is not in GROUP BY

@paavo
Copy link
Contributor

paavo commented Dec 1, 2022

May someone reopen this Bug @daniellienert @samsauter?

@samsauter
Copy link
Author

May someone reopen this Bug @daniellienert @samsauter?

Sry, I don't have permissions to reopen.

@daniellienert daniellienert reopened this Dec 1, 2022
@daniellienert
Copy link
Member

Hey Guys, I reopened the issue. I already tried to rewrite the queries but it seems that it is pretty hard to do using the doctrine persistence layer and we would need to completely rewrite it. Sadly I have to say, that we do not have this restrictions in any setup of our projects. But of course we appreciate any PR fixing the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

3 participants