Doctrine 1
  1. Doctrine 1
  2. DC-585

Hydrate Array does not return full array, when Hydrate Scalar does

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      OS : Ubuntu 9.04
      PHP : PHP 5.2.6-3ubuntu4.5

      Description

      Description : Upon hydrating as array I will receive one row returned. If I am to hydrate as Scalar, I will get 200+ rows. Also, if i echo the sql ($q->getSqlQuery()) and run that raw, it will also return around 200+ rows.

      $q = Doctrine_Query::create()
      ->select('DISTINCT(co.name) AS field, co.name AS value')
      ->from('Model_Country co')
      ->leftJoin('co.City ci');

      //here we will get only the first row
      $results = $q->execute(array(), Doctrine::HYDRATE_ARRAY);

      //Here we will get all 200+ rows
      $results = $q->execute(array(), Doctrine::HYDRATE_SCALAR);

      I have yet to dig to deep into this, but if it is indeed a bug, my guess is it is in Doctrine_Hydrator_Graph::hydrateResultSet()

      I can provide more data if needed.

      1. Doctrine-DC-585-b.patch
        0.7 kB
        Pierrot Evrard
      2. Doctrine-DC-585-c.patch
        0.7 kB
        Pierrot Evrard

        Activity

        Hide
        Lacton added a comment -

        I have run into the same issue.

        Using the default hydration, I get only one record.

        Using "$query->execute(array(), Doctrine::HYDRATE_SCALAR);", I get all the expected records.

        Show
        Lacton added a comment - I have run into the same issue. Using the default hydration, I get only one record. Using "$query->execute(array(), Doctrine::HYDRATE_SCALAR);", I get all the expected records.
        Hide
        klemen nagode added a comment - - edited

        I found solution for my problem:

        Table had ID field but it was not primary key. When I deleted this column, doctrine started to work as expected.

        Show
        klemen nagode added a comment - - edited I found solution for my problem: Table had ID field but it was not primary key. When I deleted this column, doctrine started to work as expected.
        Hide
        klemen nagode added a comment -

        I also have this problem .. Anyone know howt o fix it?

        $query->execute(array(), Doctrine::HYDRATE_ARRAY); // returns one row only
        $query->execute(array(), Doctrine::HYDRATE_RECORD); // returns one row only

        $query->execute(array(), Doctrine::HYDRATE_SCALAR); // returns result as expected

        Show
        klemen nagode added a comment - I also have this problem .. Anyone know howt o fix it? $query->execute(array(), Doctrine::HYDRATE_ARRAY); // returns one row only $query->execute(array(), Doctrine::HYDRATE_RECORD); // returns one row only $query->execute(array(), Doctrine::HYDRATE_SCALAR); // returns result as expected
        Hide
        Pierrot Evrard added a comment - - edited

        Damn, the bug above was corrected during a few weeks and comes back with the new branch of Doctrine 1.2.14.

        Does anybody can re-apply the corrective patch (renamed DC-585-c), please ?

        I repeat it agin, but these few lines of code really need to be review.

        Loops

        Show
        Pierrot Evrard added a comment - - edited Damn, the bug above was corrected during a few weeks and comes back with the new branch of Doctrine 1.2.14. Does anybody can re-apply the corrective patch (renamed DC-585 -c), please ? I repeat it agin, but these few lines of code really need to be review. Loops
        Hide
        Pierrot Evrard added a comment - - edited

        Hi,

        I have a little issue with this bug report...

        I'm currently using Doctrine 1.2 at revision 7691, and I've encounter a bug when select the primary key of a model with a custom alias (typically $query->addSelect( 'r.id as my_id' )), the issue was that Doctrine automatically add `r`.```id``` AS `r_1` to the select clause, in addition to the correct `r`.`id` AS `r_1` part.

        So, I've browse the code to finally found where does this strange thing comes from, and I've found it on Doctrine_Query::parseSelect() method, just at the line 663:

        // Fix for http://www.doctrine-project.org/jira/browse/DC-585
        // Add selected columns to pending fields
        if (preg_match('/^([^\(]+)\.(\'?)(.*?)(\'?)$/', $expression, $field)) {
        $this->_pendingFields[$componentAlias][$alias] = $field[3];
        }

        So I'm wonder : where does this patch is related to this bug report?

        Whatever, the bug I've encounter is very simple : the regular expression that extract the field name takes care about ' but not ´.

        You will find a patch for the bug DC-585-b in a few minutes... This patch just make the regular expression taking account of ' and ´ and also remove all useless parentheses in expression (by this way PCRE get less matches to capture and we can earn some precious microseconds).

        Also, this patch should be completed because the query still have two `r`.`id` AS `r_1` parts, that may cause some other issues with some databases...

        IMPORTANT NOTE: The previous revision 7674 of Doctrine_Query does not cause the bug encounter with the few lines of code above, just because they were not there. They really must be review.

        Loops

        Show
        Pierrot Evrard added a comment - - edited Hi, I have a little issue with this bug report... I'm currently using Doctrine 1.2 at revision 7691, and I've encounter a bug when select the primary key of a model with a custom alias (typically $query->addSelect( 'r.id as my_id' ) ), the issue was that Doctrine automatically add `r`.```id``` AS `r _ 1` to the select clause, in addition to the correct `r`.`id` AS `r _ 1` part. So, I've browse the code to finally found where does this strange thing comes from, and I've found it on Doctrine_Query::parseSelect() method, just at the line 663: // Fix for http://www.doctrine-project.org/jira/browse/DC-585 // Add selected columns to pending fields if (preg_match('/^( [^\(] +)\.(\'?)(.*?)(\'?)$/', $expression, $field)) { $this->_pendingFields [$componentAlias] [$alias] = $field [3] ; } So I'm wonder : where does this patch is related to this bug report? Whatever, the bug I've encounter is very simple : the regular expression that extract the field name takes care about ' but not ´ . You will find a patch for the bug DC-585 -b in a few minutes... This patch just make the regular expression taking account of ' and ´ and also remove all useless parentheses in expression (by this way PCRE get less matches to capture and we can earn some precious microseconds). Also, this patch should be completed because the query still have two `r`.`id` AS `r _ 1` parts, that may cause some other issues with some databases... IMPORTANT NOTE: The previous revision 7674 of Doctrine_Query does not cause the bug encounter with the few lines of code above, just because they were not there. They really must be review. Loops

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            James Solomon
          • Votes:
            4 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

            • Created:
              Updated: