BUG Fix filtersOnId ignoring WHERE "ID" IN () (#5546)

This commit is contained in:
Damian Mooyman 2016-05-17 18:30:33 +12:00 committed by Sam Minnée
parent c66a969c1d
commit 8947bb0245
2 changed files with 37 additions and 3 deletions

View File

@ -650,9 +650,8 @@ abstract class SQLConditionalExpression extends SQLExpression {
* @return boolean * @return boolean
*/ */
public function filtersOnID() { public function filtersOnID() {
$regexp = '/^(.*\.)?("|`)?ID("|`)?\s?=/'; $regexp = '/^(.*\.)?("|`)?ID("|`)?\s?(=|IN)/';
// @todo - Test this works with paramaterised queries
foreach($this->getWhereParameterised($parameters) as $predicate) { foreach($this->getWhereParameterised($parameters) as $predicate) {
if(preg_match($regexp, $predicate)) return true; if(preg_match($regexp, $predicate)) return true;
} }
@ -668,7 +667,7 @@ abstract class SQLConditionalExpression extends SQLExpression {
* @return boolean * @return boolean
*/ */
public function filtersOnFK() { public function filtersOnFK() {
$regexp = '/^(.*\.)?("|`)?[a-zA-Z]+ID("|`)?\s?=/'; $regexp = '/^(.*\.)?("|`)?[a-zA-Z]+ID("|`)?\s?(=|IN)/';
// @todo - Test this works with paramaterised queries // @todo - Test this works with paramaterised queries
foreach($this->getWhereParameterised($parameters) as $predicate) { foreach($this->getWhereParameterised($parameters) as $predicate) {

View File

@ -321,6 +321,41 @@ class SQLQueryTest extends SapphireTest {
"filtersOnID() is true with simple unquoted column name" "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 = new SQLQuery();
$query->setWhere("ID=5"); $query->setWhere("ID=5");
$this->assertTrue( $this->assertTrue(