Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix data loss on multiple Result#rewind() calls #273

Merged
merged 1 commit into from
Dec 17, 2022

Conversation

Grundik
Copy link
Contributor

@Grundik Grundik commented Dec 17, 2022

Q A
Documentation no
Bugfix yes
BC Break maybe?
New Feature no
RFC no
QA no

Description

Fixes #196.

BC break can occur if one deliberately used this bug as a feature. But that should not be the case in sane projects.

Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me, although I don't understand the code 🤣

To be clear, previously rewinding twice would lead to undefined behaviour?

@Grundik
Copy link
Contributor Author

Grundik commented Dec 17, 2022

Yes, as stated in referenced issue. Calling ->rewind() just caused one row to be read from database. Always. Even if current positions already was at the beginning of result.

@samsonasik
Copy link
Member

samsonasik commented Dec 17, 2022

@Ocramius iirc, call ->rewind() was requires ->buffer() call to always back to position 0. It probably requires new test on combination with ->buffer()

@Ocramius
Copy link
Member

Ok, given @samsonasik's feedback, could such a test be introduced, @Grundik?

I'd then gladly merge, even at the risk of minor BC issues.

@Grundik
Copy link
Contributor Author

Grundik commented Dec 17, 2022

As I can see, buffering for PDO results are explicitly disabled:

    /**
     * @return void
     */
    public function buffer()
    {
    }

    /**
     * @return bool|null
     */
    public function isBuffered()
    {
        return false;
    }

So, this should not be an issue at all.

@samsonasik
Copy link
Member

That's on class implements AbstractResultSet in general

public function buffer()
{
if ($this->buffer === -2) {
throw new Exception\RuntimeException('Buffering must be enabled before iteration is started');
} elseif ($this->buffer === null) {
$this->buffer = [];
if ($this->dataSource instanceof ResultInterface) {
$this->dataSource->rewind();
}
}
return $this;
}

@samsonasik
Copy link
Member

This is my old blog post about buffer() to set position 0 on rewind() call

https://samsonasik.wordpress.com/2019/08/05/using-buffer-for-resultsetrewind-after-resultsetnext-called-in-zenddb/

@Grundik
Copy link
Contributor Author

Grundik commented Dec 17, 2022

Will this be enough?

@samsonasik
Copy link
Member

Yes, that's should be enough 👍

Signed-off-by: Grundik <grundik@ololo.cc>
@Grundik
Copy link
Contributor Author

Grundik commented Dec 17, 2022

Sorry! Extra code have slipped through. Removed duplicate of existing test.

@samsonasik
Copy link
Member

I think this should go to 2.17.0 since it behaviour change, I will let's @Ocramius decide on that

@Ocramius
Copy link
Member

@samsonasik as a bugfix, targeting for a patch release: bugfixes are behaviour changes anyway 😁

@Ocramius Ocramius self-assigned this Dec 17, 2022
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Grundik!

@Ocramius Ocramius merged commit dadd9a1 into laminas:2.16.x Dec 17, 2022
@Ocramius Ocramius changed the title Fix data loss on multiple Result->rewind() Fix data loss on multiple Result#rewind() calls Dec 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants