mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
GetSingleScalarResult/GetScalarResult should always return an int when the field is typed as integer #6470
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @VincentLanglet on GitHub (May 22, 2020).
Feature Request
Summary
The start of the discussion can be found here: https://github.com/doctrine/orm/pull/8149
Let's take an integer field
And a query
With a postgres database,
Is returning an
int, 1.But with mariadb it returns a
string,1.I think it should be better to always return an
int.Moreover,
is returning an array of
intwith MariaDB.So I see no reason to returns a
stringwithgetSingleScalarResultand an (array of)intwithgetResult.@VincentLanglet commented on GitHub (May 22, 2020):
This is not restricted to
getSingleScalarResult.getScalarResulthas the same issue and returns an array ofstringwith MariaDB for the given query.This also occurs for query like
->select('COUNT(contractOperation.id)'), returningintwith pdosql andstringwith MariaDB. But It's maybe harder to improve the behaviour since it's not related to a field...@VincentLanglet commented on GitHub (May 22, 2020):
The issue seems should be fixable in https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php#L318
$cacheKeyInfo are
So
Fix the issue
There is already something similar
But in my case there is a
isScalarvalue and nodqlAliasone.Maybe the
fieldNamemodification should stay in theisScalarcheck but the type update shouldn't ?For the other issue (when using 'COUNT(contractOperation.id)') the type is currently
Doctrine\StringType.This is because of this function: https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/Query/SqlWalker.php#L1317
According to the comment, the type cannot be resolved so
stringis set by default.https://github.com/doctrine/orm/blob/master/lib/Doctrine/ORM/Query/SqlWalker.php#L1378
But maybe the type should be resolved sometimes...
@greg0ire commented on GitHub (May 23, 2020):
Any thoughts about this comment:
72bc09926d/lib/Doctrine/ORM/Internal/Hydration/AbstractHydrator.php (L330-L331)? It was first introduced ina4dac7a292and then reworked in48172f3a53.@VincentLanglet commented on GitHub (May 23, 2020):
Thanks for the help @greg0ire
Is pretty clear and go on my side. We do wont to convert the value with the type. But it was a BC-break so should be made in 3.0.
The rework
Wasn't the best rework, it should have been
Because the manipulation are not made for the same reason.
We could make a PR on master then.
@beberlei commented on GitHub (May 27, 2020):
@greg0ire the problem is not integer columns, but lets say you have a "datetime" column though getSingleScalarResult. changing to use type conversion would suddenly created a DateTime instead of a string, potentially breaking lots of code.
Its indeed something that can be changed on 3.0 already, but it should be done in a BC / upgradable way.
Idea: Introduce a new query hint that is checked in hydrator at the point, and call it when using a new method
getSingleTypedScalarResult. Is that technically feasible?@greg0ire commented on GitHub (May 27, 2020):
I have no idea 😅 it does sound feasible but I'm don't know much about the ORM, what's for sure is that I know less than you do 😛
Also, I don't understand what "it" refers to in "call it when using a new method", you can't call a query hint, can you? And finally, a new method sounds a bit overkill, I think it's acceptable to change the behavior of existing methods iff the query hint is provided.
EDIT: or do you mean the new method would add the hint right before executing the query?
@SenseException commented on GitHub (May 28, 2020):
And does this new method replace the old one? Is there a plan for deprecation?