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
QueryResultTypeWalker: resolve if int/float/bool is fetched as native type or stringified #506
base: 1.3.x
Are you sure you want to change the base?
QueryResultTypeWalker: resolve if int/float/bool is fetched as native type or stringified #506
Conversation
What about auto-detecting this from PhpVersion, and also from objectManagerLoader if one is provided? |
@@ -812,43 +844,39 @@ public function walkSelectExpression($selectExpression) | |||
$resultAlias = $selectExpression->fieldIdentificationVariable ?? $this->scalarResultCounter++; | |||
$type = $this->unmarshalType($expr->dispatch($this)); | |||
|
|||
if (class_exists(TypedExpression::class) && $expr instanceof TypedExpression) { |
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 was dead block of code as class_exists(TypedExpression::class)
is always false.
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.
@@ -1097,8 +1127,12 @@ public function walkLiteral($literal) | |||
break; | |||
|
|||
case AST\Literal::BOOLEAN: | |||
$value = strtolower($literal->value) === 'true' ? 1 : 0; | |||
$type = new ConstantIntegerType($value); |
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 was just wrong for postgres, that returns real booleans, but we were infering 1|0|'1'|'0'
private function shouldStringifyExpressions(Type $type): TrinaryLogic | ||
{ | ||
$driver = $this->em->getConnection()->getDriver(); | ||
$nativeConnection = $this->getNativeConnection(); |
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.
Sadly, this causes connection initialization.
Note: this is still WIP and I still plan to finalize this, but implementing all the built-in SQL functions is non-trivial when considering all edge-cases. To be able to implement it properly, I created test repository to verify all differences: https://github.com/janedbal/php-database-drivers-fetch-test/ |
@VincentLanglet Jan already drowned dozens of hours to get this right, it's a very complex topic as you can see in here https://github.com/janedbal/php-database-drivers-fetch-test/. Don't rush this :) |
Sorry if my message was heard like this, wasn't my intention. I thought one of the issue with this big PR was to write tests for all the build-in method, and that maybe I could find and offer time to this. Anyway, it will take the time it need to take ! :) |
The green CI here is misleading, there is still ton of work awaiting ( |
@VincentLanglet Pushed the WIP so that you can check the direction I'm leaning towards. |
* - bigint: int int int int | ||
* - bool: int int bool bool | ||
*/ | ||
public function getDatabaseInternalType(Driver $driver): Type; |
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 change will be a BC break since the interface has @api
annotation.
Not sure which strategy should be followed to avoid this...
Should another interface be introduced ?
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.
Yeah, another interface somehow.
Thanks, can I help you on this ? I notice there was conflict with the 1.3.x branch, do you have time to solve them or do you want me to try ? :) |
@VincentLanglet I've some stuff in backlog to do first before returning to this. But the outline what needs to be done:
And maybe more stuff I already forgot. I think you can easily help with (3) as such test can be added in standalone MR and possibly merged beforehand. The rest is just digging in code. |
I would take the little step by little step approach: untested drivers will returns the same type than before.
And if a untested-drivers user complains about the type, he/we just have test this drivers and update the code to support it.
What about starting with only the existing implemented aggregate functions ?
It could be easier to first, make a PR with those aggregate functions and then adding other aggregate one by one ?
The options I see are
and passing the driver. In next major the param will be required. This is often done by Symfony.
and implementing the interface ; then the check
could be made. I think the decision is more on @ondrejmirtes about how he wants to proceed in order to evolve such method signature. |
Currently, inferring numeric types (mainly results of
AVG
,SUM
etc) is imperfect as it is currently implemented to serve all configurations resulting in union types likeint|numeric-string
. This is painful to work with in real codebase with some specific configuration where you know it is alwaysint
.To match setup of modern PHP versions (8.1+) using most used driver (PDO), I added option not to stringify such expressions.Rewritten to autodetct driver & PHP version & PDO setup to properly infer types.