[+BUGFIX] (Persistence): return correct objectCountByQuery when query
authorMarc Bastian Heinrichs <heinrichs@mbh-web.de>
Sun, 6 Mar 2011 15:21:53 +0000 (16:21 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 26 Jun 2011 23:16:45 +0000 (01:16 +0200)
contains left join and no limit

When using DISTINCT with COUNT, the DISTINCT has to be inside the
COUNT otherwise the DISTINCT works only on the returned single number
of rows with doublets, what has no effect.

Fixes: #13075

Change-Id: Ie2359d593004e012ca71ac5769b8806b43596855

typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php

index ef5c61b..af69e2f 100644 (file)
@@ -279,6 +279,10 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
                        $count = $this->databaseHandle->sql_num_rows($result);
                } else {
                        $statementParts['fields'] = array('COUNT(*)');
+                       if (isset($statementParts['keywords']['distinct'])) {
+                               unset($statementParts['keywords']['distinct']);
+                               $statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.uid)');
+                       }
                        $statement = $this->buildQuery($statementParts, $parameters);
                        $this->replacePlaceholders($statement, $parameters);
                        $result = $this->databaseHandle->sql_query($statement);