mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
BUG Fix filtersOnId ignoring WHERE "ID" IN ()
(#5546)
This commit is contained in:
parent
c66a969c1d
commit
8947bb0245
@ -650,9 +650,8 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
||||
* @return boolean
|
||||
*/
|
||||
public function filtersOnID() {
|
||||
$regexp = '/^(.*\.)?("|`)?ID("|`)?\s?=/';
|
||||
$regexp = '/^(.*\.)?("|`)?ID("|`)?\s?(=|IN)/';
|
||||
|
||||
// @todo - Test this works with paramaterised queries
|
||||
foreach($this->getWhereParameterised($parameters) as $predicate) {
|
||||
if(preg_match($regexp, $predicate)) return true;
|
||||
}
|
||||
@ -668,7 +667,7 @@ abstract class SQLConditionalExpression extends SQLExpression {
|
||||
* @return boolean
|
||||
*/
|
||||
public function filtersOnFK() {
|
||||
$regexp = '/^(.*\.)?("|`)?[a-zA-Z]+ID("|`)?\s?=/';
|
||||
$regexp = '/^(.*\.)?("|`)?[a-zA-Z]+ID("|`)?\s?(=|IN)/';
|
||||
|
||||
// @todo - Test this works with paramaterised queries
|
||||
foreach($this->getWhereParameterised($parameters) as $predicate) {
|
||||
|
@ -321,6 +321,41 @@ class SQLQueryTest extends SapphireTest {
|
||||
"filtersOnID() is true with simple unquoted column name"
|
||||
);
|
||||
|
||||
$query = new SQLQuery();
|
||||
$query->setWhere('"ID" = 5');
|
||||
$this->assertTrue(
|
||||
$query->filtersOnID(),
|
||||
"filtersOnID() is true with simple quoted column name"
|
||||
);
|
||||
|
||||
$query = new SQLQuery();
|
||||
$query->setWhere(array('"ID"' => 4));
|
||||
$this->assertTrue(
|
||||
$query->filtersOnID(),
|
||||
"filtersOnID() is true with parameterised quoted column name"
|
||||
);
|
||||
|
||||
$query = new SQLQuery();
|
||||
$query->setWhere(array('"ID" = ?' => 4));
|
||||
$this->assertTrue(
|
||||
$query->filtersOnID(),
|
||||
"filtersOnID() is true with parameterised quoted column name"
|
||||
);
|
||||
|
||||
$query = new SQLQuery();
|
||||
$query->setWhere('"ID" IN (5,4)');
|
||||
$this->assertTrue(
|
||||
$query->filtersOnID(),
|
||||
"filtersOnID() is true with WHERE ID IN"
|
||||
);
|
||||
|
||||
$query = new SQLQuery();
|
||||
$query->setWhere(array('"ID" IN ?' => array(1,2)));
|
||||
$this->assertTrue(
|
||||
$query->filtersOnID(),
|
||||
"filtersOnID() is true with parameterised WHERE ID IN"
|
||||
);
|
||||
|
||||
$query = new SQLQuery();
|
||||
$query->setWhere("ID=5");
|
||||
$this->assertTrue(
|
||||
|
Loading…
x
Reference in New Issue
Block a user