[TYPO3-mvc] Count query results
Stefan Isak
stefanisak at googlemail.com
Wed May 19 12:42:38 CEST 2010
Looking at public function getObjectCountByQuery() in
Tx_Extbase_Persistence_Storage_Typo3DbBackend makes it clear to me. Calling
the count() method always results in a statement like SELECT DISTINCT
COUNT(*) FROM.
The problem is that the usage of DISTINCT with COUNT(*) doesn't have any
effect at all.
It better should be something like SELECT COUNT(DISTINCT column_name) FROM.
I can help myself, adding 2 lines of code manipulating $statementParts. But
it's just being able to get by.
Should I file a bug?
So long.
Stefan
2010/5/18 Stefan Isak <stefanisak at googlemail.com>
> Hi Jochen,
>
> the very first thing I thought was that it just isn't what I expected.
> But I realized that the same query is correct when I simply execute it.
>
> Maybe the problem is that I use constraints with m:m relations like
> $query->equals('objects.uid');
> I think those relations can't be resolved by the count() method unlike the
> execute() method.
>
> Am I wrong or if not, is there a workaround?
>
> So long.
> Stefan
>
>
> 2010/5/18 Jochen Rau <jochen.rau at typoplanet.de>
>
> > Hi Stefan.
> >
> >
> > On 18.05.10 11:04, Stefan Isak wrote:
> >
> >> Hey,
> >>
> >> got a question on counting rows of a query.
> >> What is the best approach to get the number of results for a query
> having
> >> constraints?
> >>
> >> This is my query:
> >> $query = $this->createQuery();
> >> $constraints = array();
> >> $constraints[] = $query->equals(...);
> >> $constraints[] = $query->equals(...);
> >> $query->matching($query->logicalAnd($constraints))->execute();
> >>
> >> What I tried was
> >> $query->matching($query->logicalAnd($constraints))->count();
> >>
> >> Although the result is a number, it is a wrong one.
> >>
> >> Any suggestions on that?
> >>
> >
> > This is the best approach. Maybe the number is right but does not fit to
> > you expectations ;-)
> >
> > Could you please post the result you expected and the actual result? What
> > do you want to count?
> >
> > Regards
> > Jochen
> >
> > _______________________________________________
> > TYPO3-project-typo3v4mvc mailing list
> > TYPO3-project-typo3v4mvc at lists.typo3.org
> > http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
> >
> _______________________________________________
> TYPO3-project-typo3v4mvc mailing list
> TYPO3-project-typo3v4mvc at lists.typo3.org
> http://lists.typo3.org/cgi-bin/mailman/listinfo/typo3-project-typo3v4mvc
>
More information about the TYPO3-project-typo3v4mvc
mailing list