CDbQueryBuilder text is not updated after changing select




  $command = Yii::app()->db->createCommand()				

    ->select('COUNT(*)')    

    ->from('foo');

		

  $count= $command->queryScalar();		

  $command->setSelect('foo.id');


  $text = $command->text; //Text is still 'COUNT(*) FROM foo



In CDbCommand you will find, which explains this behavior:




	public function getText()

	{

		if($this->_text=='' && !empty($this->_query))

			$this->setText($this->buildQuery($this->_query));

		return $this->_text;

	}



Workaround:




$command->text = '';

$text = $command->text; //Text is updated with latest select statement



Shouldn’t this be changed in Yii core?

Check the documentation - http://www.yiiframework.com/doc/guide/1.1/en/database.query-builder#building-multiple-queries

Thanks, but reset() is not really an option for me, because the point of just changing the select statement is to keep all other query settings.