Yii Framework v1.1.10 绫诲弬鑰

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;
}

杩炴帴鍒板彟澶栦竴涓叧鑱旀煡璇㈣妭鐐瑰厓绱犮

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.