$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?