-
-
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
DBAL36 - BIGINT documentation misunderstanding #6126
Comments
In your example, the ID is cast to an integer because your class uses Line 48 in 17d7baf
But given that 32bit systems are rather rare, we could change this behavior in 4.0. Up for a PR? |
Note that MySQL's |
Yes, but what about the UNSIGNED integers? |
edit: I was wrong. We can compare the value returned from the database with |
So we'll be basically returning two types depending on the database, right? integer when it's bigint signed and float when it's bigint unsigned. Doesn't that make the behavior unpredictable? How about we create another dedicated type for unsigned big integers? |
No, we never cast integers to float. |
Not you but PHP does. php > var_dump((int) PHP_INT_MAX + 1);
float(9.223372036854776E+18) |
In my opinion it got a little confused. The same class is returning two distinct types but it's saying that it returns Integer in the Is this is a case for a new class? |
This is not a type-cast. It's a sum operation with a float result. I don't see how this relates to my statement or the issue we're discussing here. |
Alright, no problem. |
@cizordj the binding type is not about the type of the PHP representation. It is about the way the value should be interpreted in query parameters (so that the database knows how to cast it when executing a prepared statement) |
| Q | A |------------- | ----------- | Type | improvement | Fixed issues | Replaces doctrine#6143, closes doctrine#6126 #### Summary `BigIntType` casts values retrieved from the database to int if they're inside the integer range of PHP. Previously, those values were always cast to string. This PR continues the work done by @cizordj in doctrine#6143. Co-authored-by: cizordj <[email protected]>
This comment was marked as duplicate.
This comment was marked as duplicate.
I think, we can close this issue. @ondrejmirtes, I've answered your comment on #6177 already. Let's keep the discussion in one place. |
@ondrejmirtes if you know for sure your integer is signed then you don't need to declare as |
@cizordj Can you tell me the conditions for which |
I'll answer you there #6177 |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Bug Report
Summary
Please rephrase the explanation in the docs about the BIGINT datatype.
Current behaviour
The current statements lead to misinterpretation:
<!-- dbal/docs/en/reference/types.rst:95 --> For compatibility reasons this type is not converted to an integer
Which is not true.
We have many entities mapped with BIGINT and BIGSERIAL in a PostgreSQL database
and doctrine always casts their value to a regular PHP integer. We use the 64 bit architecture
and the primary keys are mapped this way.
According to the PostgreSQL's documentation the maximum number for a BIGINT field is 9223372036854775807 which is the same as the PHP_INT_MAX.
How to reproduce
dd()
or let it serialize it through a JsonResponse.You'll notice that the value comes as a PHP integer.
You can also add another row to the table with the maximum possible value, see the value of PHP_INT_MAX and make an insertion to the database.
Fetch all the entities and you can see that the value still comes as a regular integer type.
Due to the limitations of JSON, things start to get really weird for numbers like this, so you can only trust the
dd()
output in this case.Expected behaviour
The docs should say that the values retrieved from the database are always converted to PHP's
int
type ornull
if no data is present and display a notice about it being cast to string only in legacy 32-bit platforms.Btw why have you guys changed your minds? #2976
The text was updated successfully, but these errors were encountered: