CJoinQuery
鍖 | system.db.ar |
---|---|
缁ф壙 | class CJoinQuery |
婧愯嚜 | 1.0 |
鐗堟湰 | $Id: CActiveFinder.php 3562 2012-02-13 01:27:06Z qiang.xue $ |
婧愮爜 | framework/db/ar/CActiveFinder.php |
CJoinQuery浠h〃鐫涓涓叧鑱旀煡璇 SQL 璇彞銆
鍏叡灞炴
灞炴 | 绫诲瀷 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|---|
conditions | array | WHERE 瀛愬彞鍒楄〃 | CJoinQuery |
distinct | boolean | 鏄惁瑕侀夋嫨涓嶅悓鐨勭粨鏋滈泦 | CJoinQuery |
elements | array | 杩炴帴鍏冪礌鐨処D鍒楄〃(id=>true) | CJoinQuery |
groups | array | GROUP BY 瀛愬彞鍒楄〃 | CJoinQuery |
havings | array | HAVING瀛愬彞鍒楄〃 | CJoinQuery |
joins | array | 鍏宠仈璇彞鍒楄〃 | CJoinQuery |
limit | integer | 琛宭imit | CJoinQuery |
offset | integer | 琛屽亸绉 | CJoinQuery |
orders | array | ORDER BY 瀛愬彞鍒楄〃 | CJoinQuery |
params | array | 鏌ヨ鍙傛暟鐨勫垪琛 | CJoinQuery |
selects | array | 瀛楁閫夋嫨鍒楄〃 | CJoinQuery |
鍏叡鏂规硶
鏂规硶 | 鎻忚堪 | 瀹氫箟鍦 |
---|---|---|
__construct() | 鏋勯犲嚱鏁般 | CJoinQuery |
createCommand() | 鍒涘缓涓鏉QL璇彞銆 | CJoinQuery |
join() | 杩炴帴鍒板彟澶栦竴涓叧鑱旀煡璇㈣妭鐐瑰厓绱犮 | CJoinQuery |
灞炴ц缁
conditions
灞炴
public array $conditions;
WHERE 瀛愬彞鍒楄〃
distinct
灞炴
public boolean $distinct;
鏄惁瑕侀夋嫨涓嶅悓鐨勭粨鏋滈泦
elements
灞炴
public array $elements;
杩炴帴鍏冪礌鐨処D鍒楄〃(id=>true)
groups
灞炴
public array $groups;
GROUP BY 瀛愬彞鍒楄〃
havings
灞炴
public array $havings;
HAVING瀛愬彞鍒楄〃
joins
灞炴
public array $joins;
鍏宠仈璇彞鍒楄〃
limit
灞炴
public integer $limit;
琛宭imit
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#1265 (鏄剧ず)
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 string createCommand(CDbCommandBuilder $builder)
| ||
$builder | CDbCommandBuilder | 鍛戒护鐢熸垚鍣 |
{return} | string | SQL璇彞 |
婧愮爜锛 framework/db/ar/CActiveFinder.php#1323 (鏄剧ず)
public function createCommand($builder)
{
$sql=($this->distinct ? 'SELECT DISTINCT ':'SELECT ') . implode(', ',$this->selects);
$sql.=' FROM ' . implode(' ',$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;
}
鍒涘缓涓鏉QL璇彞銆
join()
鏂规硶
public void join(CJoinElement $element)
| ||
$element | CJoinElement | 绛夊緟鑱旀帴鐨勫厓绱 |
婧愮爜锛 framework/db/ar/CActiveFinder.php#1295 (鏄剧ず)
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;
}
杩炴帴鍒板彟澶栦竴涓叧鑱旀煡璇㈣妭鐐瑰厓绱犮