|
|
@ -1,6 +1,6 @@ |
|
|
|
<?php |
|
|
|
<?php |
|
|
|
/** |
|
|
|
/** |
|
|
|
* ActiveQuery class file. |
|
|
|
* ActiveFinder class file. |
|
|
|
* |
|
|
|
* |
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
* @link http://www.yiiframework.com/ |
|
|
|
* @link http://www.yiiframework.com/ |
|
|
@ -18,10 +18,10 @@ use yii\db\Exception; |
|
|
|
* ActiveFinder.php is ... |
|
|
|
* ActiveFinder.php is ... |
|
|
|
* todo: add SQL monitor |
|
|
|
* todo: add SQL monitor |
|
|
|
* |
|
|
|
* |
|
|
|
* todo: add ActiveQueryBuilder |
|
|
|
* todo: add ActiveFinderBuilder |
|
|
|
* todo: quote join/on part of the relational query |
|
|
|
* todo: quote join/on part of the relational query |
|
|
|
* todo: modify QueryBuilder about join() methods |
|
|
|
* todo: modify QueryBuilder about join() methods |
|
|
|
* todo: unify ActiveQuery and ActiveRelation in query building process |
|
|
|
* todo: unify ActiveFinder and ActiveRelation in query building process |
|
|
|
* todo: intelligent table aliasing (first table name, then relation name, finally t?) |
|
|
|
* todo: intelligent table aliasing (first table name, then relation name, finally t?) |
|
|
|
* todo: allow using tokens in primary query fragments |
|
|
|
* todo: allow using tokens in primary query fragments |
|
|
|
* todo: findBySql |
|
|
|
* todo: findBySql |
|
|
@ -33,14 +33,14 @@ use yii\db\Exception; |
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
* @since 2.0 |
|
|
|
* @since 2.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \ArrayAccess, \Countable |
|
|
|
class ActiveFinder extends \yii\base\Object implements \IteratorAggregate, \ArrayAccess, \Countable |
|
|
|
{ |
|
|
|
{ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var string the name of the ActiveRecord class. |
|
|
|
* @var string the name of the ActiveRecord class. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $modelClass; |
|
|
|
public $modelClass; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* @var \yii\db\dao\Query the Query object |
|
|
|
* @var Query the Query object |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public $query; |
|
|
|
public $query; |
|
|
|
/** |
|
|
|
/** |
|
|
@ -278,7 +278,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* @param string $option additional option that should be appended to the 'SELECT' keyword. For example, |
|
|
|
* @param string $option additional option that should be appended to the 'SELECT' keyword. For example, |
|
|
|
* in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used. |
|
|
|
* in MySQL, the option 'SQL_CALC_FOUND_ROWS' can be used. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function select($columns, $option = '') |
|
|
|
public function select($columns, $option = '') |
|
|
|
{ |
|
|
|
{ |
|
|
@ -289,7 +289,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the value indicating whether to SELECT DISTINCT or not. |
|
|
|
* Sets the value indicating whether to SELECT DISTINCT or not. |
|
|
|
* @param bool $value whether to SELECT DISTINCT or not. |
|
|
|
* @param bool $value whether to SELECT DISTINCT or not. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function distinct($value = true) |
|
|
|
public function distinct($value = true) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -304,7 +304,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* Table names can contain schema prefixes (e.g. 'public.tbl_user') and/or table aliases (e.g. 'tbl_user u'). |
|
|
|
* Table names can contain schema prefixes (e.g. 'public.tbl_user') and/or table aliases (e.g. 'tbl_user u'). |
|
|
|
* The method will automatically quote the table names unless it contains some parenthesis |
|
|
|
* The method will automatically quote the table names unless it contains some parenthesis |
|
|
|
* (which means the table is given as a sub-query or DB expression). |
|
|
|
* (which means the table is given as a sub-query or DB expression). |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function from($tables) |
|
|
|
public function from($tables) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -379,7 +379,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* @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. |
|
|
|
* For anonymous parameters, they can alternatively be specified as separate parameters to this method. |
|
|
|
* For anonymous parameters, they can alternatively be specified as separate parameters to this method. |
|
|
|
* For example, `where('type=? AND status=?', 100, 1)`. |
|
|
|
* For example, `where('type=? AND status=?', 100, 1)`. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see andWhere() |
|
|
|
* @see andWhere() |
|
|
|
* @see orWhere() |
|
|
|
* @see orWhere() |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -400,7 +400,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* on how to specify this parameter. |
|
|
|
* on how to specify this parameter. |
|
|
|
* @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. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see where() |
|
|
|
* @see where() |
|
|
|
* @see orWhere() |
|
|
|
* @see orWhere() |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -421,7 +421,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* on how to specify this parameter. |
|
|
|
* on how to specify this parameter. |
|
|
|
* @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. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see where() |
|
|
|
* @see where() |
|
|
|
* @see andWhere() |
|
|
|
* @see andWhere() |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -445,7 +445,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* Please refer to [[where()]] on how to specify this parameter. |
|
|
|
* Please refer to [[where()]] on how to specify this parameter. |
|
|
|
* @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. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function join($table, $condition, $params = array()) |
|
|
|
public function join($table, $condition, $params = array()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -466,7 +466,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* @param string|array $condition the join condition that should appear in the ON part. |
|
|
|
* @param string|array $condition the join condition that should appear in the ON part. |
|
|
|
* Please refer to [[where()]] on how to specify this parameter. |
|
|
|
* Please refer to [[where()]] on how to specify this parameter. |
|
|
|
* @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 ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function leftJoin($table, $condition, $params = array()) |
|
|
|
public function leftJoin($table, $condition, $params = array()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -487,7 +487,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* @param string|array $condition the join condition that should appear in the ON part. |
|
|
|
* @param string|array $condition the join condition that should appear in the ON part. |
|
|
|
* Please refer to [[where()]] on how to specify this parameter. |
|
|
|
* Please refer to [[where()]] on how to specify this parameter. |
|
|
|
* @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 ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function rightJoin($table, $condition, $params = array()) |
|
|
|
public function rightJoin($table, $condition, $params = array()) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -506,7 +506,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). |
|
|
|
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). |
|
|
|
* The method will automatically quote the table name unless it contains some parenthesis |
|
|
|
* The method will automatically quote the table name unless it contains some parenthesis |
|
|
|
* (which means the table is given as a sub-query or DB expression). |
|
|
|
* (which means the table is given as a sub-query or DB expression). |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function crossJoin($table) |
|
|
|
public function crossJoin($table) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -521,7 +521,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). |
|
|
|
* Table name can contain schema prefix (e.g. 'public.tbl_user') and/or table alias (e.g. 'tbl_user u'). |
|
|
|
* The method will automatically quote the table name unless it contains some parenthesis |
|
|
|
* The method will automatically quote the table name unless it contains some parenthesis |
|
|
|
* (which means the table is given as a sub-query or DB expression). |
|
|
|
* (which means the table is given as a sub-query or DB expression). |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function naturalJoin($table) |
|
|
|
public function naturalJoin($table) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -535,7 +535,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')). |
|
|
|
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')). |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see addGroupBy() |
|
|
|
* @see addGroupBy() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function groupBy($columns) |
|
|
|
public function groupBy($columns) |
|
|
@ -550,7 +550,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')). |
|
|
|
* Columns can be specified in either a string (e.g. "id, name") or an array (e.g. array('id', 'name')). |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see groupBy() |
|
|
|
* @see groupBy() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function addGroupBy($columns) |
|
|
|
public function addGroupBy($columns) |
|
|
@ -565,7 +565,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* Please refer to [[where()]] on how to specify this parameter. |
|
|
|
* Please refer to [[where()]] on how to specify this parameter. |
|
|
|
* @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. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see andHaving() |
|
|
|
* @see andHaving() |
|
|
|
* @see orHaving() |
|
|
|
* @see orHaving() |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -586,7 +586,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* on how to specify this parameter. |
|
|
|
* on how to specify this parameter. |
|
|
|
* @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. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see having() |
|
|
|
* @see having() |
|
|
|
* @see orHaving() |
|
|
|
* @see orHaving() |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -607,7 +607,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* on how to specify this parameter. |
|
|
|
* on how to specify this parameter. |
|
|
|
* @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. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see having() |
|
|
|
* @see having() |
|
|
|
* @see andHaving() |
|
|
|
* @see andHaving() |
|
|
|
*/ |
|
|
|
*/ |
|
|
@ -627,7 +627,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. array('id ASC', 'name DESC')). |
|
|
|
* Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. array('id ASC', 'name DESC')). |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see addOrderBy() |
|
|
|
* @see addOrderBy() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function orderBy($columns) |
|
|
|
public function orderBy($columns) |
|
|
@ -642,7 +642,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. array('id ASC', 'name DESC')). |
|
|
|
* Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. array('id ASC', 'name DESC')). |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* The method will automatically quote the column names unless a column contains some parenthesis |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* (which means the column contains a DB expression). |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see orderBy() |
|
|
|
* @see orderBy() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function addOrderBy($columns) |
|
|
|
public function addOrderBy($columns) |
|
|
@ -654,7 +654,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the LIMIT part of the query. |
|
|
|
* Sets the LIMIT part of the query. |
|
|
|
* @param integer $limit the limit |
|
|
|
* @param integer $limit the limit |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function limit($limit) |
|
|
|
public function limit($limit) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -665,7 +665,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sets the OFFSET part of the query. |
|
|
|
* Sets the OFFSET part of the query. |
|
|
|
* @param integer $offset the offset |
|
|
|
* @param integer $offset the offset |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function offset($offset) |
|
|
|
public function offset($offset) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -676,7 +676,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Appends a SQL statement using UNION operator. |
|
|
|
* Appends a SQL statement using UNION operator. |
|
|
|
* @param string|Query $sql the SQL statement to be appended using UNION |
|
|
|
* @param string|Query $sql the SQL statement to be appended using UNION |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function union($sql) |
|
|
|
public function union($sql) |
|
|
|
{ |
|
|
|
{ |
|
|
@ -694,7 +694,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* @param array list of query parameter values indexed by parameter placeholders. |
|
|
|
* @param array list of query parameter values indexed by parameter placeholders. |
|
|
|
* For example, `array(':name'=>'Dan', ':age'=>31)`. |
|
|
|
* For example, `array(':name'=>'Dan', ':age'=>31)`. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see addParams() |
|
|
|
* @see addParams() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function params($params) |
|
|
|
public function params($params) |
|
|
@ -708,7 +708,7 @@ class ActiveQuery extends \yii\base\Object implements \IteratorAggregate, \Array |
|
|
|
* @param array list of query parameter values indexed by parameter placeholders. |
|
|
|
* @param array list of query parameter values indexed by parameter placeholders. |
|
|
|
* For example, `array(':name'=>'Dan', ':age'=>31)`. |
|
|
|
* For example, `array(':name'=>'Dan', ':age'=>31)`. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* Please refer to [[where()]] on alternative syntax of specifying anonymous parameters. |
|
|
|
* @return ActiveQuery the query object itself |
|
|
|
* @return ActiveFinder the query object itself |
|
|
|
* @see params() |
|
|
|
* @see params() |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public function addParams($params) |
|
|
|
public function addParams($params) |