This repository has been archived by the owner on Jan 8, 2020. It is now read-only.
Fix iterating over empty result set with buffering enabled #4450
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In case we using result set with buffering dataSource rewind method should be called at least once before resultSet rewind call, to ensure dataSource valid() would work as expected.
Simple test case:
If no data in result set (ie empty result) when Iterator rewind calls (\Zend\Db\ResultSet\AbstractResultSet::rewind) and buffer is enabled, then dataSource rewind never be called and in this case iteration loop started and first item will be false (at least for Adapter/Pdo/Result). But expected behavior is iteration not started for empty result set.
So, we introduce result set position default state is -1, to ensure first iteration calls dataSource rewind at least one even buffer is enabled
if (!is_array($this->buffer) || $this->position === -1) {
BTW if buffering is disabled we call rewind on dataSource for every iteration as before