Skip to content

accept more than 2 parameters in CONCAT function #583

Closed
wants to merge 5 commits into from

5 participants

@broncha
broncha commented Feb 19, 2013

The DBAL Platform supports more then 2 parameters but the ConcatFunction only validates 2 parameters to CONCAT. This commit allows to pass more than 2 parameters to CONCAT. Also this change would require that getConcatExpression accept array as a parameter. I have opened a pull request for that as well.

Here is the pull request : doctrine/dbal#275

I also propose that the function getConcatExpression only accept array of string rather than multiple string arguments.

@doctrinebot

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DDC-2304

@Majkl578 Majkl578 commented on an outdated diff Feb 19, 2013
lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php
@@ -56,10 +59,13 @@ public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
-
- $this->firstStringPrimary = $parser->StringPrimary();
- $parser->match(Lexer::T_COMMA);
- $this->secondStringPrimary = $parser->StringPrimary();
+
+ $this->concatExpressions[] = $parser->StringPrimary();
+
+ while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
+ $parser->match(Lexer::T_COMMA);
+ $this->concatExpressions[] = $parser->StringPrimary();
@Majkl578
Majkl578 added a note Feb 19, 2013

Wrong indentation by tab.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff Feb 19, 2013
lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php
@@ -22,7 +22,7 @@
use Doctrine\ORM\Query\Lexer;
/**
- * "CONCAT" "(" StringPrimary "," StringPrimary ")"
+ * "CONCAT" "(" StringPrimary "," StringPrimary "," StringPrimary ",...)"
@stof
Doctrine member
stof added a note Feb 19, 2013

This is not the right syntax for this in EBNF It should be "CONCAT" "(" StringPrimary "," StringPrimary {"," StringPrimary }* ")"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff Feb 19, 2013
lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php
/**
* @override
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
$platform = $sqlWalker->getConnection()->getDatabasePlatform();
- return $platform->getConcatExpression(
- $sqlWalker->walkStringPrimary($this->firstStringPrimary),
- $sqlWalker->walkStringPrimary($this->secondStringPrimary)
- );
+
+ $args = array();
+
+ foreach($this->concatExpressions as $e){
@stof
Doctrine member
stof added a note Feb 19, 2013

missing space after foreach. And you should name the variable $expression rather than $e to have a meanignful name

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff Feb 19, 2013
lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php
@@ -34,19 +34,22 @@
*/
class ConcatFunction extends FunctionNode
{
- public $firstStringPrimary;
- public $secondStringPrimary;
-
+ public $concatExpressions = array();
+
@stof
Doctrine member
stof added a note Feb 19, 2013

Please remove all trailing whitespaces. Empty line should be really empty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff Feb 19, 2013
lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php
/**
* @override
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
$platform = $sqlWalker->getConnection()->getDatabasePlatform();
- return $platform->getConcatExpression(
- $sqlWalker->walkStringPrimary($this->firstStringPrimary),
- $sqlWalker->walkStringPrimary($this->secondStringPrimary)
- );
+
+ $args = array();
+
+ foreach($this->concatExpressions as $e){
+ $args[] = $sqlWalker->walkStringPrimary($this->firstStringPrimary);
@stof
Doctrine member
stof added a note Feb 19, 2013

This is broken. $this->firstStringPrimary does not exist anymore

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff Feb 19, 2013
lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php
@@ -34,19 +34,22 @@
*/
class ConcatFunction extends FunctionNode
{
- public $firstStringPrimary;
- public $secondStringPrimary;
-
+ public $concatExpressions = array();
@stof
Doctrine member
stof added a note Feb 19, 2013

Changing the public properties is a BC break for any code dealing with the AST

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff Feb 19, 2013
lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php
@@ -56,10 +59,13 @@ public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
-
- $this->firstStringPrimary = $parser->StringPrimary();
- $parser->match(Lexer::T_COMMA);
- $this->secondStringPrimary = $parser->StringPrimary();
+
+ $this->concatExpressions[] = $parser->StringPrimary();
+
+ while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
@stof
Doctrine member
stof added a note Feb 19, 2013

This will not require to have at least 2 arguments. It is wrong IMO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof
Doctrine member
stof commented Feb 19, 2013

The new feature should be tested.
And you should run the tests when doing changes (or at least look at the Travis result on the pull request) as they spotted the issue about the wrong property

@broncha
broncha commented Feb 20, 2013

doctrine2/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php is passing given the DBAL Platform has been patched. I doubt if the travis build will pass as the pull request I sent fot DBAL has not been merged

@stof
Doctrine member
stof commented Feb 20, 2013

If this depend on an unmerged PR in DBAL, please add the link in the description of the PR.

@stof stof commented on an outdated diff Feb 20, 2013
lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php
/**
* @override
*/
public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
$platform = $sqlWalker->getConnection()->getDatabasePlatform();
- return $platform->getConcatExpression(
- $sqlWalker->walkStringPrimary($this->firstStringPrimary),
- $sqlWalker->walkStringPrimary($this->secondStringPrimary)
- );
+
+ $args = array();
+
+ foreach ($this->concatExpressions as $expression) {
+ $args[] = $sqlWalker->walkStringPrimary($expression);
+ }
+
+ return $platform->getConcatExpression( $args );
@stof
Doctrine member
stof added a note Feb 20, 2013

you should remove the extra spaces around $args

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof stof commented on an outdated diff Feb 20, 2013
lib/Doctrine/ORM/Query/AST/Functions/ConcatFunction.php
@@ -56,10 +59,15 @@ public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
-
- $this->firstStringPrimary = $parser->StringPrimary();
- $parser->match(Lexer::T_COMMA);
- $this->secondStringPrimary = $parser->StringPrimary();
+
+ $this->concatExpressions[] = $parser->StringPrimary();
+ $parser->match(Lexer::T_COMMA);
+ $this->concatExpressions[] = $parser->StringPrimary();
+
+ while ($parser->getLexer()->isNextToken(Lexer::T_COMMA)) {
+ $parser->match(Lexer::T_COMMA);
+ $this->concatExpressions[] = $parser->StringPrimary();
@stof
Doctrine member
stof added a note Feb 20, 2013

wrong indentation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@stof
Doctrine member
stof commented Feb 20, 2013

you still need to add a unit test (in https://github.com/doctrine/doctrine2/blob/master/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php) for the case where you have more than 2 expressions

@broncha
broncha commented Feb 20, 2013

Unit test SelectSqlGenerationTest::testSupportsMoreThanTwoParametersInConcatFunction added and passing..
Indentation looks fine in eclipse, but seems distorted when I push. I dont know whats happening.

@broncha broncha calling getConcatExpression using call_user_func_array as number of a…
…rguments is not known removing dependency to patch DBAL
3a3d053
@broncha
broncha commented Feb 26, 2013

I have pushed a new commit, which does not require doctrine/dbal#275 to be merged.
Travis build should now pass

@beberlei
Doctrine member

Merged in 4841a06

@beberlei beberlei closed this Mar 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.