Limit in CSqlDataProvider

Can we limit the query record in CSqlDataProvider?

But in CActiveDataProvider() we can control by







$dataProvider= new CActiveDataProvider('module_name',

                                    array('criteria' =>

                                        array('condition' => 'id = ' . $model->id,

                                              'order' => ' ',

                                              'limit' => 20,

                                         	),

                               	'pagination' => false 	


                                     	)

                                  );




Any hint??

I am not sure if I understand your problem, but I think that you need to understand the difference between the 2 dataProvider classes you mentioned.

If you use a CACTIVEDataProvider you basically make use of CActiveRecord in combination with CDbCriteria objects (as seen the example you gave above). These classes (AR and CDbCriteria) create the SQL for you so you don’t have to think about the low-level statements. The result is an array of CActiveRecord instances.

If you use CSQLDataProvider you basically set the SQL statement by yourself and don’t rely on any AR or CDbCriteria “magic”. The result is an array of rows, not ActiveRecord instances.

So to sum this up you would have to add the limit statement to your sql statement (simplified):


$sql='SELECT * FROM modeltable where id='.$model->id.' LIMIT 20'; 

$dataProvider=new CSqlDataProvider($sql);



I have tried your solution but with no luck.