Skip to content
Browse files

Merge pull request #1500 branch 'CSqlDataProvider-support-CDbCommand'…

… of https://github.com/slavcodev/fork-yii into slavcodev-CSqlDataProvider-support-CDbCommand

* 'CSqlDataProvider-support-CDbCommand' of https://github.com/slavcodev/fork-yii:
  CHAGELOG fix
  CHANGELOG
  CSqlDataProvider now supports CDbCommand in constructor

Conflicts:
	CHANGELOG
  • Loading branch information...
2 parents e65956d + 47c9ddb commit e8a93ac5cc8ef7fa490af7244baf39050da04b2f @cebe cebe committed Oct 10, 2012
Showing with 14 additions and 10 deletions.
  1. +1 −0 CHANGELOG
  2. +13 −10 framework/web/CSqlDataProvider.php
View
1 CHANGELOG
@@ -48,6 +48,7 @@ Version 1.1.13 work in progress
- Enh #1396: Added 'text/csv' mime-type for the 'csv' file extension in utils/mimeTypes.php (effectively used by e.g. CHttpRequest::sendFile()) (rawtaz)
- Enh #1426: Behaviors are now affecting memory consumption significantly less (slavcodev, creocoder, Qiang, samdark)
- Enh #1443: Added CHttpRequest::getRawBody() that allows reading RAW HTTP request body multiple times (itamar82, resurtm, samdark)
+- Enh #1500: CSqlDataProvider now supports CDbCommand in constructor (slavcodev)
- Enh #1518: Allow to configure CHtml::$closeSingleTags and CHtml::$renderSpecialAttributesValue. Useful for HTML5 code (creocoder)
- Enh #1531: CArrayDataProvider is now able to sort cutted array, where sorting column is not available in every entry (Yiivgeny)
- Enh: Fixed the check for ajaxUpdate false value in jquery.yiilistview.js as that never happens (mdomba)
View
23 framework/web/CSqlDataProvider.php
@@ -43,7 +43,7 @@ class CSqlDataProvider extends CDataProvider
*/
public $db;
/**
- * @var string the SQL statement to be used for fetching data rows.
+ * @var string|CDbCommand the SQL statement to be used for fetching data rows.
*/
public $sql;
/**
@@ -57,7 +57,7 @@ class CSqlDataProvider extends CDataProvider
/**
* Constructor.
- * @param string $sql the SQL statement to be used for fetching data rows.
+ * @param string|CDbCommand $sql the SQL statement to be used for fetching data rows.
* @param array $config configuration (name=>value) to be applied as the initial property values of this class.
*/
public function __construct($sql,$config=array())
@@ -73,19 +73,23 @@ public function __construct($sql,$config=array())
*/
protected function fetchData()
{
- $sql=$this->sql;
- $db=$this->db===null ? Yii::app()->db : $this->db;
- $db->active=true;
+ if(!$this->sql instanceof CDbCommand)
+ {
+ $db=$this->db===null ? Yii::app()->db : $this->db;
+ $command=$db->createCommand($this->sql);
+ }
+ else
+ $command=clone $this->sql;
if(($sort=$this->getSort())!==false)
{
$order=$sort->getOrderBy();
if(!empty($order))
{
- if(preg_match('/\s+order\s+by\s+[\w\s,]+$/i',$sql))
- $sql.=', '.$order;
+ if(preg_match('/\s+order\s+by\s+[\w\s,]+$/i',$command->text))
+ $command->text.=', '.$order;
else
- $sql.=' ORDER BY '.$order;
+ $command->text.=' ORDER BY '.$order;
}
}
@@ -94,10 +98,9 @@ protected function fetchData()
$pagination->setItemCount($this->getTotalItemCount());
$limit=$pagination->getLimit();
$offset=$pagination->getOffset();
- $sql=$db->getCommandBuilder()->applyLimit($sql,$limit,$offset);
+ $command->text=$command->getConnection()->getCommandBuilder()->applyLimit($command->text,$limit,$offset);
}
- $command=$db->createCommand($sql);
foreach($this->params as $name=>$value)
$command->bindValue($name,$value);

0 comments on commit e8a93ac

Please sign in to comment.
Something went wrong with that request. Please try again.