DDC-680: Complex Mathematical Expressions in DQL Subselects #837

Closed
opened 2026-01-22 12:52:14 +01:00 by admin · 6 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 10, 2010).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user @beberlei:

It seems complex mathematical expressions are handled differently in DQL Subselects then in normal Selects:

    public function testSelectCorrelatedSubqueryComplexMathematicalExpression()
    {
        $this->assertSqlGeneration(
            'SELECT (SELECT (count(p.phonenumber)<ins>5)*10 FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p JOIN p.user ui WHERE ui.id = u.id) AS c FROM Doctrine\Tests\Models\CMS\CmsUser u',
            'SELECT (SELECT (count(c0*.phonenumber)</ins>5)*10 AS dctrn__1 FROM cms_phonenumbers c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id WHERE c1_.id = c2_.id) AS sclr0 FROM cms_users c2*'
        );
    }

    public function testSelectComplexMathematicalExpression()
    {
        $this->assertSqlGeneration(
            'SELECT (count(p.phonenumber)<ins>5)*10 FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p JOIN p.user ui WHERE ui.id = ?1',
            'SELECT (count(c0*.phonenumber) </ins> 5) * 10 AS sclr0 FROM cms_phonenumbers c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id WHERE c1*.id = ?'
        );
    }

Here the first test fails and the second passes. The second has the nested SQL running alone. The failure message is:

1) Doctrine\Tests\ORM\Query\SelectSqlGenerationTest::testSelectCorrelatedSubqueryComplexMathematicalExpression
[Syntax Error] line 0, col 15: Error: Expected One of: MAX, MIN, AVG, SUM, COUNT, got '('

/home/benny/code/php/wsnetbeans/doctrine2/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php:31
/home/benny/code/php/wsnetbeans/doctrine2/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php:709
Originally created by @doctrinebot on GitHub (Jul 10, 2010). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user @beberlei: It seems complex mathematical expressions are handled differently in DQL Subselects then in normal Selects: ``` public function testSelectCorrelatedSubqueryComplexMathematicalExpression() { $this->assertSqlGeneration( 'SELECT (SELECT (count(p.phonenumber)<ins>5)*10 FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p JOIN p.user ui WHERE ui.id = u.id) AS c FROM Doctrine\Tests\Models\CMS\CmsUser u', 'SELECT (SELECT (count(c0*.phonenumber)</ins>5)*10 AS dctrn__1 FROM cms_phonenumbers c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id WHERE c1_.id = c2_.id) AS sclr0 FROM cms_users c2*' ); } public function testSelectComplexMathematicalExpression() { $this->assertSqlGeneration( 'SELECT (count(p.phonenumber)<ins>5)*10 FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p JOIN p.user ui WHERE ui.id = ?1', 'SELECT (count(c0*.phonenumber) </ins> 5) * 10 AS sclr0 FROM cms_phonenumbers c0_ INNER JOIN cms_users c1_ ON c0_.user_id = c1_.id WHERE c1*.id = ?' ); } ``` Here the first test fails and the second passes. The second has the nested SQL running alone. The failure message is: ``` 1) Doctrine\Tests\ORM\Query\SelectSqlGenerationTest::testSelectCorrelatedSubqueryComplexMathematicalExpression [Syntax Error] line 0, col 15: Error: Expected One of: MAX, MIN, AVG, SUM, COUNT, got '(' /home/benny/code/php/wsnetbeans/doctrine2/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php:31 /home/benny/code/php/wsnetbeans/doctrine2/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php:709 ```
admin added the Bug label 2026-01-22 12:52:14 +01:00
admin closed this issue 2026-01-22 12:52:16 +01:00
Author
Owner

@doctrinebot commented on GitHub (Jul 11, 2010):

Comment created by @beberlei:

The problem seems to be in SelectExpression(). Functions are only detected in isolation, i.e. everything after the first function is ignored.

@doctrinebot commented on GitHub (Jul 11, 2010): Comment created by @beberlei: The problem seems to be in SelectExpression(). Functions are only detected in isolation, i.e. everything after the first function is ignored.
Author
Owner

@doctrinebot commented on GitHub (Aug 10, 2010):

Comment created by @guilhermeblanco:

Patch that fixes the issue.

However, I am not 100% if the alias (sclr) of subquery select expression should be generated and added to RSM.
Can anyone chat with me tomorrow and agree on this patch?

@doctrinebot commented on GitHub (Aug 10, 2010): Comment created by @guilhermeblanco: Patch that fixes the issue. However, I am not 100% if the alias (sclr) of subquery select expression should be generated and added to RSM. Can anyone chat with me tomorrow and agree on this patch?
Author
Owner

@doctrinebot commented on GitHub (Aug 11, 2010):

Comment created by @guilhermeblanco:

New patch

@doctrinebot commented on GitHub (Aug 11, 2010): Comment created by @guilhermeblanco: New patch
Author
Owner

@doctrinebot commented on GitHub (Aug 11, 2010):

Comment created by @guilhermeblanco:

In 84b9eda17c I have committed a fix to this issue.

@doctrinebot commented on GitHub (Aug 11, 2010): Comment created by @guilhermeblanco: In http://github.com/doctrine/doctrine2/commit/84b9eda17c8faead9ea59b39f12d1b78aa5ba823 I have committed a fix to this issue.
Author
Owner

@doctrinebot commented on GitHub (Aug 11, 2010):

Issue was closed with resolution "Fixed"

@doctrinebot commented on GitHub (Aug 11, 2010): Issue was closed with resolution "Fixed"
Author
Owner

@doctrinebot commented on GitHub (Dec 13, 2015):

Imported 1 attachments from Jira into https://gist.github.com/05f78980b5c88d1e967f

@doctrinebot commented on GitHub (Dec 13, 2015): Imported 1 attachments from Jira into https://gist.github.com/05f78980b5c88d1e967f - [10734_DDC680patch.diff](https://gist.github.com/05f78980b5c88d1e967f#file-10734_DDC680patch-diff)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#837