Fixes #9127, Fixes #9128: Fixed MSSQL QueryBuilder::renameColumn() and QueryBuilder::renameTable() escaping

This commit is contained in:
octicon-git-branch(16/)
octicon-tag(16/)
Sitawit Suteepohnwiroj
2015-07-16 15:53:35 +07:00
committed by Alexander Makarov
gitea-unlock(16/)
parent d94ccfe017
commit 5af6105ea7
octicon-diff(16/tw-mr-1) 2 changed files with 10 additions and 6 deletions

15
framework/db/mssql/QueryBuilder.php
View File

@@ -119,25 +119,28 @@ class QueryBuilder extends \yii\db\QueryBuilder
/**
* Builds a SQL statement for renaming a DB table.
* @param string $table the table to be renamed. The name will be properly quoted by the method.
* @param string $oldName the table to be renamed. The name will be properly quoted by the method.
* @param string $newName the new table name. The name will be properly quoted by the method.
* @return string the SQL statement for renaming a DB table.
*/
public function renameTable($table, $newName)
public function renameTable($oldName, $newName)
{
return "sp_rename '$table', '$newName'";
return 'sp_rename ' . $this->db->quoteTableName($oldName) . ', ' . $this->db->quoteTableName($newName);
}
/**
* Builds a SQL statement for renaming a column.
* @param string $table the table whose column is to be renamed. The name will be properly quoted by the method.
* @param string $name the old name of the column. The name will be properly quoted by the method.
* @param string $oldName the old name of the column. The name will be properly quoted by the method.
* @param string $newName the new name of the column. The name will be properly quoted by the method.
* @return string the SQL statement for renaming a DB column.
*/
public function renameColumn($table, $name, $newName)
public function renameColumn($table, $oldName, $newName)
{
return "sp_rename '$table.$name', '$newName', 'COLUMN'";
$table = $this->db->quoteTableName($table);
$oldName = $this->db->quoteColumnName($oldName);
$newName = $this->db->quoteColumnName($newName);
return "sp_rename '{$table}.{$oldName}', {$newName}, 'COLUMN'";
}
/**