Skip to content
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

Add Expr::concat support for multiple arguments #1397

Merged

Conversation

giosh94mhz
Copy link
Contributor

DQL CONCAT function support variable number of arguments (2+) since version 2.4.0.

The Expr class, on the other hand, is still limited to 2 arguments, and require multiple call to achive a similar result (see this SO question). I've improved Expr implementation to support variable number of arguments in a backward compatible way.

Please, consider backporting to 2.4 branch if you plan to release other versions, since 2.5 introduce many features and may not be possible to easily upgrade. I may be wrong, though.

@doctrinebot
Copy link

Hello,

thank you for creating this pull request. I have automatically opened an issue
on our Jira Bug Tracker for you. See the issue link:

http://www.doctrine-project.org/jira/browse/DDC-3717

We use Jira to track the state of pull requests and the versions they got
included in.

@giosh94mhz giosh94mhz force-pushed the concat_expr_variable_arguments branch from 07681f4 to 1a0bdae Compare April 30, 2015 08:40
@giosh94mhz giosh94mhz force-pushed the concat_expr_variable_arguments branch from 1a0bdae to 61e33e5 Compare May 15, 2015 07:43
@Ocramius Ocramius self-assigned this Aug 8, 2015
@@ -526,13 +526,13 @@ public function notLike($x, $y)
* Creates a CONCAT() function expression with the given arguments.
*
* @param mixed $x First argument to be used in CONCAT() function.
* @param mixed $y Second argument to be used in CONCAT() function.
* @param mixed $y,... Other arguments to be used in CONCAT() function.
*
* @return Expr\Func
*/
public function concat($x, $y)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should have only one argument $x like the other functions accepting multiple arguments (andX, orX and countDistinct).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I kept the minimum of 2 not to introduce BC. Not supporting 2+ arguments is a bug, since CONCAT DQL expression is now valid syntax, but supporting a single parameters is halfway a bugfix and a feature.

I'll do some test and commit the new change so that the maintainer can review.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MisatoTremor: @giosh94mhz is correct - removing the param would be a bc break.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeroedin-bill well I don't know if this is strictly a BC.

I mean, to stay on the safe side the $y parameter should be kept, but at runtime is a BC only to add a parameters (w/o defaults), since PHP will ignore extra parameters by default.

You'll have a BC by overriding the method in sub classes, but since this class is part of a Builder pattern is meant to be final anyway.

Am I correct?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@giosh94mhz If the class were actually marked final, it would not matter. Given that it is not actually marked final, someone out there may have extended it. As part of the public API, the intent for this class doesn't really matter. The class is not final, so removing a parameter of this function is indeed a BC break (will raise warnings if it has been extended)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zeroedin-bill I agree with you. I was just suggesting that the scenario is rare and not recommended due to the Builder pattern, so the maintainer may decide to merge it anyway. Also, this can be merged in master, only partially back-ported to 2.4 and/or 2.5.

@giosh94mhz
Copy link
Contributor Author

I've pushed a new commit which allow CONCAT with only one argument; this is supported in DBAL, so there should be no problem. Travis will have the final answer.

Note that since this change the public method concat($x, $y) to concat($x) this MAY be considered a BC; there should be no problem at runtime, but some sub-class (in a Builder pattern?) may be affected. I'm ready to rollback and open a new PR if needed.


$this->secondStringPrimary = $parser->StringPrimary();
$this->concatExpressions[] = $this->secondStringPrimary;
$this->concatExpressions[] = $parser->StringPrimary();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All of the changes in this file are unnecessary - DQL CONCAT already supported >2 arguments - The semantics required at least 2 arguments. This change makes it so you can do weird things like CONCAT(field) - That isn't really valid. CONCAT should require a minimum of 2 arguments.

@giosh94mhz
Copy link
Contributor Author

@zeroedin-bill Thanks for the code review, and... well I got the point. I just noted right now that you are tagged as Collaborator; I though you were just reviewing not actually preparing for merge, since @Ocramius is usually reviewing PR.

Anyway, I never found a DBMS which yell at me if I do SELECT CONCAT("a"), neither a scripting language which prevent me of doing cat file or equivalent. Don't want to start the flame, just saying that the strict requirement of 2+ arguments is only supported by the BC issue.

So, if I revert commit 6a665b8 and follow your other suggestion, this will be merged?

@MisatoTremor
Copy link

Sorry for having caused such a fuzz here.
I wasn't fully aware of \Expr being public, so your original changes are good in my book.

@billschaller
Copy link
Member

@giosh94mhz I can guess that @Ocramius will not merge a BC break for this, as this is simply an enhancement, and probably not worth a BC break.

Also, I don't know about Oracle, but SELECT CONCAT('a') will return The concat function requires 2 to 254 arguments. on SQL Server.

@giosh94mhz
Copy link
Contributor Author

SQL Server always surprise me :) I looked into the Platform and I saw that the actual concat expression is the + operator, probably to deal with concatenation of a single element.

In the end, the one-parameter scenario is too complicated: BC and Platforms issues are too much for sure. I'll rollback, the last commmit and integrate you suggestion. I'll do my best with whitespaces, but there are some CS issue (carriage-return chars, some tabs, ...).

@Ocramius Ocramius assigned billschaller and unassigned Ocramius Nov 7, 2015
@Ocramius
Copy link
Member

Ocramius commented Nov 7, 2015

Overall, looks good. @zeroedin-bill: assigning to you for final review/merge (into master - 2.6.0).

I think the test needs to be split into a separate method.

@Ocramius Ocramius removed the Delayed label Nov 7, 2015
guilhermeblanco added a commit that referenced this pull request Nov 7, 2015
Add Expr::concat support for multiple arguments
@guilhermeblanco guilhermeblanco merged commit d7a3154 into doctrine:master Nov 7, 2015
@guilhermeblanco
Copy link
Member

Thanks! =)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants