framework/db/schema/CDbCommandBuilder.php
public function createColumnCriteria($table,$columns,$condition='',$params=array(),$prefix=null)
	{
		$this->ensureTable($table);
		$criteria=$this->createCriteria($condition,$params);
		if($criteria->alias!='')
			$prefix=$this->_schema->quoteTableName($criteria->alias).'.';
		$bindByPosition=isset($criteria->params[0]);
		$conditions=array();
		$values=array();
		$i=0;
		if($prefix===null)
			$prefix=$table->rawName.'.';
		foreach($columns as $name=>$value)
		{
			if(($column=$table->getColumn($name))!==null)
			{
				if(is_array($value))
					$conditions[]=$this->createInCondition($table,$name,$value,$prefix);
				elseif($value!==null)
				{
					if($bindByPosition)
					{
						$conditions[]=$prefix.$column->rawName.'=?';
						$values[]=$value;
					}
					else
					{
						$conditions[]=$prefix.$column->rawName.'='.self::PARAM_PREFIX.$i;
						$values[self::PARAM_PREFIX.$i]=$value;
						$i++;
					}
				}
				else
					$conditions[]=$prefix.$column->rawName.' IS NULL';
			}
			else
				throw new CDbException(Yii::t('yii','Table "{table}" does not have a column named "{column}".',
					array('{table}'=>$table->name,'{column}'=>$name)));
		}
		$criteria->params=array_merge($values,$criteria->params);
		if(isset($conditions[0]))
		{
			if($criteria->condition!='')
				$criteria->condition=implode(' AND ',$conditions).' AND ('.$criteria->condition.')';
			else
				$criteria->condition=implode(' AND ',$conditions);
		}
		return $criteria;
	}
public function createColumnCriteria($table,$columns,$condition='',$params=array(),$prefix=null)
	{
		$this->ensureTable($table);
		$criteria=$this->createCriteria($condition,$params);
		if($criteria->alias!='')
			$prefix=$this->_schema->quoteTableName($criteria->alias).'.';
		$bindByPosition=isset($criteria->params[0]);
		$conditions=array();
		$values=array();
		$i=0;
		if($prefix===null)
			$prefix=$table->rawName.'.';
		foreach($columns as $name=>$value)
		{
			if(($column=$table->getColumn($name))!==null)
			{
				if(is_array($value))
					$conditions[]=$this->createInCondition($table,$name,$value,$prefix);
				elseif($value!==null)
				{
					if($bindByPosition)
					{
						$conditions[]=$prefix.$column->rawName.'=?';
						$values[]=$value;
					}
					else
					{
						$conditions[]=$prefix.$column->rawName.'='.self::PARAM_PREFIX.$i;
						$values[self::PARAM_PREFIX.$i]=$value;
						$i++;
					}
				}
				else
					$conditions[]=$prefix.$column->rawName.' IS NULL';
			}
			else
				throw new CDbException(Yii::t('yii','Table "{table}" does not have a column named "{column}".',
					array('{table}'=>$table->name,'{column}'=>$name)));
		}
		$criteria->params=array_merge($values,$criteria->params);
		if(isset($conditions[0]))
		{
			if($criteria->condition!='')
				$criteria->condition=implode(' AND ',$conditions).' AND ('.$criteria->condition.')';
			else
				$criteria->condition=implode(' AND ',$conditions);
		}
		return $criteria;
	}
public function createColumnCriteria ( $ table , $ columns , $ condition = '' , $ params = array ( ) , $ prefix = null ) { $ this -> ensureTable ( $ table ) ; $ criteria = $ this -> createCriteria ( $ condition , $ params ) ; if ( $ criteria -> alias != '' ) $ prefix = $ this -> _schema -> quoteTableName ( $ criteria -> alias ) . '.' ; $ bindByPosition = isset ( $ criteria -> params [ 0 ] ) ; $ conditions = array ( ) ; $ values = array ( ) ; $ i = 0 ; if ( $ prefix === null ) $ prefix = $ table -> rawName . '.' ; foreach ( $ columns as $ name => $ value ) { if ( ( $ column = $ table -> getColumn ( $ name ) ) !== null ) { if ( is_array ( $ value ) ) $ conditions [ ] = $ this -> createInCondition ( $ table , $ name , $ value , $ prefix ) ; elseif ( $ value !== null ) { if ( $ bindByPosition ) { $ conditions [ ] = $ prefix . $ column -> rawName . '=?' ; $ values [ ] = $ value ; } else { $ conditions [ ] = $ prefix . $ column -> rawName . '=' . self :: PARAM_PREFIX . $ i ; $ values [ self :: PARAM_PREFIX . $ i ] = $ value ; $ i ++ ; } } else $ conditions [ ] = $ prefix . $ column -> rawName . ' IS NULL' ; } else throw new CDbException ( Yii :: t ( 'yii' , 'Table "{table}" does not have a column named "{column}".' , array ( '{table}' => $ table -> name , '{column}' => $ name ) ) ) ; } $ criteria -> params = array_merge ( $ values , $ criteria -> params ) ; if ( isset ( $ conditions [ 0 ] ) ) { if ( $ criteria -> condition != '' ) $ criteria -> condition = implode ( ' AND ' , $ conditions ) . ' AND (' . $ criteria -> condition . ')' ; else $ criteria -> condition = implode ( ' AND ' , $ conditions ) ; } return $ criteria ; }
Creates a query criteria with the specified column values.
@param mixed $table the table schema ({@link CDbTableSchema}) or the table name (string).
@param array $columns column values that should be matched in the query (name=>value)
@param mixed $condition query condition or criteria.
If a string, it is treated as query condition;
If an array, it is treated as the initial values for constructing a {@link CDbCriteria};
Otherwise, it should be an instance of {@link CDbCriteria}.
@param array $params parameters to be bound to an SQL statement.
This is only used when the third parameter is a string (query condition).
In other cases, please use {@link CDbCriteria::params} to set parameters.
@param string $prefix column prefix (ended with dot). If null, it will be the table name
@throws CDbException if specified column is not found in given table
@return CDbCriteria the created query criteria
Creates a query criteria with the specified column values .