Closed HLeithner closed 3 years ago
It's not possible to use an iterator query and a normal at the same time.
Issue: https://github.com/joomla/joomla-cms/issues/34696
Sample code from joomla issue:
public function checkDatabase() { $db = $this->getDbo(); $query = $db->getQuery(true) ->select($db->quoteName('id')) ->from($db->quoteName('#__content')); $db->setQuery($query); $records = $db->getIterator(); $items = $records->count(); $query->clear() ->select($db->quoteName('id')) ->from($db->quoteName('#__categories')); $db->setQuery($query); $db->loadResult(); return $items === $records->count(); }
returns true
returns false
mysql
Works in Joomla 3
The reason is that setQuery closes the old statement:
https://github.com/joomla-framework/database/blob/2.0-dev/src/DatabaseDriver.php#L1848 https://github.com/joomla-framework/database/blob/2.0-dev/src/DatabaseDriver.php#L777
Possible solution see https://github.com/joomla/joomla-cms/issues/34696#issuecomment-879100523 .
It's not possible to use an iterator query and a normal at the same time.
Issue: https://github.com/joomla/joomla-cms/issues/34696
Steps to reproduce the issue
Sample code from joomla issue:
Expected result
returns true
Actual result
returns false
System information (as much as possible)
mysql
Additional comments
Works in Joomla 3
The reason is that setQuery closes the old statement:
https://github.com/joomla-framework/database/blob/2.0-dev/src/DatabaseDriver.php#L1848 https://github.com/joomla-framework/database/blob/2.0-dev/src/DatabaseDriver.php#L777