DDC-1952: Add support for array parameters on the SQLFilter #2462

Closed
opened 2026-01-22 13:54:07 +01:00 by admin · 4 comments
Owner

Originally created by @doctrinebot on GitHub (Jul 27, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user holtkamp:

The SQLFilter currently only accepts string parameters which would result in SQL like:

"tableAlias.column = '$filterParameter'"

To filter an Entity that has a lifecycle, this can be usefull to filter Entities that are in a specific state, for example:

"tableAlias.state = 1"

To be able to apply the filter on an Entity that can be in multiple states, it is usefull to be able to assign an array of states using setParameter:

$allowedStates = array(1,2,3,4);
$filter->setParameter('allowedStatesParam', $allowedStates);
sprintf("tableAlias.state IN (%s)", implode(',', $this->getParameter('allowedStatesParam')));

to eventually result in:

"tableAlias.state IN (1,2,3,4)"

However, this is currently not supported, it seems to go wrong on the PDO::quote() of the parameter. The SQL works ok when setting it statically in the filter, not taking the parameter into account.

It would be nice to have support for arrays on the setParameter()

Originally created by @doctrinebot on GitHub (Jul 27, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user holtkamp: The SQLFilter currently only accepts string parameters which would result in SQL like: ``` "tableAlias.column = '$filterParameter'" ``` To filter an Entity that has a lifecycle, this can be usefull to filter Entities that are in a specific state, for example: ``` "tableAlias.state = 1" ``` To be able to apply the filter on an Entity that can be in multiple states, it is usefull to be able to assign an array of states using setParameter: ``` $allowedStates = array(1,2,3,4); $filter->setParameter('allowedStatesParam', $allowedStates); sprintf("tableAlias.state IN (%s)", implode(',', $this->getParameter('allowedStatesParam'))); ``` to eventually result in: ``` "tableAlias.state IN (1,2,3,4)" ``` However, this is currently not supported, it seems to go wrong on the PDO::quote() of the parameter. The SQL works ok when setting it statically in the filter, not taking the parameter into account. It would be nice to have support for arrays on the setParameter()
admin added the Improvement label 2026-01-22 13:54:07 +01:00
admin closed this issue 2026-01-22 13:54:09 +01:00
Author
Owner

@doctrinebot commented on GitHub (Oct 24, 2014):

Comment created by petr.pavel:

I've just created a pull request that implements just that. The only difference is that you don't call implode on the parameter when using it.
https://github.com/doctrine/doctrine2/pull/1168

The usage would be:

$allowedStates = array(1,2,3,4);
$filter->setParameter('allowedStatesParam', $allowedStates);

$quotedList = $this->getParameter('allowedStatesParam');
"tableAlias.state IN ($quotedList)"
@doctrinebot commented on GitHub (Oct 24, 2014): Comment created by petr.pavel: I've just created a pull request that implements just that. The only difference is that you don't call implode on the parameter when using it. https://github.com/doctrine/doctrine2/pull/1168 The usage would be: ``` $allowedStates = array(1,2,3,4); $filter->setParameter('allowedStatesParam', $allowedStates); $quotedList = $this->getParameter('allowedStatesParam'); "tableAlias.state IN ($quotedList)" ```
Author
Owner

@doctrinebot commented on GitHub (Jan 24, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1168] was labeled:
https://github.com/doctrine/doctrine2/pull/1168

@doctrinebot commented on GitHub (Jan 24, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1168] was labeled: https://github.com/doctrine/doctrine2/pull/1168
Author
Owner

@doctrinebot commented on GitHub (Nov 6, 2015):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-1168] was closed:
https://github.com/doctrine/doctrine2/pull/1168

@doctrinebot commented on GitHub (Nov 6, 2015): Comment created by @doctrinebot: A related Github Pull-Request [GH-1168] was closed: https://github.com/doctrine/doctrine2/pull/1168
Author
Owner

@beberlei commented on GitHub (Apr 19, 2021):

Implemented by #8375

@beberlei commented on GitHub (Apr 19, 2021): Implemented by #8375
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2462