CDBCriteria FROM

Hello All!

help me! i can’t understand how to write this sql with CDBCriteria


SELECT s.* FROM (SELECT @d1:='01.02.2012' p1, @d2:='29.02.2012' p2) par, v_stats s

i looked at class reference but saw nothing about FROM(((

-=upd=-

so i think it is not possible… so how can i form dataprovider from dbcommand?


$sqlComm=Yii::app()->db->createCommand();

$sqlComm->select('s,*');

$sqlComm->from("(SELECT @d1:='".$_POST['from-date-k']."' p1, @d2:='".$_POST['to-date-k']."' p2) par, v_stats s");

or may be how can i convert it to dbcriteria to pass to dataprovider constructor?

the issue is that i have to show this data in cgridview, but it accepts only dataprovider(

I think you can use CSqlDataProvider

You’ll have to provide a totalItemCount if you want to use pagination (i.e, issue a select count(*) before)

To clarify your DbCriteria question: A DB criteria in Yii is not specific to any AR. You can in theory build a criteria and use it for different ActiveRecords. That’s why there’s no FROM. It will get added by the framework as soon as you perform a AR query on a ActiveRecord.