framework/db/ar/CActiveFinder.php
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;
	}
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;
	}
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 ; }
Creates the SQL statement.
@param CDbCommandBuilder $builder the command builder
@return CDbCommand DB command instance representing the SQL statement
Creates the SQL statement .