CDbCommand::createCommand() returns zero affected rows inside migration

This code works just fine (all database items updated as expected):


foreach($idMap as $menuId=>$pageId)

{

	$sql = "UPDATE menus_items SET link = '/content/show?id=".$pageId."' WHERE id = ".$menuId."; ";


	$affectedRows = Yii::app()->db->createCommand($sql)->execute();


	echo $affectedRows." affected rows\n";

}

But it prints 0 affected rows for each executed query. Why?

The same effect is, when executing many rows affecting statements in one SQL query:


$sql = '';


foreach($idMap as $menuId=>$pageId)

{

	$sql .= "UPDATE menus_items SET link = '/content/show?id=".$pageId."' WHERE id = ".$menuId."; ";

}


$affectedRows = Yii::app()->db->createCommand($sql)->execute();

echo $affectedRows." affected rows\n";

What am I missing? Docs says, that CDbCommand::execute should return number of rows affected by the execution. Does this feature work, when used inside migration?

Answered on Stack Overflow.