Doctrine 1
  1. Doctrine 1
  2. DC-706

Subqueries do not work in select

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Blocker Blocker
    • Resolution: Fixed
    • Affects Version/s: 1.2.2
    • Fix Version/s: 1.2.3
    • Component/s: None
    • Labels:
      None
    • Environment:
      XP, Xamp

      Description

      Hi All

      I have found another bug in Doctrine 1.2.2.

      Subqueries are not working in select statements at the moment.

      The reason for this is that this line (found in the parseSelect function of the class Doctrine_Query) :

      $componentAlias = $this->getExpressionOwner($expression);
      

      Returns an unusable value when passed an $expression which is a subquery.

      To fix this problem I have patched my version of the code to use an existing "$componentAlias" instead of the value that would be returned by this function when a subquery is encountered.

      My code now reads:

      if ($pos !== false && substr($term[0], 0, 1) !== "'" && substr($term[0], 0, $pos) == '') {
      	$_queryComponents = $this->_queryComponents;
      	reset($components);
      	$componentAlias = key($_queryComponents);
      } else {
              $componentAlias = $this->getExpressionOwner($expression);
      }
      

      I have not rigorously tested this patch yet but it has been working for me in what tests I have done so far.

      I have posted several very large bugs into jira over the past few months and haven't heard back regarding them. This leads me to believe that the Doctrine team has moved on from Doctrine 1.2.2 and is focusing only on Doctrine 2 issues at this point. I still love version 1 and haven't had the heart (or the time) to migrate my code over to 2 yet. If this is the case then the job of patching bugs like the ones I have reported in 1.2.2 is probably up to us users at this point. As such I will post my patched version of Doctrine_Query in a comment to this bug (My patched version also fixes another bug I reported: DC-594) .

      Best Regards

      Will Ferrer

      1. Query.php.patch
        177 kB
        will ferrer
      2. ticketDC706.patch
        3 kB
        will ferrer

        Activity

        Hide
        will ferrer added a comment -

        Hi Jon

        I checked out the svn branch 1.2.2 and noticed that you had my original/broken patch in the code (that one failed some tests for me so I fixed it and tried to upload it in the last patch file I attached to this thread – the patch file that didn't work).

        Using the technique you described I made a working patch to put the correct version of my code into the 1.2.2 branch.

        I also added a test case for this fix in my patch.

        Please see the new patch I have attached to this thread.

        Thanks for all your help.

        Will Ferrer

        Show
        will ferrer added a comment - Hi Jon I checked out the svn branch 1.2.2 and noticed that you had my original/broken patch in the code (that one failed some tests for me so I fixed it and tried to upload it in the last patch file I attached to this thread – the patch file that didn't work). Using the technique you described I made a working patch to put the correct version of my code into the 1.2.2 branch. I also added a test case for this fix in my patch. Please see the new patch I have attached to this thread. Thanks for all your help. Will Ferrer
        Hide
        will ferrer added a comment -

        Here is the correct patch for the bug fix, along with the test case for it.

        Show
        will ferrer added a comment - Here is the correct patch for the bug fix, along with the test case for it.
        Hide
        will ferrer added a comment -

        I reopened the issue to call attention to the fixed patch/test case I added to the thread.

        Show
        will ferrer added a comment - I reopened the issue to call attention to the fixed patch/test case I added to the thread.
        Hide
        Jonathan H. Wage added a comment -

        That one works and looks better. Just had a few tabs vs spaces problems that I fixed. Thanks for your work on this. It is much appreciated!!!!!

        Show
        Jonathan H. Wage added a comment - That one works and looks better. Just had a few tabs vs spaces problems that I fixed. Thanks for your work on this. It is much appreciated!!!!!
        Hide
        will ferrer added a comment -

        Hi Jon

        No problem – I am very glad to contribute back to the project . Doctrine has really been invaluable to me in my development, thanks for building it.

        Hope you are well.

        Will Ferrer

        Show
        will ferrer added a comment - Hi Jon No problem – I am very glad to contribute back to the project . Doctrine has really been invaluable to me in my development, thanks for building it. Hope you are well. Will Ferrer

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            will ferrer
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: