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

        Hide
        Benjamin Eberlei added a comment -

        Fixed

        Show
        Benjamin Eberlei added a comment - Fixed
        Hide
        Patrick Schwisow added a comment -

        I'm getting this issue too.

        Doctrine\ORM\Query::_doExecute() does a ksort on $sqlParams, but does not sort $types. Doctrine\DBAL\SQLParserUtils::expandListParameters() assumes that $params and $types are in the same order.

        As a workaround, I added ksort($types) in _doExecute(), but I'm not sure if this is the proper way to handle this.

        Show
        Patrick Schwisow added a comment - I'm getting this issue too. Doctrine\ORM\Query::_doExecute() does a ksort on $sqlParams, but does not sort $types. Doctrine\DBAL\SQLParserUtils::expandListParameters() assumes that $params and $types are in the same order. As a workaround, I added ksort($types) in _doExecute(), but I'm not sure if this is the proper way to handle this.

          People

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

            Dates

            • Created:
              Updated:
              Resolved: