-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Return numeric-string instead of just string to represent row count #5317
Conversation
Looks good in general. I believe, the same idea applies to the
|
@morozov I believe changing - public function exec(string $sql): int;
+ public function exec(string $sql): int|string; results in hard BC break since I'll have to remove the type hint (union types not supported here yet) - public function exec(string $sql): int;
+ public function exec(string $sql) Should I proceed? |
No, but it should be possible to add a |
Ok so I keep :int but add @return int|string?
…On Fri, Mar 11, 2022, 00:43 Sergei Morozov ***@***.***> wrote:
No, but it should be possible to add a @return or @psalm-return
annotation that would override the native return type.
—
Reply to this email directly, view it on GitHub
<#5317 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACQAJN46WWYAHTSZ47TU23U7KCJVANCNFSM5QL2EVVQ>
.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Yes, keep Off-topic: note that it's not just |
b1f927f
to
e0850bf
Compare
bae311f
to
5a0d8e2
Compare
@morozov what about |
Would it help to remove the conflicting |
IMO this would not be good. If the PHP return type is The only correct way here that I see is to remove the int return type from exec&executeUpdate IMO, and then use Removing the type hint should not be a huge deal, classes extending it can still specify it without breaking LSP (at least in the 3.3 branch as this was allowed in PHP 7.2) so it's not a BC break I would say. |
Note that the DBAL 3.x codebase doesn't use Another thought is that it was never reported that a number of affected rows larger than It is much more likely that changing the signature will affect the API consumers who don't experience this issue than it will fix the issue for those who experience it. I am fine with introducing this minor BC break in a minor release but we have to be conscious about the real side effects it can lead to. |
If you look at my example (https://3v4l.org/YaedP) again, it also does not use strict types, and while it also surprised me, it seems like PHP fails the string->int cast if the numeric string is beyond PHP_MAX_INT. So technically you already have the issue with the current code. But as you say, in practice even on 32bit doing an operation on 2billion rows is pretty damn rare, and 32bit systems themselves are getting rarer, so IMO it's fine to use a plain If adding return types would be considered a BC break, we can still do I think this would be way less surprising for everyone, and lets you use a much leaner The bigint -> string type thing is a bit of a pain already, but I can understand the rationale there (tho I wish we could forget about 32bit), and having tables with ids going above 2billion is definitely not that far fetched. But again for affected rows a 32bit integer really sounds like it is good enough. |
Agreed, plus the only 32bit system I had to recently work with is a raspberry pi 😁 |
Actually, all the classes implementing
Agree.
Agree. It won't be a BC break. |
I am a bit confused, if that is the case already then why not keep the int return types on Connection and simply drop the string types? If So having an As per Lines 1157 to 1160 in 83f779b
I opened #5334 to show more clearly what I suggested doing above in #5317 (comment) IMO this is the best outcome as it completely removes the string type, keeping things simpler for the API consumers, and it is anyway reflecting the current reality of the code better. |
Constraint int to int<0, max>
Because the underlying driver can return a string. |
Yes there is one driver (MySQLi) which can return a string as far as I have seen after looking at all drivers docs this morning. And it will do so only in the case that you have a query affecting over 2billion rows (super rare) AND only on 32bit platforms (super rare). I don't find it justified to add a string return type just for that one edge case, adding burden to every API consumer, but that's obviously just my perspective. Also note that in the current state, this PR does not fix it as https://github.com/doctrine/dbal/blob/3.3.x/src/Driver/Mysqli/Result.php#L164-L171 and other Result classes still have the I would appeal to pragmatism here as forcing everyone to deal with int|string when reality is 99.9999999% of users will ever see an int, seems absurd. P.S: Also another minor aspect I noticed this morning is that strictly speaking some drivers (SQLSrv and Mysqli as per https://github.com/doctrine/dbal/pull/5334/files) do return -1 in some error conditions, which does not fit the |
I realize that this is such an insignificant and at the same time such a complex problem that I'm not willing to spend time on solving it. It is insignificant because the edge case is indeed rare. It is complex because different underlying drivers are handling it differently. I.e. SQL Server seems to be unable to return more than I don't believe we have the integration tests that validate the semantics of these values in all cases (e.g. select, insert, update where all matching rows indeed were updated or some of them already had the value set by the update). With that said, whoever has the commit permissions for this repo has my full blessing in doing whatever they deem reasonable.
This appeal should be targeted at the maintainers of the underlying drivers first of all. BTW @kamil-tekiela contributed some changes that allowed to simplify the DBAL code for |
OK, then if you rather not solve anything, I would suggest leaving the php types as they are now, broken or not that they may be in edge cases, and switch to a simple Removing the If you agree I am happy to prepare a new PR (or @simPod updates this one here?). It'd be risk free in terms of code, but improves the type situation for API consumers which I believe was @simPod's intent as well. |
There hasn't been any activity on this pull request in the past 90 days, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 7 days. |
This pull request was closed due to inactivity. |
Yeah this should be reopened IMO. @morozov if you can let us know what you think about #5317 (comment) I'll happily send a PR. |
I'll be fine with whatever changes that somebody else from the maintainers approves. After skimming over the thread, I don't want to work on this change. |
Closing due to the lack of progress. |
What is your feedback on #5334 then? |
I don't have any feedback on in, it's closed. |
Summary
The returned string representing row count is always a number so it makes sense to constrain it a little bit more.