Skip to content

PdoPgsql::setNoticeCallback() #14299

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

Merged
merged 7 commits into from
Jun 9, 2024
Merged

Conversation

outtersg
Copy link
Contributor

@outtersg outtersg commented May 22, 2024

Make the newly implemented setNoticeCallback() officially exposed in @kocsismate / @Danack Pdo\Pgsql (discussion begun at #6764)

@outtersg
Copy link
Contributor Author

@nielsdos you may be interested in reviewing this complement (hoping I did not break the beautiful work we did on #6764…).

@outtersg outtersg mentioned this pull request May 22, 2024
Copy link
Member

@nielsdos nielsdos left a comment

Choose a reason for hiding this comment

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

Sorry, I didn't think of those new classes.
I have a suggestion on how to simplify this.
Also: the CI currently fails because the stub isn't regenerated into the arginfo file. That usually happens automatically when you do make. You can force it manually by doing: ./build/gen_stub.php.

@outtersg outtersg force-pushed the issue-78621-pdopgsql branch 2 times, most recently from 7fe2959 to 35c0216 Compare May 22, 2024 16:36
@outtersg
Copy link
Contributor Author

@nielsdos wrote:

Also: the CI currently fails because the stub isn't regenerated into the arginfo file.
That usually happens automatically when you do make. You can force it manually by doing: ./build/gen_stub.php.

Yes, it's not the first time I got caught by the CI :(
But git diff seeing the arginfo as binary made me visually miss it when adding to the commit.

@devnexen
Copy link
Member

@outtersg here when you can.

Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

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

Thanks for the quick followup! Please update the UPGRADING note + maybe a dedicated test for PdoPgsql:: setNoticeCallback() would be useful to have. And then I guess it is good to go.

@outtersg outtersg force-pushed the issue-78621-pdopgsql branch from 35c0216 to 6dee3db Compare May 23, 2024 07:33
@outtersg
Copy link
Contributor Author

outtersg commented May 23, 2024

@kocsismate wrote:

Thanks for the quick followup! Please update the UPGRADING note

Something like "Added PdoPgsql::setNoticeCallback() / PDO::pgsqlSetNoticeCallback to allow […]"?

maybe a dedicated test for PdoPgsql:: setNoticeCallback() would be useful to have. And then I guess it is good to go.

Here it is, with 6dee3db.

@kocsismate
Copy link
Member

Something like "Added PdoPgsql::setNoticeCallback() / PDO::pgsqlSetNoticeCallback to allow […]"?

Exactly :)

@outtersg outtersg force-pushed the issue-78621-pdopgsql branch 2 times, most recently from 3e76414 to 79f5ddb Compare May 25, 2024 06:29
@outtersg
Copy link
Contributor Author

We're good to go after retriggering Travis CI (which has a timeout of 50 mn on a 45 mn+ job…)!

Still, there's the egg-and-chicken question of how to make PdoPgsql::Xxx the official entry point, while letting PDO::pgsqlXxx available until connect becomes mainstream (and I think third parties already switched to not subclassing PDO anymore, but proxying it).
@Girgias, @kocsismate, @Danack, do you think of a way to solve this elegantly?

@Danack
Copy link
Contributor

Danack commented May 25, 2024

do you think of a way to solve this elegantly?

I would only add support for PdoPgsql::Xxx and then only think about adding a PDO::pgsqlXxx version if someone offered to pay me something like £10k

Hardcoding the class seems to defeat the universal purpose of PDO (switching from SQLite to pg with a single DSN change)

wrap_the_db_class

You're testing a DB specific method. It's fine to hard code the class name.

(it is possible you might get a more useful answer from someone not quite as in a mood as myself)

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Missing tests, and I still believe we should not be adding new "magic" driver methods to the core PDO class.

@outtersg
Copy link
Contributor Author

outtersg commented May 27, 2024

@Danack wrote:

(it is possible you might get a more useful answer from someone not quite as in a mood as myself)
[…]
You're testing a DB specific method. It's fine to hard code the class name.

See my reply in the conversation.

outtersg added a commit to outtersg/php-src that referenced this pull request May 27, 2024
@outtersg outtersg force-pushed the issue-78621-pdopgsql branch from 79f5ddb to 5b4b012 Compare May 27, 2024 20:18
Copy link
Member

@kocsismate kocsismate left a comment

Choose a reason for hiding this comment

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

Thank you for your work, I believe this is now much better than the original solution was with the 2 methods. :) I mean, I agree with Dan and George, let's not add anything to the old and clunky API. Unfortunately, I didn't realize the importance of this when I first reviewed the PR.

@kocsismate
Copy link
Member

I noticed it still had references to PdoXxx instead of Pdo\Xxx.

Sorry, my fault. I also forgot to update them yesterday :(

@nielsdos
Copy link
Member

nielsdos commented Jun 6, 2024

Unless I'm mistaken, you're still missing a test where you test that a trampoline does not leak on an uninitialized pdo instance?

@outtersg
Copy link
Contributor Author

outtersg commented Jun 6, 2024

@nielsdos wrote:

Unless I'm mistaken, you're still missing a test where you test that a trampoline does not leak on an uninitialized pdo instance?

OK, I'm not familiar at all with how to test that.
By reading sqlite3_trampoline_*_no_leak.phpt, if I understand correctly:

  • I should test multiple invalid combinations, one by one, on the same object
  • Each callback should gracefully return a "must be a valid callback", but should not output leaks
  • Then I could too test on a newInstanceWithoutConstructor(), same thing
  • And then a final, correct, call, with a trampoline instead of a direct function.

Is that right?

But I see no "Trampoline for" in the output: are we just testing the set of the callback, not its execution at runtime?

@nielsdos
Copy link
Member

nielsdos commented Jun 6, 2024

What you've done so far is right, but you should also test the set method on an uninitialized PDO instance.
You can create a PDO instance and test with it like so: https://github.com/php/php-src/blob/a580d4a1c319203053ab66cdf1205f126d96e667/ext/pdo/tests/pdo_uninitialized.phpt
In the case of PdoPgsql, you can create a new instance using new PdoPgsql and this will be uninitialized. Then you can test whether the set method on such an uninitialized instance correctly errors out and does not leak when given a trampoline.

outtersg added 5 commits June 7, 2024 03:18
Make the newly implemented setNoticeCallback() officially exposed (php#6764)
based on PDO::pgsqlSetNoticeCallback()'s one
php@c265b90#r142275842
Redefines PDO_CONSTRUCT_CHECK to make room for an optional cleanup
Keep only Pdo\Pgsql::setNoticeCallback()
@outtersg
Copy link
Contributor Author

outtersg commented Jun 7, 2024

@nielsdos wrote:

[…] test with it like so: …/ext/pdo/tests/pdo_uninitialized.phpt

I almost had it 😞, in a commented, uncommited part of my local pdopgsql_setNoticeCallback.phpt,
and with a newInstanceWithoutConstructor() as seen in sqlite3_trampoline_*_no_leak.phpt.

In the case of PdoPgsql, you can create a new instance using new PdoPgsql and this will be uninitialized.

On a theorical point of view, is there a difference between newInstanceWithoutConstructor() and subclassing with a constructor short-circuit? (a direct new Pdo\Pgsql() throws, requiring at least 1 arg)
For example, do class members initialized at declaration (protected $thing = 'bla') get initialized with an empty constructor, but not with newInstanceWithoutConstructor(), or is it strictly equivalent?
(in the case of an internal class like Pdo\Pgsql I doubt there are class members of course)

@outtersg outtersg force-pushed the issue-78621-pdopgsql branch 2 times, most recently from 4bbed47 to fe2b24d Compare June 7, 2024 16:24
@outtersg outtersg force-pushed the issue-78621-pdopgsql branch from fe2b24d to 7d100a4 Compare June 7, 2024 16:26
@nielsdos
Copy link
Member

nielsdos commented Jun 7, 2024

Thanks for the test!

In the case of PdoPgsql, you can create a new instance using new PdoPgsql and this will be uninitialized.

On a theorical point of view, is there a difference between newInstanceWithoutConstructor() and subclassing with a constructor short-circuit? (a direct new Pdo\Pgsql() throws, requiring at least 1 arg) For example, do class members initialized at declaration (protected $thing = 'bla') get initialized with an empty constructor, but not with newInstanceWithoutConstructor(), or is it strictly equivalent? (in the case of an internal class like Pdo\Pgsql I doubt there are class members of course)

It is equivalent, the properties are initialized when the object is allocated before calling the constructor. In case no constructor is called the properties are initialized.

I think the patch looks good.

@Girgias I believe all cases are now covered.

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

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

Thank you! Looks good to me now :)

Comment on lines +37 to +39
/* Do NOT add new methods here. See https://wiki.php.net/rfc/pdo_driver_specific_subclasses
* Any new feature should be declared only on Pdo\Pgsql.
*/
Copy link
Member

Choose a reason for hiding this comment

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

This might make sense to add to other drivers in a follow-up PR.

@Girgias Girgias merged commit a9259c0 into php:master Jun 9, 2024
11 checks passed
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.

7 participants