|
|
|
@ -60,6 +60,47 @@ 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 $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) |
|
|
|
|
{ |
|
|
|
|
return "sp_rename '$table', '$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 $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) |
|
|
|
|
{ |
|
|
|
|
return "sp_rename '$table.$name', '$newName', 'COLUMN'"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Builds a SQL statement for changing the definition of a column. |
|
|
|
|
* @param string $table the table whose column is to be changed. The table name will be properly quoted by the method. |
|
|
|
|
* @param string $column the name of the column to be changed. The name will be properly quoted by the method. |
|
|
|
|
* @param string $type the new column type. The {@link getColumnType} method will be invoked to convert abstract column type (if any) |
|
|
|
|
* into the physical one. Anything that is not recognized as abstract type will be kept in the generated SQL. |
|
|
|
|
* For example, 'string' will be turned into 'varchar(255)', while 'string not null' will become 'varchar(255) not null'. |
|
|
|
|
* @return string the SQL statement for changing the definition of a column. |
|
|
|
|
*/ |
|
|
|
|
public function alterColumn($table, $column, $type) |
|
|
|
|
{ |
|
|
|
|
$type=$this->getColumnType($type); |
|
|
|
|
$sql='ALTER TABLE ' . $this->db->quoteTableName($table) . ' ALTER COLUMN ' |
|
|
|
|
. $this->db->quoteColumnName($column) . ' ' |
|
|
|
|
. $this->getColumnType($type); |
|
|
|
|
return $sql; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Builds a SQL statement for enabling or disabling integrity check. |
|
|
|
|
* @param boolean $check whether to turn on or off the integrity check. |
|
|
|
|
* @param string $schema the schema of the tables. Defaults to empty string, meaning the current or default schema. |
|
|
|
|