Skip to content

Commit

Permalink
API CHANGE Introduced DataQuery::whereAny() and SQLQuery::whereAny()
Browse files Browse the repository at this point in the history
  • Loading branch information
Stig Lindqvist authored and Sam Minnee committed Dec 17, 2011
1 parent 671c8b7 commit 9bf247c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion model/DataList.php
Expand Up @@ -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;
}

Expand Down
17 changes: 17 additions & 0 deletions model/DataQuery.php
Expand Up @@ -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
Expand Down
11 changes: 10 additions & 1 deletion model/SQLQuery.php
Expand Up @@ -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.
*/
Expand Down
9 changes: 9 additions & 0 deletions tests/model/SQLQueryTest.php 100644 → 100755
Expand Up @@ -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 {
Expand Down

0 comments on commit 9bf247c

Please sign in to comment.