Bug #80464
opencount() not working correctly in Extbase when using custom statement
0%
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/
Updated by Julian Hofmann over 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
Updated by Julian Hofmann over 7 years ago
- Related to Bug #80820: Extbase - Wrong size of QueryResult object after make statement added
Updated by Sven Burkert over 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;
Updated by Mathias Brodala about 4 years ago
- Related to Bug #87655: Wrong count by extbase with own QueryBuilder added
Updated by Michael Grundkötter over 3 years ago
- Related to Bug #93576: Typo3DbBackend::getObjectCountByQuery does not work correctly with custom doctrine queries added