Merge pull request #246 from FabioBatSilva/DDC-1557
[DDC 1557] Support for DQL function on subselect
This commit is contained in:
commit
e43897916a
@ -1981,9 +1981,10 @@ class Parser
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SimpleSelectExpression ::=
|
* SimpleSelectExpression ::= (
|
||||||
* StateFieldPathExpression | IdentificationVariable |
|
* StateFieldPathExpression | IdentificationVariable | FunctionDeclaration |
|
||||||
* ((AggregateExpression | "(" Subselect ")" | ScalarExpression) [["AS"] AliasResultVariable])
|
* AggregateExpression | "(" Subselect ")" | ScalarExpression
|
||||||
|
* ) [["AS"] AliasResultVariable]
|
||||||
*
|
*
|
||||||
* @return \Doctrine\ORM\Query\AST\SimpleSelectExpression
|
* @return \Doctrine\ORM\Query\AST\SimpleSelectExpression
|
||||||
*/
|
*/
|
||||||
@ -2004,6 +2005,18 @@ class Parser
|
|||||||
|
|
||||||
return new AST\SimpleSelectExpression($expression);
|
return new AST\SimpleSelectExpression($expression);
|
||||||
|
|
||||||
|
case ($this->_isFunction()):
|
||||||
|
// SUM(u.id) + COUNT(u.id)
|
||||||
|
if ($this->_isMathOperator($this->_peekBeyondClosingParenthesis())) {
|
||||||
|
return new AST\SimpleSelectExpression($this->ScalarExpression());
|
||||||
|
}
|
||||||
|
// COUNT(u.id)
|
||||||
|
if ($this->_isAggregateFunction($this->_lexer->lookahead['type'])) {
|
||||||
|
return new AST\SimpleSelectExpression($this->AggregateExpression());
|
||||||
|
}
|
||||||
|
// IDENTITY(u)
|
||||||
|
return new AST\SimpleSelectExpression($this->FunctionDeclaration());
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// Do nothing
|
// Do nothing
|
||||||
}
|
}
|
||||||
|
@ -1434,6 +1434,37 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-1557
|
||||||
|
*/
|
||||||
|
public function testSupportsSubSqlFunction()
|
||||||
|
{
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE u1.name IN ( SELECT TRIM(u2.name) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )',
|
||||||
|
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.name IN (SELECT TRIM(c1_.name) AS sclr4 FROM cms_users c1_)'
|
||||||
|
);
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE u1.name IN ( SELECT TRIM(u2.name) FROM Doctrine\Tests\Models\CMS\CmsUser u2 WHERE LOWER(u2.name) LIKE \'%fabio%\')',
|
||||||
|
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.name IN (SELECT TRIM(c1_.name) AS sclr4 FROM cms_users c1_ WHERE LOWER(c1_.name) LIKE \'%fabio%\')'
|
||||||
|
);
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE u1.email IN ( SELECT TRIM(IDENTITY(u2.email)) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )',
|
||||||
|
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.email_id IN (SELECT TRIM(c1_.email_id) AS sclr4 FROM cms_users c1_)'
|
||||||
|
);
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE u1.email IN ( SELECT IDENTITY(u2.email) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )',
|
||||||
|
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE c0_.email_id IN (SELECT c1_.email_id AS sclr4 FROM cms_users c1_)'
|
||||||
|
);
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE COUNT(u1.id) = ( SELECT SUM(u2.id) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )',
|
||||||
|
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE COUNT(c0_.id) = (SELECT SUM(c1_.id) AS dctrn__1 FROM cms_users c1_)'
|
||||||
|
);
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT u1 FROM Doctrine\Tests\Models\CMS\CmsUser u1 WHERE COUNT(u1.id) <= ( SELECT SUM(u2.id) + COUNT(u2.email) FROM Doctrine\Tests\Models\CMS\CmsUser u2 )',
|
||||||
|
'SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ WHERE COUNT(c0_.id) <= (SELECT SUM(c1_.id) + COUNT(c1_.email_id) AS sclr4 FROM cms_users c1_)'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
public function testCustomTypeValueSql()
|
public function testCustomTypeValueSql()
|
||||||
{
|
{
|
||||||
if (DBALType::hasType('negative_to_positive')) {
|
if (DBALType::hasType('negative_to_positive')) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user