Bug #82910
closedInconsistencies in queries from execute and count
100%
Description
The QueryResult functions execute and count build currently 2 different queries.
The execute functions runs into the Typo3DbBackend->getObjectDataByRawQuery function where the final query is what I wrote in the statement.
But the count function runs into the Typo3DbBackend->getObjectCountByQuery function.
The interesting thing about this function is that it respects the QuerySettings of the query object contrary to the getObjectDataByRawQuery function(it is adding clauses for sys_language_uid, hidden, deleted, storage pid(!!!), etc).
As a result I got inconsistencies between what the count function is returning and how many results I really got.
Code to reproduce/debug it:
$query = $this->testRepository->createQuery();
$statement = "SELECT * FROM tx_test_domain_model_test WHERE 1";
$query->statement($statement);
echo "SizeOf ToArray:\n";
echo sizeof($query->execute()->toArray()); # result: 1 with 1 object in database
echo "\nQueryResultInterface Count:\n";
echo $query->execute()->count(); # result: 0 with 1 object in database
# now set the QuerySettings and we'll get results with count
$query->getQuerySettings()->setRespectStoragePage(False);
echo "\nSizeOf ToArray:\n";
echo sizeof($query->execute()->toArray()); # result: 1 with 1 object in database
echo "\nQueryResultInterface Count:\n";
echo $query->execute()->count(); # result: 1 with 1 object in database
Executed queries:
execute function:
SELECT *
FROM tx_test_domain_model_test
WHERE 1
count function:
SELECT tx_test_domain_model_test.*
FROM tx_test_domain_model_test
WHERE 1 = 1
AND ( tx_test_domain_model_test.sys_language_uid IN ( 0, -1 ) )
AND tx_test_domain_model_test.pid IN (0)
AND tx_test_domain_model_test.deleted = 0
AND tx_test_domain_model_test.hidden = 0
AND tx_test_domain_model_test.starttime <= 1508943660
AND ( tx_test_domain_model_test.endtime = 0
OR tx_test_domain_model_test.endtime > 1508943660 )
ORDER BY tx_test_domain_model_test.sorting ASC
What would be the desired behavior? Respect the QuerySettings on execute with statements or ignore them on count?
Updated by Georg Ringer about 7 years ago
I would propose to check 7 how it was there.
Updated by Steffen Keuper about 7 years ago
Georg Ringer wrote:
I would propose to check 7 how it was there.
it's inconsistent across nearly all versions(6 and 7 at least)
Updated by Gerrit Code Review almost 7 years ago
- Status changed from New to Under Review
Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/54844
Updated by Gerrit Code Review almost 7 years ago
Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/54844
Updated by Gerrit Code Review almost 7 years ago
Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/54844
Updated by Gerrit Code Review almost 7 years ago
Patch set 1 for branch TYPO3_8-7 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/55214
Updated by Sebastian Hofer almost 7 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset 3ed515fbb316e81e3ffe09a8ec20e4da568a0df6.