-
Notifications
You must be signed in to change notification settings - Fork 7.8k
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
Conversation
a4d01eb
to
9078169
Compare
c02adac
to
3b5043d
Compare
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
3b5043d
to
d38ba8b
Compare
return false; | ||
} | ||
|
||
if (flags == PDO_FETCH_GROUP && stmt->fetch.column == -1) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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 */ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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