[BUGFIX] Extbase: Don't use ORDER BY with COUNT(*) SQL statements 13/51313/2
authorMorton Jonuschat <m.jonuschat@mojocode.de>
Sun, 15 Jan 2017 05:36:02 +0000 (21:36 -0800)
committerMorton Jonuschat <m.jonuschat@mojocode.de>
Sun, 15 Jan 2017 21:24:09 +0000 (22:24 +0100)
Databases that adhere to the SQL92 standard and enforce having all
columns that are using in any part of the query be part of the
SELECT/COUNT field list will throw an error when using COUNT(*) in
combination with ORDER BY.
Since ordering has no influence on the result of COUNT(*) the
ORDER BY query part has been disabled in getObjectCountByQuery().

Change-Id: Idd7c73d172116a83feb653db6a0167fb0bea2023
Resolves: #79322
Releases: master
Reviewed-on: https://review.typo3.org/51313
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Tymoteusz Motylewski <t.motylewski@gmail.com>
Reviewed-by: Manuel Selbach <manuel_selbach@yahoo.de>
Tested-by: Manuel Selbach <manuel_selbach@yahoo.de>
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>

index 4eec01c..95aaa1a 100644 (file)
@@ -416,9 +416,13 @@ class Typo3DbBackend implements BackendInterface, SingletonInterface
         $queryBuilder = $this->objectManager->get(Typo3DbQueryParser::class)
-                ->convertQueryToDoctrineQueryBuilder($query);
+            ->convertQueryToDoctrineQueryBuilder($query);
         try {
-            $count = $queryBuilder->count('*')->execute()->fetchColumn(0);
+            $count = $queryBuilder->resetQueryPart('orderBy')
+                ->count('*')
+                ->execute()
+                ->fetchColumn(0);
         } catch (DBALException $e) {
             throw new SqlErrorException($e->getPrevious()->getMessage(), 1472074379);