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: Don’t drop first row on repeated iteration #99

Merged
merged 1 commit into from
Jul 3, 2019
Merged

FIX: Don’t drop first row on repeated iteration #99

merged 1 commit into from
Jul 3, 2019

Conversation

sminnee
Copy link
Member

@sminnee sminnee commented Jun 28, 2019

@ScopeyNZ
Copy link
Contributor

At the risk of making your brain hate me more, we can avoid the second seek with PostgreSQL. We can specify specific rows to seek to when fetching a record (as one of the parameters to pg_fetch_array). This means we can make seek call pg_fetch_array($this->handle, 0, PGSQL_NUM) and then move the processing of the result (done in nextRecord) into a separate method.

I can implement this if you want?

@sminnee
Copy link
Member Author

sminnee commented Jun 28, 2019 via email

@ScopeyNZ
Copy link
Contributor

Done :)

pg_result_seek($this->handle, $row);
return $this->nextRecord();
// Specifying the zero-th record here will reset the pointer
$row = pg_fetch_array($this->handle, 0, PGSQL_NUM);
Copy link
Member Author

Choose a reason for hiding this comment

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

You've overwritten $row?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't understand why the 0 isn't $row.

Also I don't understand why this doesn't increment to the next (wrong) record next time nextRecord() is called.

The nextRecord() call after seek() must return the same record in order to fix the bug in question.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that was just a mistake 😖 . As I understand it (and from how it was working when testing it) if you call pg_fetch_array with a row number, you set the pointer to that location and get the record at that location. pg_fetch_array with a null row will return the row at the current pointer location and then increment the pointer.

@sminnee
Copy link
Member Author

sminnee commented Jul 3, 2019

OK @ScopeyNZ I've tested locally and it works, so 👍 from me. The only thing I did was remove the return-type hint as this patch release still supports PHP 5.6

@ScopeyNZ
Copy link
Contributor

ScopeyNZ commented Jul 3, 2019

Ah yep - my mistake. Only takes a few weeks of writing PHP7 code for me to change my habits apparently 😅 .

I'm happy to merge considering our collab/peer review process here if you're comfortable with that (and the tests pass).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants