CJoinQuery
| Пакет | system.db.ar |
|---|---|
| Наследование | класс CJoinQuery |
| С версии | 1.0 |
| Исходный код | framework/db/ar/CActiveFinder.php |
CJoinQuery представляет оператор JOIN SQL.
Свойства общедоступные
| Свойство | Тип | Описание | Определено в |
|---|---|---|---|
| conditions | массив | список условий WHERE | CJoinQuery |
| distinct | булево | выбирать ли уникальные результаты | CJoinQuery |
| elements | массив | список идентификаторов элементов объединения (id=>true) | CJoinQuery |
| groups | массив | список условий GROUP BY | CJoinQuery |
| havings | массив | список условий HAVING | CJoinQuery |
| joins | массив | список операторов объединения | CJoinQuery |
| limit | целое | ограничение строк | CJoinQuery |
| offset | целое | смещение строк | CJoinQuery |
| orders | массив | список условий ORDER BY | CJoinQuery |
| params | массив | список параметров запроса | CJoinQuery |
| selects | массив | список выбранных столбцов | CJoinQuery |
Методы общедоступные
| Метод | Описание | Определено в |
|---|---|---|
| __construct() | Конструктор. | CJoinQuery |
| createCommand() | Создаёт оператор SQL. | CJoinQuery |
| join() | Объединяет с другим элементом объединения | CJoinQuery |
Подробное описание свойств
conditions свойство
public array $conditions;
список условий WHERE
distinct свойство
public boolean $distinct;
выбирать ли уникальные результаты
elements свойство
public array $elements;
список идентификаторов элементов объединения (id=>true)
groups свойство
public array $groups;
список условий GROUP BY
havings свойство
public array $havings;
список условий HAVING
joins свойство
public array $joins;
список операторов объединения
limit свойство
public integer $limit;
ограничение строк
offset свойство
public integer $offset;
смещение строк
orders свойство
public array $orders;
список условий ORDER BY
params свойство
public array $params;
список параметров запроса
selects свойство
public array $selects;
список выбранных столбцов
Подробное описание методов
__construct() метод
public void __construct(CJoinElement $joinElement, CDbCriteria $criteria=NULL) | ||
| $joinElement | CJoinElement | Корневое дерево объединения. |
| $criteria | CDbCriteria | критерии запроса |
Исходный код: framework/db/ar/CActiveFinder.php#1280 (показать)
public function __construct($joinElement,$criteria=null)
{
if($criteria!==null)
{
$this->selects[]=$joinElement->getColumnSelect($criteria->select);
$this->joins[]=$joinElement->getTableNameWithAlias();
$this->joins[]=$criteria->join;
$this->conditions[]=$criteria->condition;
$this->orders[]=$criteria->order;
$this->groups[]=$criteria->group;
$this->havings[]=$criteria->having;
$this->limit=$criteria->limit;
$this->offset=$criteria->offset;
$this->params=$criteria->params;
if(!$this->distinct && $criteria->distinct)
$this->distinct=true;
}
else
{
$this->selects[]=$joinElement->getPrimaryKeySelect();
$this->joins[]=$joinElement->getTableNameWithAlias();
$this->conditions[]=$joinElement->getPrimaryKeyRange();
}
$this->elements[$joinElement->id]=true;
}
Конструктор.
createCommand() метод
public CDbCommand createCommand(CDbCommandBuilder $builder) | ||
| $builder | CDbCommandBuilder | строитель команд |
| {return} | CDbCommand | экземпляр команды базы данных, представляющий оператор SQL |
Исходный код: framework/db/ar/CActiveFinder.php#1338 (показать)
public function createCommand($builder)
{
$sql=($this->distinct ? 'SELECT DISTINCT ':'SELECT ') . implode(', ',$this->selects);
$sql.=' FROM ' . implode(' ',array_unique($this->joins));
$conditions=array();
foreach($this->conditions as $condition)
if($condition!=='')
$conditions[]=$condition;
if($conditions!==array())
$sql.=' WHERE (' . implode(') AND (',$conditions).')';
$groups=array();
foreach($this->groups as $group)
if($group!=='')
$groups[]=$group;
if($groups!==array())
$sql.=' GROUP BY ' . implode(', ',$groups);
$havings=array();
foreach($this->havings as $having)
if($having!=='')
$havings[]=$having;
if($havings!==array())
$sql.=' HAVING (' . implode(') AND (',$havings).')';
$orders=array();
foreach($this->orders as $order)
if($order!=='')
$orders[]=$order;
if($orders!==array())
$sql.=' ORDER BY ' . implode(', ',$orders);
$sql=$builder->applyLimit($sql,$this->limit,$this->offset);
$command=$builder->getDbConnection()->createCommand($sql);
$builder->bindValues($command,$this->params);
return $command;
}
Создаёт оператор SQL.
join() метод
public void join(CJoinElement $element) | ||
| $element | CJoinElement | элемент, подлежащий объединению |
Исходный код: framework/db/ar/CActiveFinder.php#1310 (показать)
public function join($element)
{
if($element->slave!==null)
$this->join($element->slave);
if(!empty($element->relation->select))
$this->selects[]=$element->getColumnSelect($element->relation->select);
$this->conditions[]=$element->relation->condition;
$this->orders[]=$element->relation->order;
$this->joins[]=$element->getJoinCondition();
$this->joins[]=$element->relation->join;
$this->groups[]=$element->relation->group;
$this->havings[]=$element->relation->having;
if(is_array($element->relation->params))
{
if(is_array($this->params))
$this->params=array_merge($this->params,$element->relation->params);
else
$this->params=$element->relation->params;
}
$this->elements[$element->id]=true;
}
Объединяет с другим элементом объединения
© 2008–2017 by Yii Software LLC
Licensed under the three clause BSD license.
http://www.yiiframework.com/doc/api/1.1/CJoinQuery