API CHANGE Introduced DataQuery::whereAny() and SQLQuery::whereAny()

This commit is contained in:
Stig Lindqvist 2011-12-09 14:09:07 +01:00 committed by Sam Minnee
parent 671c8b734d
commit 9bf247cc33
4 changed files with 37 additions and 2 deletions

View File

@ -292,7 +292,7 @@ class DataList extends ViewableData implements SS_List {
$SQL_Statements[] = ('"'.$fieldName.'" != \''.Convert::raw2sql($value).'\'');
}
}
$this->dataQuery->where(implode(' OR ', $SQL_Statements));
$this->dataQuery->whereAny($SQL_Statements);
return $this;
}

View File

@ -337,6 +337,23 @@ class DataQuery {
return $this;
}
}
/**
* Set a WHERE with OR
*
* @param array $filter
* @return DataQuery
* @example $dataQuery->whereAny(array("Monkey = 'Chimp'", "Color = 'Brown'"));
*/
function whereAny($filter) {
if($filter) {
$clone = $this;
$clone->query->whereAny($filter);
return $clone;
} else {
return $this;
}
}
/**
* Set the ORDER BY clause of this query

View File

@ -405,7 +405,16 @@ class SQLQuery {
return $this;
}
/**
*
*/
function whereAny($filters) {
if(is_string($filters)) $filters = func_get_args();
$clause = implode(" OR ", $filters);
return $this->where($clause);
}
/**
* Use the disjunctive operator 'OR' to join filter expressions in the WHERE clause.
*/

9
tests/model/SQLQueryTest.php Normal file → Executable file
View File

@ -234,6 +234,15 @@ class SQLQueryTest extends SapphireTest {
$query->sql()
);
}
public function testWhereAny() {
$query = new SQLQuery();
$query->from( 'MyTable' );
$query->whereAny(array("Monkey = 'Chimp'", "Color = 'Brown'"));
$this->assertEquals("SELECT * FROM MyTable WHERE (Monkey = 'Chimp' OR Color = 'Brown')",$query->sql());
}
}
class SQLQueryTest_DO extends DataObject implements TestOnly {