Fixed excess escaping in Command::batchInsert() (#13236)

This commit is contained in:
Dmitry Naumenko
2017-10-23 22:43:39 +03:00
committed by GitHub
parent e65451991d
commit 7e7faeebd1
7 changed files with 128 additions and 6 deletions

View File

@ -137,19 +137,43 @@ class Command extends Component
}
/**
* Specifies the SQL statement to be executed.
* The previous SQL execution (if any) will be cancelled, and [[params]] will be cleared as well.
* Specifies the SQL statement to be executed. The SQL statement will be quoted using [[Connection::quoteSql()]].
* The previous SQL (if any) will be discarded, and [[params]] will be cleared as well. See [[reset()]]
* for details.
*
* @param string $sql the SQL statement to be set.
* @return $this this command instance
* @see reset()
* @see cancel()
*/
public function setSql($sql)
{
if ($sql !== $this->_sql) {
$this->cancel();
$this->reset();
$this->_sql = $this->db->quoteSql($sql);
$this->_pendingParams = [];
$this->params = [];
$this->_refreshTableName = null;
}
return $this;
}
/**
* Specifies the SQL statement to be executed. The SQL statement will not be modified in any way.
* The previous SQL (if any) will be discarded, and [[params]] will be cleared as well. See [[reset()]]
* for details.
*
* @param string $sql the SQL statement to be set.
* @return $this this command instance
* @since 2.0.13
* @see reset()
* @see cancel()
*/
public function setRawSql($sql)
{
if ($sql !== $this->_sql) {
$this->cancel();
$this->reset();
$this->_sql = $sql;
}
return $this;
@ -461,9 +485,16 @@ class Command extends Component
*/
public function batchInsert($table, $columns, $rows)
{
$table = $this->db->quoteSql($table);
$columns = array_map(function ($column) {
return $this->db->quoteSql($column);
}, $columns);
$sql = $this->db->getQueryBuilder()->batchInsert($table, $columns, $rows);
return $this->setSql($sql);
$this->setRawSql($sql);
return $this;
}
/**
@ -1081,4 +1112,17 @@ class Command extends Component
$this->db->getSchema()->refreshTableSchema($this->_refreshTableName);
}
}
/**
* Resets [[sql]] and [[params]] properties.
*
* @since 2.0.13
*/
protected function reset()
{
$this->_sql = null;
$this->_pendingParams = [];
$this->params = [];
$this->_refreshTableName = null;
}
}