Permalink
Browse files

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

  • Loading branch information...
1 parent 671c8b7 commit 9bf247cc3333a691c45423e9a41cacbed809a5c9 @stojg stojg committed with sminnee Dec 9, 2011
Showing with 37 additions and 2 deletions.
  1. +1 −1 model/DataList.php
  2. +17 −0 model/DataQuery.php
  3. +10 −1 model/SQLQuery.php
  4. +9 −0 tests/model/SQLQueryTest.php
View
@@ -292,7 +292,7 @@ public function exclude(){
$SQL_Statements[] = ('"'.$fieldName.'" != \''.Convert::raw2sql($value).'\'');
}
}
- $this->dataQuery->where(implode(' OR ', $SQL_Statements));
+ $this->dataQuery->whereAny($SQL_Statements);
return $this;
}
View
@@ -337,6 +337,23 @@ function where($filter) {
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
@@ -405,7 +405,16 @@ public function where() {
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.
*/
View
9 tests/model/SQLQueryTest.php 100644 → 100755
@@ -234,6 +234,15 @@ public function testInnerJoin() {
$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 {

0 comments on commit 9bf247c

Please sign in to comment.