Project

General

Profile

Actions

Bug #82910

closed

Inconsistencies in queries from execute and count

Added by Steffen Keuper over 6 years ago. Updated over 5 years ago.

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

100%

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

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?

Actions #1

Updated by Georg Ringer over 6 years ago

I would propose to check 7 how it was there.

Actions #2

Updated by Steffen Keuper over 6 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)

Actions #3

Updated by Gerrit Code Review over 6 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

Actions #4

Updated by Gerrit Code Review over 6 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

Actions #5

Updated by Gerrit Code Review over 6 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

Actions #6

Updated by Gerrit Code Review over 6 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

Actions #7

Updated by Sebastian Hofer over 6 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
Actions #8

Updated by Benni Mack over 5 years ago

  • Status changed from Resolved to Closed
Actions

Also available in: Atom PDF