-
-
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
Fix DateInterval
database value truncation (string overflow)
#2316
Conversation
@@ -22,7 +22,7 @@ public function getName() | |||
*/ | |||
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) | |||
{ | |||
$fieldDeclaration['length'] = 20; | |||
$fieldDeclaration['length'] = 255; |
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.
Despite my remark that 20 can be to short for large intervals, 255 might be a bit over the top. :)
Question is what a sensible limit would be ...
To have an interval spanning the seconds past since the "beginning" of the visible universe would be P00Y00M00DT00H00M435400000000000000S = 66 characters. I can't imagine right now any higher possible overflowing, but with adding some "buffer" length I think any value between 70 or 80 should be safe.
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, but theoretically you can add as many numbers in any interval part as you want, so i.e. MySQL 64, 128 or other length lower than 255 (varchar) reservers same amount of memory, so is it really needed to calculate potential minimum?
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.
Afaik that only applies to the memory storage type.
This being DBAL the length should not consider only one specific platform. And if I'm not mistaken a developer could adjust the length if needed when defining the schema.
So this is mainly about finding a sensible default length.
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.
Tweaking is not really up to us - we just need to accommodate a generic use-case scenario, and that's it.
Linking #2314 |
@Ocramius Do you plan to include this new type is next release? 2.4.6? or is it too soon? |
New features can only go to minor versions, not to patch releases
|
@zeroedin-bill, @Ocramius - could you please review the code? |
You are right @Ocramius, then plans for 2.6 😉 ? |
@vbartusevicius code looks ok to me. Assigned to @deeky666 for review. @juliangut @deeky666 is the gateway keeper for DBAL: he's in command |
return 'P' | ||
. str_pad($value->y, 4, '0', STR_PAD_LEFT) . '-' | ||
. $value->format('%M-%DT%H:%I:%S'); | ||
/** @var \DateInterval $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 comment is not needed, please remove.
@deeky666 - any luck on this? |
@vbartusevicius @deeky666 Let's not store an invalid Invalid according to
We should convert any invalid Or throw an exception in Note that invalid |
@galeaspablo - what do you mean by increasing the number of years? this PR already solves the problem you're addressing here:
In addition, why
|
@vbartusevicius Like I said, Invalid according to \DateInterval::__construct
Plus, the PR does not keep sortability, which was considered for this feature. And should remain so. Your PR would mean the database would sort 10, 111, and 12 seconds as If you'd like to keep your approach, we'd need to By increase the number of year digits, I mean that we store 10 digits of a year instead of 4 (as before), or 2 (as you propose). Edit 1: Rethinking this, your approach with str_pad sounds like the way to go. Unless I'm missing something. Edit 2: Actually, nevermind Edit 1. We need to keep ISO8601, and store valid (according to the specification intervals), to keep sortability. Otherwise 1 minute 10 seconds < 0 minutes 80 seconds |
@galeaspablo - your case with invalid spec only applies to datetime representation (please read again):
If you use a regular
just try this. As of 2 digits for year - where do you see that? |
You are right. My mistake.
True.
You cannot address this by using
So we're back to, throw an exception if we have an "invalid" (according to the datetime specification) interval. |
@galeaspablo - thanks for information, but I like to hear the opinion of @deeky666 or @Ocramius on this. |
Agreed. :) |
This could lead to invalid behavior, as it actually changes the meaning of that interval. |
@MisatoTremor Happy to hear more. So far, I see these options
|
As I see it, DateIntervals can't be reliably sorted anyway so I'd choose 1). |
I really can't get my head around that weird interval stuff, sorry. Will leave that one up for @Ocramius to decide :P Please just make sure to keep BC. Maybe only possible by introducing a new type (ugh). |
This is ready to merge. Sorry for the delay, @vbartusevicius! Also, for readers, this is not a BC break, as this class was not in any tagged release. |
Thanks @Ocramius for merging and ofc thanks @vbartusevicius for your work on this! |
DateInterval
database value truncation (string overflow)
The conversion format is set to '%RP%YY%MM%DDT%HH%IM%SS'. This is incorrect for Postgres. The prepended %R is not accepted. There is also an issue with the |
DateIntervalType
now stores data inP%YY%MM%DDT%HH%IM%SS
format as%M-%DT%H:%I:%S
brings a lot of problems with large intervals, i.e.:P100DT500M