#483808 by chx and Crell: Default DBTNG conditions to IN when an array of values is passed in, to match the field query API.

merge-requests/26/head
Angie Byron 2009-06-06 16:57:52 +00:00
parent 7442dc060f
commit c3e95d2532
2 changed files with 11 additions and 16 deletions

View File

@ -31,10 +31,8 @@ interface QueryConditionInterface {
* dependent on the $operator. * dependent on the $operator.
* @param $operator * @param $operator
* The comparison operator, such as =, <, or >=. It also accepts more complex * The comparison operator, such as =, <, or >=. It also accepts more complex
* options such as IN, LIKE, or BETWEEN. * options such as IN, LIKE, or BETWEEN. Defaults to IN if $value is an array
* @param $num_args * = otherwise.
* For internal use only. This argument is used to track the recursive calls when
* processing complex conditions.
* @return * @return
* The called object. * The called object.
*/ */
@ -794,11 +792,8 @@ class DeleteQuery extends Query implements QueryConditionInterface {
$this->condition = new DatabaseCondition('AND'); $this->condition = new DatabaseCondition('AND');
} }
public function condition($field, $value = NULL, $operator = '=') { public function condition($field, $value = NULL, $operator = NULL) {
if (!isset($num_args)) { $this->condition->condition($field, $value, $operator);
$num_args = func_num_args();
}
$this->condition->condition($field, $value, $operator, $num_args);
return $this; return $this;
} }
@ -939,11 +934,8 @@ class UpdateQuery extends Query implements QueryConditionInterface {
$this->condition = new DatabaseCondition('AND'); $this->condition = new DatabaseCondition('AND');
} }
public function condition($field, $value = NULL, $operator = '=') { public function condition($field, $value = NULL, $operator = NULL) {
if (!isset($num_args)) { $this->condition->condition($field, $value, $operator);
$num_args = func_num_args();
}
$this->condition->condition($field, $value, $operator, $num_args);
return $this; return $this;
} }
@ -1094,7 +1086,10 @@ class DatabaseCondition implements QueryConditionInterface, Countable {
return count($this->conditions) - 1; return count($this->conditions) - 1;
} }
public function condition($field, $value = NULL, $operator = '=') { public function condition($field, $value = NULL, $operator = NULL) {
if (!isset($operator)) {
$operator = is_array($value) ? 'IN' : '=';
}
$this->conditions[] = array( $this->conditions[] = array(
'field' => $field, 'field' => $field,
'value' => $value, 'value' => $value,

View File

@ -423,7 +423,7 @@ class SelectQueryExtender implements SelectQueryInterface {
/* Implementations of QueryConditionInterface for the WHERE clause. */ /* Implementations of QueryConditionInterface for the WHERE clause. */
public function condition($field, $value = NULL, $operator = '=') { public function condition($field, $value = NULL, $operator = NULL) {
$this->query->condition($field, $value, $operator); $this->query->condition($field, $value, $operator);
return $this; return $this;
} }