Hi guys,
Have a question about CdbCriteria. I am trying to execute this query:
select * from logs_smtpserver where message LIKE ‘Connection from%’ GROUP BY message,class,priority,log_date ORDER BY log_date DESC;
Of course I use Yii Active record, it looks like this:
$name = 'Connection from';
$criteria=new CDbCriteria;
$criteria->condition = "message LIKE :name";
$criteria->params = array(":name"=>"$name%");
$criteria->group = 'message,class,log_date,priority';
$criteria->order = 'log_date DESC';
$pages=new CPagination(logs::model()->count($criteria));
$pages->pageSize=self::PAGE_SIZE;
$pages->applyLimit($criteria);
$models=logs::model()->findAll($criteria);
It seems it’s working, Yii produces this query(found it in the application logs):
2010/08/23 13:23:50 [trace] [system.db.CDbCommand] Querying SQL: SELECT * FROM "logs_smtpserver" WHERE message LIKE :name GROUP BY message,class,log_date,priority
ORDER BY log_date DESC LIMIT 35. Bind with parameter :name=‘Connection from%’
But problem is it seems that CPagination is getting broken after this query and not showing me any pagination:
I’ve tried to print out $criteria variable,like this print_r($criteria);
And it looks like this:
CDbCriteria Object ( [select] => * [distinct] => [condition] => message LIKE :name [params] => Array ( [:name] => Connection from% ) [limit] => -1 [offset] => -1
[order] => log_date DESC [group] => message,class,log_date,priority [join] => [having] => )
limit and offset are -1 which is weird.
Any help,maybe it is a bug,or something wrong with my query,but the only thing which I am trying is to use ORDER BY.
I use PotgreSQL as a DB backend.