Commit febce763 by Qiang Xue

fixed build break and fixed doc about exists/not exists.

parent 4037e5c1
...@@ -158,6 +158,9 @@ Operator can be one of the following: ...@@ -158,6 +158,9 @@ Operator can be one of the following:
in the generated condition. in the generated condition.
- `or not like`: similar to the `not like` operator except that `OR` is used to concatenate - `or not like`: similar to the `not like` operator except that `OR` is used to concatenate
the `NOT LIKE` predicates. the `NOT LIKE` predicates.
- `exists`: requires one operand which must be an instance of [[Query]] representing the sub-query.
It will build a `EXISTS (sub-query)` expression.
- `not exists`: similar to the `exists` operator and builds a `NOT EXISTS (sub-query)` expression.
If you are building parts of condition dynamically it's very convenient to use `andWhere` and `orWhere`: If you are building parts of condition dynamically it's very convenient to use `andWhere` and `orWhere`:
......
...@@ -404,6 +404,11 @@ class Query extends Component implements QueryInterface ...@@ -404,6 +404,11 @@ class Query extends Component implements QueryInterface
* - `or not like`: similar to the `not like` operator except that `OR` is used to concatenate * - `or not like`: similar to the `not like` operator except that `OR` is used to concatenate
* the `NOT LIKE` predicates. * the `NOT LIKE` predicates.
* *
* - `exists`: requires one operand which must be an instance of [[Query]] representing the sub-query.
* It will build a `EXISTS (sub-query)` expression.
*
* - `not exists`: similar to the `exists` operator and builds a `NOT EXISTS (sub-query)` expression.
*
* @param string|array $condition the conditions that should be put in the WHERE part. * @param string|array $condition the conditions that should be put in the WHERE part.
* @param array $params the parameters (name => value) to be bound to the query. * @param array $params the parameters (name => value) to be bound to the query.
* @return static the query object itself * @return static the query object itself
......
...@@ -1077,7 +1077,7 @@ class QueryBuilder extends \yii\base\Object ...@@ -1077,7 +1077,7 @@ class QueryBuilder extends \yii\base\Object
/** /**
* Creates an SQL expressions with the `EXISTS` operator. * Creates an SQL expressions with the `EXISTS` operator.
* @param string $operator the operator to use (e.g. `EXISTS` or `NOT EXISTS`) * @param string $operator the operator to use (e.g. `EXISTS` or `NOT EXISTS`)
* @param array $operands contains only the one element. It is sub-query * @param array $operands contains only one element which is a [[Query]] object representing the sub-query.
* @param array $params the binding parameters to be populated * @param array $params the binding parameters to be populated
* @return string the generated SQL expression * @return string the generated SQL expression
*/ */
...@@ -1085,8 +1085,10 @@ class QueryBuilder extends \yii\base\Object ...@@ -1085,8 +1085,10 @@ class QueryBuilder extends \yii\base\Object
{ {
$subQuery = $operands[0]; $subQuery = $operands[0];
list($subQuerySql, $subQueryParams) = $this->build($subQuery); list($subQuerySql, $subQueryParams) = $this->build($subQuery);
foreach ($subQueryParams as $name => $value) { if (!empty($subQueryParams)) {
$params[$name] = $value; foreach ($subQueryParams as $name => $value) {
$params[$name] = $value;
}
} }
return "$operator ($subQuerySql)"; return "$operator ($subQuerySql)";
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment