mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-17 23:09:10 +08:00
fixes #1142: exposes Command::params.
This commit is contained in:
@@ -66,14 +66,16 @@ class Command extends \yii\base\Component
|
|||||||
* @see http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
|
* @see http://www.php.net/manual/en/function.PDOStatement-setFetchMode.php
|
||||||
*/
|
*/
|
||||||
public $fetchMode = \PDO::FETCH_ASSOC;
|
public $fetchMode = \PDO::FETCH_ASSOC;
|
||||||
|
/**
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
|
public $params = [];
|
||||||
/**
|
/**
|
||||||
* @var string the SQL statement that this command represents
|
* @var string the SQL statement that this command represents
|
||||||
*/
|
*/
|
||||||
private $_sql;
|
private $_sql;
|
||||||
/**
|
|
||||||
* @var array the parameter log information (name => value)
|
|
||||||
*/
|
|
||||||
private $_params = [];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the SQL statement for this command.
|
* Returns the SQL statement for this command.
|
||||||
@@ -95,7 +97,7 @@ class Command extends \yii\base\Component
|
|||||||
if ($sql !== $this->_sql) {
|
if ($sql !== $this->_sql) {
|
||||||
$this->cancel();
|
$this->cancel();
|
||||||
$this->_sql = $this->db->quoteSql($sql);
|
$this->_sql = $this->db->quoteSql($sql);
|
||||||
$this->_params = [];
|
$this->params = [];
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@@ -108,11 +110,11 @@ class Command extends \yii\base\Component
|
|||||||
*/
|
*/
|
||||||
public function getRawSql()
|
public function getRawSql()
|
||||||
{
|
{
|
||||||
if (empty($this->_params)) {
|
if (empty($this->params)) {
|
||||||
return $this->_sql;
|
return $this->_sql;
|
||||||
} else {
|
} else {
|
||||||
$params = [];
|
$params = [];
|
||||||
foreach ($this->_params as $name => $value) {
|
foreach ($this->params as $name => $value) {
|
||||||
if (is_string($value)) {
|
if (is_string($value)) {
|
||||||
$params[$name] = $this->db->quoteValue($value);
|
$params[$name] = $this->db->quoteValue($value);
|
||||||
} elseif ($value === null) {
|
} elseif ($value === null) {
|
||||||
@@ -190,7 +192,7 @@ class Command extends \yii\base\Component
|
|||||||
} else {
|
} else {
|
||||||
$this->pdoStatement->bindParam($name, $value, $dataType, $length, $driverOptions);
|
$this->pdoStatement->bindParam($name, $value, $dataType, $length, $driverOptions);
|
||||||
}
|
}
|
||||||
$this->_params[$name] =& $value;
|
$this->params[$name] =& $value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +214,7 @@ class Command extends \yii\base\Component
|
|||||||
$dataType = $this->db->getSchema()->getPdoType($value);
|
$dataType = $this->db->getSchema()->getPdoType($value);
|
||||||
}
|
}
|
||||||
$this->pdoStatement->bindValue($name, $value, $dataType);
|
$this->pdoStatement->bindValue($name, $value, $dataType);
|
||||||
$this->_params[$name] = $value;
|
$this->params[$name] = $value;
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,7 +241,7 @@ class Command extends \yii\base\Component
|
|||||||
$type = $this->db->getSchema()->getPdoType($value);
|
$type = $this->db->getSchema()->getPdoType($value);
|
||||||
}
|
}
|
||||||
$this->pdoStatement->bindValue($name, $value, $type);
|
$this->pdoStatement->bindValue($name, $value, $type);
|
||||||
$this->_params[$name] = $value;
|
$this->params[$name] = $value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this;
|
return $this;
|
||||||
|
|||||||
Reference in New Issue
Block a user