Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-680

Complex Mathematical Expressions in DQL Subselects

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA2
    • Fix Version/s: 2.0-BETA4
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      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)+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)+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)+5)*10 FROM Doctrine\Tests\Models\CMS\CmsPhonenumber p JOIN p.user ui WHERE ui.id = ?1',
                  'SELECT (count(c0_.phonenumber) + 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
      

        Activity

        Hide
        Benjamin Eberlei added a comment -

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

        Show
        Benjamin Eberlei added a comment - The problem seems to be in SelectExpression(). Functions are only detected in isolation, i.e. everything after the first function is ignored.
        Hide
        Guilherme Blanco added a comment -

        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?

        Show
        Guilherme Blanco added a comment - 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?
        Hide
        Guilherme Blanco added a comment -

        New patch

        Show
        Guilherme Blanco added a comment - New patch
        Hide
        Guilherme Blanco added a comment -
        Show
        Guilherme Blanco added a comment - In http://github.com/doctrine/doctrine2/commit/84b9eda17c8faead9ea59b39f12d1b78aa5ba823 I have committed a fix to this issue.

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Benjamin Eberlei
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: