A little debugging revealed that the snippet above generates the following sql:
SELECT * FROM `xpg_bucket` `t` WHERE bkt_user = :exp
and AFAIK only one CDbCommandBuilder::bindValue where ‘:exp’ is bound to unhex(:value). There is no parameter binding done for ‘:value’. This is happening in CDbCommandBuilder::createFindCommand. CDbCommandBuilder::createInsertCommand, on the other hand seems to take care of this condition.
CDbExpression’s documentation contains:
* CDbExpression is mainly used in {@link CActiveRecord} as attribute values.
* When inserting or updating a {@link CActiveRecord}, attribute values of
* type CDbExpression will be directly put into the corresponding SQL statement
* without escaping.
Does this mean CDbExpression is not meant to be used with CDbCriteria in findAll()? If yes, what is the alternative?
CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: no parameters were bound. The SQL statement executed was: SELECT * FROM `bucket` `t` WHERE user = unhex(:value)
Which also works. Oddly enough no CDbExpression is not involved at all.
Would you know what’s going on here? I was using my original approach because the same thing (‘bkt_user = unhex(:value)’) does not work in the insert context.