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?