Skip to content

Loading…

DBAL-171: PARAM_INT_ARRAY / PARAM_STR_ARRAY depends of parameter order #1331

Closed
doctrinebot opened this Issue · 3 comments

2 participants

@doctrinebot

Jira issue originally created by user arnaud-lb:

Named parameters appears to be treated as ordered parameters, when using PARAMINT_ARRAY or PARAM_STRARRAY:

$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.

@doctrinebot

Comment created by pschwisow:

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.

@doctrinebot

Comment created by @beberlei:

Fixed

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added the Bug label
@beberlei beberlei was assigned by doctrinebot
@doctrinebot doctrinebot added this to the 2.1.5 milestone
@doctrinebot doctrinebot closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.