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

ext/pdo: Refactor PDOStatement::fetchAll() #17347

Merged
merged 3 commits into from
Jan 7, 2025

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Jan 3, 2025

This also refactors the internal do_fetch() function to stop doing wonky stuff to handle grouping, which is a feature of fetchAll

Handle PDO_FETCH_KEY_PAIR on its own as GROUP and UNIQUE flags can interfere with it

This also refactors the internal do_fetch() function to stop doing wonky stuff to handle grouping, which is a feature of fetchAll

Handle PDO_FETCH_KEY_PAIR on its own as GROUP and UNIQUE flags can interfere with it
@Girgias Girgias force-pushed the pdo-fetchall-refactoring branch from 3b5043d to d38ba8b Compare January 4, 2025 15:32
return false;
}

if (flags == PDO_FETCH_GROUP && stmt->fetch.column == -1) {
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this the same as what you have on line 769?

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 tried to group this but I was getting failures I didn't really get. I would like to keep this for a follow-up.

//if (flags == PDO_FETCH_GROUP || flags == PDO_FETCH_UNIQUE) {
if (flags & PDO_FETCH_GROUP || flags & PDO_FETCH_UNIQUE) {
while (do_fetch(stmt, &data, how | flags, PDO_FETCH_ORI_NEXT, /* offset */ 0, &group_key)) {
ZEND_ASSERT(Z_TYPE(group_key) == IS_STRING);
Copy link
Member

Choose a reason for hiding this comment

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

Instead of assertion wouldn't it make more sense to have the convert_to_string here?

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 think something I would prefer to do is to pass a reference to a zend_string * to do_fetch() in a follow-up so that it is guaranteed to be a zend_string anyway.

Copy link
Member

@kamil-tekiela kamil-tekiela left a comment

Choose a reason for hiding this comment

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

It was quite confusing and I think it's much better now.

return true;
}

/* When fetching a column we only do one value fetch, so handle it separately */
Copy link
Member

Choose a reason for hiding this comment

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

This could still be in the switch, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because of the weird special case with PDO_FETCH_GROUP (which probably should also take into account FETCH_UNIQUE now that I think about it) I'd rather leave this outside the switch statement.

A follow-up I think to do is instead of the code setting stmt->fetch.column == -1 prior to calling do_fetch() it should set stmt->fetch.column == 0 and let the new grouping code handle it. Probably requires having a "common" colno variable however.

ext/pdo/pdo_stmt.c Outdated Show resolved Hide resolved
@Girgias Girgias merged commit 17ea79b into php:master Jan 7, 2025
1 check passed
@Girgias Girgias deleted the pdo-fetchall-refactoring branch January 7, 2025 09:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants