CDbCriteria column name don't use quote #2525

hiscaler opened this Issue May 31, 2013 · 3 comments


None yet
2 participants

Like follow code

 $criteria->addBetweenCondition('year_month', "{$this->year}01", "{$this->year}12");

will generate like this SQL

SELECT COUNT(*) FROM `www_monthly_reports` `t` WHERE (project_id=1) AND (year_month BETWEEN 201301 AND 201312)

because year_month is reserverd words in SQL, so go wrong when you execute it IN Yii 1.1.13


cebe commented May 31, 2013

This can not be fixed as CDbCriteria is not aware of the underlying database system it does not know how to quote, you have to do it yourself.
This problem has been fixed in Yii2 but can not be changed in 1.1

@cebe cebe closed this May 31, 2013

hiscaler commented Jun 1, 2013

CDbCriteria is not aware of the underlying database system? use quoteColumnName and quoteValue can't fixed this problem?


cebe commented Jun 1, 2013

You can use them youself, but CDbCriteria can not do that itself, because you can create criteria without needing a db connection:

$c = new CDbCriteria();

It is then not aware of any context, so it does not know where to call quoteColumnName.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment