Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Fix CVarDumper highlight "\" #1498

Closed
wants to merge 5 commits into
from
View
@@ -53,8 +53,12 @@ Version 1.1.13 work in progress
- Enh: Added CChainedLogFilter class to allow adding multiple filters to a logroute (cebe)
- Enh: Allow CDataProvider to use custom pagination and sorter (creocoder)
- Enh: Value of the CHtml::activeTextArea() can now be set through $htmlOptions['value'] (resurtm)
+<<<<<<< HEAD
+- Enh #1466: CSqlDataProvider now supports CDbCommand in constructor (slavcodev)
+=======
- Enh: Allow to customize CHtml::error() container tag (creocoder)
- Enh: CModule::setComponents() now can reconfigure already loaded components (creocoder)
+>>>>>>> e2fa2201ec86f8e197d560deba0b3d23340ef2a7
- Chg: MSSQL unit tests updated and actualized, added SQLSRV driver support (resurtm)
- Chg: Added Oracle unit tests (resurtm)
- Chg: Updated CHttpCacheFilter to use dates as specified by RFC 1123 (bramp)
@@ -59,7 +59,7 @@ public static function dumpAsString($var,$depth=10,$highlight=false)
self::dumpInternal($var,0);
if($highlight)
{
- $result=highlight_string("<?php\n".self::$_output,true);
+ $result=str_replace('\\\\','\\',highlight_string("<?php\n".str_replace('\\','\\\\',self::$_output),true));
self::$_output=preg_replace('/&lt;\\?php<br \\/>/','',$result,1);
}
return self::$_output;
@@ -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,24 @@ 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)
+ $command=clone $this->sql;
+ else
+ {
+ $db=$this->db===null ? Yii::app()->db : $this->db;
+ $db->active=true;
+ $command=$db->createCommand($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 +99,9 @@ protected function fetchData()
$pagination->setItemCount($this->getTotalItemCount());
$limit=$pagination->getLimit();
$offset=$pagination->getOffset();
- $sql=$db->getCommandBuilder()->applyLimit($sql,$limit,$offset);
+ $command->text=$db->getCommandBuilder()->applyLimit($command->text,$limit,$offset);
}
- $command=$db->createCommand($sql);
foreach($this->params as $name=>$value)
$command->bindValue($name,$value);