Upgrading From 1.1.13 To 1.1.14 Invalid Bound Parameter Number Error

Please see http://www.yiiframework.com/forum/index.php/topic/51023-upgrading-from-1113-to-1114-invalid-bound-parameter-number-error/ for further description.

I have a relation which worked perfectly in 1.1.13 and is now broken in 1.1.14 with CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens.

It seems to me that the query builder has issues with bound parameters within an ‘order’ statement - ie. it only counts the number of bound variables within the SQL statement (ignoring the ones in the ORDER BY clause), and then the passed number of parameters does not match the ones in the query (but it would match the overall number of bound variables in the query + order clause).

To replicate:

You have 2 relations in a model (MODEL1):

‘test’ => array(self::HAS_MANY, ‘MODEL2’, ‘index_id’, ‘order’ => ‘some_attribute = :arg_1, some_attribute = :arg_2’, ‘params’ => array(’:arg_1’ => 1, ‘:arg_2’ => 2)),

‘test2’ => array(self::HAS_MANY, ‘MODEL3’, 'index_id2, ‘through’ => ‘test’)

When you call the test2 relation on a MODEL1 object, you get the error: Invalid parameter number: number of bound variables does not match number of tokens.

This has to do with the variables in the order statemet not being counted, and then ‘params’ have more varables than needed.

This worked OK prior to Yii 1.1.14.