Skip to content

Use the % operator instead of MOD() in SQLite #5755

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 1 commit into from
Oct 12, 2022

Conversation

derrabus
Copy link
Member

Q A
Type improvement
Fixed issues Part of #5745

Summary

Depending on the SQLite version and compile flags, SQLite might not have a MOD() function. Currently, we polyfill it.

However, SQLite does have a % operator that should always be available. This PR alters getModExpression() so that we use the operator instead of calling MOD(). We're doing the same thing for SQL Server already.

The operation is covered by the functional test ModExpressionTest which still passes.

@derrabus derrabus added this to the 3.5.0 milestone Oct 12, 2022
@derrabus derrabus requested a review from morozov October 12, 2022 10:54
@morozov
Copy link
Member

morozov commented Oct 12, 2022

Should this patch also add a runtime deprecation to the implementation of the MOD() UDF? Or it's undesired because even once we remove it, the native implementation may still be available?

@derrabus
Copy link
Member Author

Or it's undesired because even once we remove it, the native implementation may still be available?

That's what I was asking in #5745 (comment). Calling MOD() is not wrong because SQLite does provide a native implementation, so triggering a deprecation might be confusing as long as we don't provide a way to opt out of our polyfill.

@derrabus derrabus merged commit 26558d4 into doctrine:3.5.x Oct 12, 2022
@derrabus derrabus deleted the improvement/sqlite-mod-compat branch October 12, 2022 14:53
@VincentLanglet
Copy link
Contributor

Hi, I just wanted to report that previously, code like

SELECT MOD(10, NULLIF(m.intColumn, m.intColumn))
FROM QueryResult\Entities\Many m

could throw a Modulo by zero and after this PR there is no exception anymore.

Not sure if it should be considered as a "bugfix" or a "bc break".

I just discovered this while trying to solve phpstan/phpstan-doctrine tests.

@derrabus
Copy link
Member Author

That exception should never have leaked to userland in the first place, I believe. The behavior that we now have should be more consistent with other drivers.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants