Cdbcommand Dropcolumn() Strange Thing

Hey, I’ve recently found out that dropColumn method of CDbCommand returns the number of rows affected by the execution.

Well, dropping a column returns 0 affected rows every time since it’s not a row based query…

That return is actually a bit useless …

Is there a way to check if the command has actually been executed somehow ?

if(!Yii::app()->db->createCommand()->dropColumn(‘table_name’, ‘column_name’))

is obviously never going to work…

I’m afraid we can not check like that.

Plz, take a look at CDBCommand class




	/**

	 * Builds and executes a SQL statement for dropping a DB column.

	 * @param string $table the table whose column is to be dropped. The name will be properly quoted by the method.

	 * @param string $column the name of the column to be dropped. The name will be properly quoted by the method.

	 * @return integer number of rows affected by the execution.

	 * @since 1.1.6

	 */

	public function dropColumn($table, $column)

	{

		return $this->setText($this->getConnection()->getSchema()->dropColumn($table, $column))->execute();

	}



the command is alway executed, if it’s failed, it will throw CDbException

I thought that maybe a good thing is adding a try catch in there to see if it throws an exception …