From b700f7129edb76388dff76d16699bf5ba5c9bdc8 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Tue, 5 Nov 2013 14:52:12 -0500 Subject: [PATCH] fixes #1142: exposes Command::params. --- framework/yii/db/Command.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/framework/yii/db/Command.php b/framework/yii/db/Command.php index e1f15b8..671558a 100644 --- a/framework/yii/db/Command.php +++ b/framework/yii/db/Command.php @@ -67,13 +67,15 @@ class Command extends \yii\base\Component */ public $fetchMode = \PDO::FETCH_ASSOC; /** - * @var string the SQL statement that this command represents + * @var array the parameters (name => value) that are bound to the current PDO statement. + * This property is maintained by methods such as [[bindValue()]]. + * Do not modify it directly. */ - private $_sql; + public $params = []; /** - * @var array the parameter log information (name => value) + * @var string the SQL statement that this command represents */ - private $_params = []; + private $_sql; /** * Returns the SQL statement for this command. @@ -95,7 +97,7 @@ class Command extends \yii\base\Component if ($sql !== $this->_sql) { $this->cancel(); $this->_sql = $this->db->quoteSql($sql); - $this->_params = []; + $this->params = []; } return $this; } @@ -108,11 +110,11 @@ class Command extends \yii\base\Component */ public function getRawSql() { - if (empty($this->_params)) { + if (empty($this->params)) { return $this->_sql; } else { $params = []; - foreach ($this->_params as $name => $value) { + foreach ($this->params as $name => $value) { if (is_string($value)) { $params[$name] = $this->db->quoteValue($value); } elseif ($value === null) { @@ -190,7 +192,7 @@ class Command extends \yii\base\Component } else { $this->pdoStatement->bindParam($name, $value, $dataType, $length, $driverOptions); } - $this->_params[$name] =& $value; + $this->params[$name] =& $value; return $this; } @@ -212,7 +214,7 @@ class Command extends \yii\base\Component $dataType = $this->db->getSchema()->getPdoType($value); } $this->pdoStatement->bindValue($name, $value, $dataType); - $this->_params[$name] = $value; + $this->params[$name] = $value; return $this; } @@ -239,7 +241,7 @@ class Command extends \yii\base\Component $type = $this->db->getSchema()->getPdoType($value); } $this->pdoStatement->bindValue($name, $value, $type); - $this->_params[$name] = $value; + $this->params[$name] = $value; } } return $this;