[DBAL-171] PARAM_INT_ARRAY / PARAM_STR_ARRAY depends of parameter order Created: 11/Sep/11  Updated: 18/Nov/11  Resolved: 18/Nov/11

Status: Resolved
Project: Doctrine DBAL
Component/s: None
Affects Version/s: 2.1.1
Fix Version/s: 2.1.5
Security Level: All

Type: Bug Priority: Major
Reporter: arnaud-lb Assignee: Benjamin Eberlei
Resolution: Fixed Votes: 1
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.



 Comments   
Comment by Patrick Schwisow [ 27/Sep/11 ]

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.

Comment by Benjamin Eberlei [ 18/Nov/11 ]

Fixed

Generated at Fri Nov 28 18:28:57 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.