Doctrine DBAL
  1. Doctrine DBAL
  2. DBAL-171

PARAM_INT_ARRAY / PARAM_STR_ARRAY depends of parameter order

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.1
    • Fix Version/s: 2.1.5
    • Component/s: None
    • Security Level: All
    • Labels:
      None

      Description

      Named parameters appears to be treated as ordered parameters, when using PARAM_INT_ARRAY or PARAM_STR_ARRAY:

      $query = $em->createQuery('
      SELECT f FROM Foo f
      WHERE a = :a
      AND b IN (:b)
      ');
      
      $query->setParameters(array(
          'b' => array(1,2,3),
          'a' => 1,
      ));
      

      Notice that in the query the parameter :a appears before :b. And I call ->setParameters() with :b before :a.

      When running this, I get an error from Doctrine/DBAL/SQLParserUtils::expandListParameters:119 saying that the second parameter of array_merge() is not an array.

      When setting the parameters in the same order than they appear in the query, it works:

      $query->setParameters(array(
          'a' => 1,
          'b' => array(1,2,3),
      ));
      

      This is unexpected, as I'm using named parameters; the order should not matter.

        Activity

        arnaud-lb created issue -
        arnaud-lb made changes -
        Field Original Value New Value
        Description I have an error in this query:

        {code}
        $query = $em->createQuery('
        SELECT f FROM Foo f
        WHERE a = :a
        AND b IN (:b)
        ');

        $query->setParameters(array(
            'b' => array(1,2,3),
            'a' => 1,
        ));
        {code}

        Notice that in the query the parameter :a is before :b; and I set :b before setting :a.

        When running this, I get an error from [Doctrine/DBAL/SQLParserUtils::expandListParameters:119|https://github.com/doctrine/dbal/blob/2a44c94b9b15de446ecdff3ee8581c5d56f6ed3e/lib/Doctrine/DBAL/SQLParserUtils.php#L119] saying that the second parameter of array_merge() is not an array.

        When setting the parameters in the same order than they appear in the query, it works:

        {code}
        $query->setParameters(array(
            'a' => 1,
            'b' => array(1,2,3),
        ));
        {code}
        Named parameters appears to be treated as ordered parameters, when using PARAM_INT_ARRAY or PARAM_STR_ARRAY:


        {code}
        $query = $em->createQuery('
        SELECT f FROM Foo f
        WHERE a = :a
        AND b IN (:b)
        ');

        $query->setParameters(array(
            'b' => array(1,2,3),
            'a' => 1,
        ));
        {code}

        Notice that in the query the parameter :a appears before :b. And I call ->setParameters() with :b before :a.

        When running this, I get an error from [Doctrine/DBAL/SQLParserUtils::expandListParameters:119|https://github.com/doctrine/dbal/blob/2a44c94b9b15de446ecdff3ee8581c5d56f6ed3e/lib/Doctrine/DBAL/SQLParserUtils.php#L119] saying that the second parameter of array_merge() is not an array.

        When setting the parameters in the same order than they appear in the query, it works:

        {code}
        $query->setParameters(array(
            'a' => 1,
            'b' => array(1,2,3),
        ));
        {code}

        This is unexpected, as I'm using named parameters; the order should not matter.
        Benjamin Eberlei made changes -
        Project Doctrine 2 - ORM [ 10032 ] Doctrine DBAL [ 10040 ]
        Key DDC-1372 DBAL-171
        Patrick Schwisow made changes -
        Affects Version/s 2.1.1 [ 10156 ]
        Benjamin Eberlei made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Fix Version/s 2.1.4 [ 10167 ]
        Resolution Fixed [ 1 ]
        Benjamin Eberlei made changes -
        Workflow jira [ 13013 ] jira-feedback2 [ 17751 ]
        Benjamin Eberlei made changes -
        Workflow jira-feedback2 [ 17751 ] jira-feedback3 [ 20106 ]

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            arnaud-lb
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: