Project

General

Profile

Actions

Bug #80464

open

count() not working correctly in Extbase when using custom statement

Added by Christian Wellinghorst about 7 years ago. Updated about 5 years ago.

Status:
New
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2017-03-27
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

When creating a Query object and assigning a custom statement, the count() method in QueryResult might not work correctly (depending on the query).
Once the QueryResult is initilialized, count() will return the correct result since it will use result array.

If count() is called before that, the error appears in TYPO3\CMS\Extbase\Persistence\Generic\Storage::getObjectCountByQuery()

In my case, i have a query on an extension table where I left join another table of the same extension (as the extension is not public it would be no use to add the statement here).
The problem is: the joined table, a condition referencing the joined table as well as one (the last) condition referencing the main table are ignored within getObjectCountByQuery().
The result is that getObjectCountByQuery() effectively returns the raw count of all records in the main table that are not deleted or hidden (in this case).

If count() is not supposed to work with custom statements, this should be annotated in the code and I would prefer returning "NULL" or "false" as a default in that case - though I can't imagine this is intended behavior.
There appear to be other cases where count() does not work correctly with custom statement, so this might not be limited to left joins:
https://www.typo3.net/forum/thematik/zeige/thema/108484/


Related issues 3 (2 open1 closed)

Related to TYPO3 Core - Bug #80820: Extbase - Wrong size of QueryResult object after make statementClosed2017-04-12

Actions
Related to TYPO3 Core - Bug #87655: Wrong count by extbase with own QueryBuilderAccepted2019-02-05

Actions
Related to TYPO3 Core - Bug #93576: Typo3DbBackend::getObjectCountByQuery does not work correctly with custom doctrine queriesNew2021-02-24

Actions
Actions #1

Updated by Julian Hofmann almost 7 years ago

  • TYPO3 Version changed from 7 to 8

smichaelsen has written an extension of QueryResult which solves the problem: https://gist.github.com/smichaelsen/2bfdfb872d04a0776f01

Actions #2

Updated by Julian Hofmann almost 7 years ago

  • Related to Bug #80820: Extbase - Wrong size of QueryResult object after make statement added
Actions #3

Updated by Sven Burkert about 5 years ago

I also had this bug (in TYPO3 7.6.31), even for simple (or invalid!) queries like:

$statement = 'SELECT * from mytable WHERE uid=1';
$statement = 'SELECT * from notexistingtable';

This helped:

$result = $query->statement($statement)->execute();
$result->current();
return $result;

Actions #4

Updated by Mathias Brodala over 3 years ago

  • Related to Bug #87655: Wrong count by extbase with own QueryBuilder added
Actions #5

Updated by Michael Grundkötter about 3 years ago

  • Related to Bug #93576: Typo3DbBackend::getObjectCountByQuery does not work correctly with custom doctrine queries added
Actions

Also available in: Atom PDF