diff --git a/framework/db/ColumnSchemaBuilder.php b/framework/db/ColumnSchemaBuilder.php index 510a20ba1b..5262b66993 100644 --- a/framework/db/ColumnSchemaBuilder.php +++ b/framework/db/ColumnSchemaBuilder.php @@ -103,7 +103,7 @@ class ColumnSchemaBuilder extends Object */ public $db; /** - * @var mixed comment value of the column. + * @var string comment value of the column. * @since 2.0.8 */ public $comment; @@ -168,7 +168,7 @@ class ColumnSchemaBuilder extends Object } /** - * Specify the comment for the column. + * Specifies the comment for column. * @param string $comment the comment * @return $this * @since 2.0.8 @@ -243,7 +243,7 @@ class ColumnSchemaBuilder extends Object { switch ($this->getTypeCategory()) { case self::CATEGORY_PK: - $format = '{type}{check}'; + $format = '{type}{check}{comment}'; break; default: $format = '{type}{length}{notnull}{unique}{default}{check}{comment}'; @@ -365,6 +365,16 @@ class ColumnSchemaBuilder extends Object return $this->categoryMap[$this->type]; } + /** + * Builds the comment specification for the column. + * @return string a string containing the COMMENT keyword and the comment itself + * @since 2.0.8 + */ + protected function buildCommentString() + { + return $this->comment !== null ? " COMMENT " . $this->db->quoteValue($this->comment) : ''; + } + /** * Returns the complete column definition from input format * @param string $format the format of the definition. @@ -381,20 +391,11 @@ class ColumnSchemaBuilder extends Object '{unique}' => $this->buildUniqueString(), '{default}' => $this->buildDefaultString(), '{check}' => $this->buildCheckString(), + '{comment}' => $this->buildCommentString(), '{pos}' => ($this->isFirst) ? $this->buildFirstString() : $this->buildAfterString(), - '{comment}' => $this->buildCommentString(), ]; return strtr($format, $placeholderValues); } - - /** - * Builds the comment specification for the column. - * @return string with comment. - */ - protected function buildCommentString() - { - return $this->comment !== null ? " COMMENT '{$this->comment}'" : ''; - } } diff --git a/framework/db/Command.php b/framework/db/Command.php index 10ab75677b..31a0dbd4d2 100644 --- a/framework/db/Command.php +++ b/framework/db/Command.php @@ -763,6 +763,7 @@ class Command extends Component * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. * @return $this the command object itself + * @since 2.0.8 */ public function addCommentOnColumn($table, $column, $comment) { @@ -777,6 +778,7 @@ class Command extends Component * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. * @return $this the command object itself + * @since 2.0.8 */ public function addCommentOnTable($table, $comment) { @@ -791,6 +793,7 @@ class Command extends Component * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. * @return $this the command object itself + * @since 2.0.8 */ public function dropCommentFromColumn($table, $column) { @@ -804,6 +807,7 @@ class Command extends Component * * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. * @return $this the command object itself + * @since 2.0.8 */ public function dropCommentFromTable($table) { diff --git a/framework/db/Migration.php b/framework/db/Migration.php index f840342b9f..d4fbd56dea 100644 --- a/framework/db/Migration.php +++ b/framework/db/Migration.php @@ -505,7 +505,7 @@ class Migration extends Component implements MigrationInterface { echo " > drop comment from column $column ..."; $time = microtime(true); - $this->db->createCommand()->dropCommentFromColumn($table, $column, $comment)->execute(); + $this->db->createCommand()->dropCommentFromColumn($table, $column)->execute(); echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n"; } @@ -520,7 +520,7 @@ class Migration extends Component implements MigrationInterface { echo " > drop comment from table $table ..."; $time = microtime(true); - $this->db->createCommand()->dropCommentFromTable($table, $comment)->execute(); + $this->db->createCommand()->dropCommentFromTable($table)->execute(); echo ' done (time: ' . sprintf('%.3f', microtime(true) - $time) . "s)\n"; } } diff --git a/framework/db/QueryBuilder.php b/framework/db/QueryBuilder.php index eb449c6842..57096e3bcc 100644 --- a/framework/db/QueryBuilder.php +++ b/framework/db/QueryBuilder.php @@ -574,10 +574,12 @@ class QueryBuilder extends \yii\base\Object * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself + * @return string the SQL statement for adding comment on column + * @since 2.0.8 */ public function addCommentOnColumn($table, $column, $comment) { + return 'COMMENT ON COLUMN ' . $this->db->quoteTableName($table) . '.' . $this->db->quoteColumnName($column) . ' IS ' . $this->db->quoteValue($comment); } @@ -586,7 +588,8 @@ class QueryBuilder extends \yii\base\Object * * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself + * @return string the SQL statement for adding comment on table + * @since 2.0.8 */ public function addCommentOnTable($table, $comment) { @@ -598,7 +601,8 @@ class QueryBuilder extends \yii\base\Object * * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @return $this the command object itself + * @return string the SQL statement for adding comment on column + * @since 2.0.8 */ public function dropCommentFromColumn($table, $column) { @@ -609,7 +613,8 @@ class QueryBuilder extends \yii\base\Object * Builds a SQL command for adding comment to table * * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @return $this the command object itself + * @return string the SQL statement for adding comment on column + * @since 2.0.8 */ public function dropCommentFromTable($table) { diff --git a/framework/db/cubrid/ColumnSchemaBuilder.php b/framework/db/cubrid/ColumnSchemaBuilder.php index 82d2cdf0e9..d9000271a2 100644 --- a/framework/db/cubrid/ColumnSchemaBuilder.php +++ b/framework/db/cubrid/ColumnSchemaBuilder.php @@ -50,13 +50,13 @@ class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder { switch ($this->getTypeCategory()) { case self::CATEGORY_PK: - $format = '{type}{check}{pos}'; + $format = '{type}{check}{pos}{comment}'; break; case self::CATEGORY_NUMERIC: - $format = '{type}{length}{unsigned}{notnull}{unique}{default}{check}{pos}'; + $format = '{type}{length}{unsigned}{notnull}{unique}{default}{check}{pos}{comment}'; break; default: - $format = '{type}{length}{notnull}{unique}{default}{check}{pos}'; + $format = '{type}{length}{notnull}{unique}{default}{check}{pos}{comment}'; } return $this->buildCompleteString($format); } diff --git a/framework/db/cubrid/QueryBuilder.php b/framework/db/cubrid/QueryBuilder.php index e475d6f35c..cbf21e5ac7 100644 --- a/framework/db/cubrid/QueryBuilder.php +++ b/framework/db/cubrid/QueryBuilder.php @@ -105,84 +105,42 @@ class QueryBuilder extends \yii\db\QueryBuilder } /** - * Builds a SQL command for adding comment to column - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself - * @since 2.0.8 + * @inheritdoc */ public function addCommentOnColumn($table, $column, $comment) { - $quotedTable = $this->db->quoteTableName($table); - $definition = $this->getColumnDefinition($quotedTable, $column); + $definition = $this->getColumnDefinition($table, $column); $definition = trim(preg_replace("/COMMENT '(.*?)'/i", '', $definition)); - return sprintf( - 'ALTER TABLE %s CHANGE %s %s%s COMMENT %s', - $quotedTable, - $this->db->quoteColumnName($column), - $this->db->quoteColumnName($column), - empty($definition) ? '' : ' ' . $definition, - $this->db->quoteValue($comment) - ); + + return 'ALTER TABLE ' . $this->db->quoteTableName($table) + . ' CHANGE ' . $this->db->quoteColumnName($column) + . ' ' . $this->db->quoteColumnName($column) + . (empty($definition) ? '' : ' ' . $definition) + . ' COMMENT ' . $this->db->quoteValue($comment); } /** - * Builds a SQL command for adding comment to table - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself - * @since 2.0.8 + * @inheritdoc */ public function addCommentOnTable($table, $comment) { - $quotedTable = $this->db->quoteTableName($table); - return sprintf( - 'ALTER TABLE %s COMMENT %s', - $quotedTable, - $this->db->quoteValue($comment) - ); + return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' COMMENT ' . $this->db->quoteValue($comment); } /** - * Builds a SQL command for adding comment to column - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @return $this the command object itself - * @since 2.0.8 + * @inheritdoc */ public function dropCommentFromColumn($table, $column) { - $quotedTable = $this->db->quoteTableName($table); - $definition = $this->getColumnDefinition($quotedTable, $column); - $definition = trim(preg_replace("/COMMENT '(.*?)'/i", '', $definition)); - return sprintf( - 'ALTER TABLE %s CHANGE %s %s%s COMMENT \'\'', - $quotedTable, - $this->db->quoteColumnName($column), - $this->db->quoteColumnName($column), - empty($definition) ? '' : ' ' . $definition - ); + return $this->addCommentOnColumn($table, $column, ''); } /** - * Builds a SQL command for adding comment to table - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @return $this the command object itself - * @since 2.0.8 + * @inheritdoc */ public function dropCommentFromTable($table) { - $quotedTable = $this->db->quoteTableName($table); - return sprintf( - "ALTER TABLE %s COMMENT ''", - $quotedTable, - empty($definition) ? '' : ' ' . $definition - ); + return $this->addCommentOnTable($table, ''); } @@ -197,7 +155,7 @@ class QueryBuilder extends \yii\db\QueryBuilder */ private function getColumnDefinition($table, $column) { - $row = $this->db->createCommand('SHOW CREATE TABLE ' . $table)->queryOne(); + $row = $this->db->createCommand('SHOW CREATE TABLE ' . $this->db->quoteTableName($table))->queryOne(); if ($row === false) { throw new Exception("Unable to find column '$column' in table '$table'."); } diff --git a/framework/db/mssql/ColumnSchemaBuilder.php b/framework/db/mssql/ColumnSchemaBuilder.php index 1e1ec92354..d08b2a4135 100644 --- a/framework/db/mssql/ColumnSchemaBuilder.php +++ b/framework/db/mssql/ColumnSchemaBuilder.php @@ -20,7 +20,6 @@ class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder /** * @inheritdoc */ - protected function buildCommentString() { return ''; diff --git a/framework/db/mssql/QueryBuilder.php b/framework/db/mssql/QueryBuilder.php index 8adc5a4591..e492aef749 100644 --- a/framework/db/mssql/QueryBuilder.php +++ b/framework/db/mssql/QueryBuilder.php @@ -187,12 +187,7 @@ class QueryBuilder extends \yii\db\QueryBuilder } /** - * Builds a SQL command for adding comment to column - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself + * @inheritdoc */ public function addCommentOnColumn($table, $column, $comment) { @@ -200,22 +195,15 @@ class QueryBuilder extends \yii\db\QueryBuilder } /** - * Builds a SQL command for adding comment to table - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself + * @inheritdoc */ public function addCommentOnTable($table, $comment) { return "sp_updateextendedproperty @name = N'MS_Description', @value = {$this->db->quoteValue($comment)}, @level1type = N'Table', @level1name = {$this->db->quoteTableName($table)}"; } + /** - * Builds a SQL command for adding comment to column - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @return $this the command object itself + * @inheritdoc */ public function dropCommentFromColumn($table, $column) { @@ -223,10 +211,7 @@ class QueryBuilder extends \yii\db\QueryBuilder } /** - * Builds a SQL command for adding comment to table - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @return $this the command object itself + * @inheritdoc */ public function dropCommentFromTable($table) { diff --git a/framework/db/mssql/Schema.php b/framework/db/mssql/Schema.php index 45c2e83d94..ba052ccf62 100644 --- a/framework/db/mssql/Schema.php +++ b/framework/db/mssql/Schema.php @@ -126,6 +126,7 @@ class Schema extends \yii\db\Schema /** * @inheritdoc + * @return ColumnSchemaBuilder column schema builder instance */ public function createColumnSchemaBuilder($type, $length = null) { diff --git a/framework/db/mysql/ColumnSchemaBuilder.php b/framework/db/mysql/ColumnSchemaBuilder.php index c9694b2be5..24e3eb0018 100644 --- a/framework/db/mysql/ColumnSchemaBuilder.php +++ b/framework/db/mysql/ColumnSchemaBuilder.php @@ -50,13 +50,13 @@ class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder { switch ($this->getTypeCategory()) { case self::CATEGORY_PK: - $format = '{type}{length}{check}{pos}'; + $format = '{type}{length}{check}{comment}{pos}'; break; case self::CATEGORY_NUMERIC: - $format = '{type}{length}{unsigned}{notnull}{unique}{default}{check}{pos}'; + $format = '{type}{length}{unsigned}{notnull}{unique}{default}{check}{comment}{pos}'; break; default: - $format = '{type}{length}{notnull}{unique}{default}{check}{pos}'; + $format = '{type}{length}{notnull}{unique}{default}{check}{comment}{pos}'; } return $this->buildCompleteString($format); } diff --git a/framework/db/mysql/QueryBuilder.php b/framework/db/mysql/QueryBuilder.php index 426eadbe2f..78624553bd 100644 --- a/framework/db/mysql/QueryBuilder.php +++ b/framework/db/mysql/QueryBuilder.php @@ -221,80 +221,42 @@ class QueryBuilder extends \yii\db\QueryBuilder } /** - * Builds a SQL command for adding comment to column - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself + * @inheritdoc */ public function addCommentOnColumn($table, $column, $comment) { - $quotedTable = $this->db->quoteTableName($table); - $definition = $this->getColumnDefinition($quotedTable, $column); + $definition = $this->getColumnDefinition($table, $column); $definition = trim(preg_replace("/COMMENT '(.*?)'/i", '', $definition)); - return sprintf( - 'ALTER TABLE %s CHANGE %s %s%s COMMENT %s', - $quotedTable, - $this->db->quoteColumnName($column), - $this->db->quoteColumnName($column), - empty($definition) ? '' : ' ' . $definition, - $this->db->quoteValue($comment) - ); + + return 'ALTER TABLE ' . $this->db->quoteTableName($table) + . ' CHANGE ' . $this->db->quoteColumnName($column) + . ' ' . $this->db->quoteColumnName($column) + . (empty($definition) ? '' : ' ' . $definition) + . ' COMMENT ' . $this->db->quoteValue($comment); } /** - * Builds a SQL command for adding comment to table - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself + * @inheritdoc */ public function addCommentOnTable($table, $comment) { - $quotedTable = $this->db->quoteTableName($table); - return sprintf( - 'ALTER TABLE %s COMMENT %s', - $quotedTable, - $this->db->quoteValue($comment) - ); + return 'ALTER TABLE ' . $this->db->quoteTableName($table) . ' COMMENT ' . $this->db->quoteValue($comment); } /** - * Builds a SQL command for adding comment to column - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @return $this the command object itself + * @inheritdoc */ public function dropCommentFromColumn($table, $column) { - $quotedTable = $this->db->quoteTableName($table); - $definition = $this->getColumnDefinition($quotedTable, $column); - $definition = trim(preg_replace("/COMMENT '(.*?)'/i", '', $definition)); - return sprintf( - 'ALTER TABLE %s CHANGE %s %s%s COMMENT \'\'', - $quotedTable, - $this->db->quoteColumnName($column), - $this->db->quoteColumnName($column), - empty($definition) ? '' : ' ' . $definition - ); + return $this->addCommentOnColumn($table, $column, ''); } /** - * Builds a SQL command for adding comment to table - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @return $this the command object itself + * @inheritdoc */ public function dropCommentFromTable($table) { - $quotedTable = $this->db->quoteTableName($table); - return sprintf( - "ALTER TABLE %s COMMENT ''", - $quotedTable, - empty($definition) ? '' : ' ' . $definition - ); + return $this->addCommentOnTable($table, ''); } @@ -308,7 +270,8 @@ class QueryBuilder extends \yii\db\QueryBuilder */ private function getColumnDefinition($table, $column) { - $row = $this->db->createCommand('SHOW CREATE TABLE ' . $table)->queryOne(); + $quotedTable = $this->db->quoteTableName($table); + $row = $this->db->createCommand('SHOW CREATE TABLE ' . $quotedTable)->queryOne(); if ($row === false) { throw new Exception("Unable to find column '$column' in table '$table'."); } @@ -327,4 +290,4 @@ class QueryBuilder extends \yii\db\QueryBuilder } return null; } -} \ No newline at end of file +} diff --git a/framework/db/oci/ColumnSchemaBuilder.php b/framework/db/oci/ColumnSchemaBuilder.php index deff99d98d..1dda4cb041 100644 --- a/framework/db/oci/ColumnSchemaBuilder.php +++ b/framework/db/oci/ColumnSchemaBuilder.php @@ -60,4 +60,12 @@ class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder } return $this->buildCompleteString($format); } + + /** + * @inheritdoc + */ + protected function buildCommentString() + { + return ''; + } } diff --git a/framework/db/oci/QueryBuilder.php b/framework/db/oci/QueryBuilder.php index 7ceb5cfd88..130ca06bfa 100644 --- a/framework/db/oci/QueryBuilder.php +++ b/framework/db/oci/QueryBuilder.php @@ -269,27 +269,18 @@ EOD; } /** - * Builds a SQL command for adding comment to column - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @return $this the command object itself - * @since 2.0.8 + * @inheritdoc */ public function dropCommentFromColumn($table, $column) { - return 'COMMENT ON COLUMN ' . $this->db->quoteTableName($table) . '.' . $this->db->quoteColumnName($column) . " IS ' '"; + return 'COMMENT ON COLUMN ' . $this->db->quoteTableName($table) . '.' . $this->db->quoteColumnName($column) . " IS ''"; } /** - * Builds a SQL command for adding comment to table - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @return $this the command object itself - * @since 2.0.8 + * @inheritdoc */ public function dropCommentFromTable($table) { - return 'COMMENT ON TABLE ' . $this->db->quoteTableName($table) . " IS ' '"; + return 'COMMENT ON TABLE ' . $this->db->quoteTableName($table) . " IS ''"; } } diff --git a/framework/db/pgsql/ColumnSchemaBuilder.php b/framework/db/pgsql/ColumnSchemaBuilder.php index 986ce28c4a..0e2fb59b48 100644 --- a/framework/db/pgsql/ColumnSchemaBuilder.php +++ b/framework/db/pgsql/ColumnSchemaBuilder.php @@ -17,7 +17,6 @@ use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder; */ class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder { - /** * @inheritdoc */ diff --git a/framework/db/pgsql/Schema.php b/framework/db/pgsql/Schema.php index 320d669726..86402e4cfb 100644 --- a/framework/db/pgsql/Schema.php +++ b/framework/db/pgsql/Schema.php @@ -120,6 +120,7 @@ class Schema extends \yii\db\Schema /** * @inheritdoc + * @return ColumnSchemaBuilder column schema builder instance */ public function createColumnSchemaBuilder($type, $length = null) { diff --git a/framework/db/sqlite/ColumnSchemaBuilder.php b/framework/db/sqlite/ColumnSchemaBuilder.php index 4cc40ae9e9..8649baa761 100644 --- a/framework/db/sqlite/ColumnSchemaBuilder.php +++ b/framework/db/sqlite/ColumnSchemaBuilder.php @@ -7,6 +7,7 @@ namespace yii\db\sqlite; +use yii\base\NotSupportedException; use yii\db\ColumnSchemaBuilder as AbstractColumnSchemaBuilder; @@ -41,15 +42,14 @@ class ColumnSchemaBuilder extends AbstractColumnSchemaBuilder default: $format = '{type}{length}{notnull}{unique}{check}{default}'; } + return $this->buildCompleteString($format); } /** - * Specify the comment for the column - * - * @param string $comment the comment - * @throws NotSupportedException this is not supported by SQLite - * @since 2.0.8 + * @inheritdoc + * @param string $comment + * @throws NotSupportedException */ public function comment($comment) { diff --git a/framework/db/sqlite/QueryBuilder.php b/framework/db/sqlite/QueryBuilder.php index 4768b6d9e2..1b5ad4a74d 100644 --- a/framework/db/sqlite/QueryBuilder.php +++ b/framework/db/sqlite/QueryBuilder.php @@ -291,13 +291,8 @@ class QueryBuilder extends \yii\db\QueryBuilder } /** - * Builds a SQL command for adding comment to column - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself - * @throws NotSupportedException this is not supported by SQLite + * @inheritdoc + * @throws NotSupportedException */ public function addCommentOnColumn($table, $column, $comment) { @@ -305,12 +300,8 @@ class QueryBuilder extends \yii\db\QueryBuilder } /** - * Builds a SQL command for adding comment to table - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $comment the text of the comment to be added. The comment will be properly quoted by the method. - * @return $this the command object itself - * @throws NotSupportedException this is not supported by SQLite + * @inheritdoc + * @throws NotSupportedException */ public function addCommentOnTable($table, $comment) { @@ -318,12 +309,8 @@ class QueryBuilder extends \yii\db\QueryBuilder } /** - * Builds a SQL command for adding comment to column - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @param string $column the name of the column to be commented. The column name will be properly quoted by the method. - * @return $this the command object itself - * @throws NotSupportedException this is not supported by SQLite + * @inheritdoc + * @throws NotSupportedException */ public function dropCommentFromColumn($table, $column) { @@ -331,11 +318,8 @@ class QueryBuilder extends \yii\db\QueryBuilder } /** - * Builds a SQL command for adding comment to table - * - * @param string $table the table whose column is to be commented. The table name will be properly quoted by the method. - * @return $this the command object itself - * @throws NotSupportedException this is not supported by SQLite + * @inheritdoc + * @throws NotSupportedException */ public function dropCommentFromTable($table) { diff --git a/framework/db/sqlite/Schema.php b/framework/db/sqlite/Schema.php index afb8d6c6c5..21af58de2a 100644 --- a/framework/db/sqlite/Schema.php +++ b/framework/db/sqlite/Schema.php @@ -93,6 +93,7 @@ class Schema extends \yii\db\Schema /** * @inheritdoc + * @return ColumnSchemaBuilder column schema builder instance */ public function createColumnSchemaBuilder($type, $length = null) { @@ -289,12 +290,4 @@ class Schema extends \yii\db\Schema throw new NotSupportedException(get_class($this) . ' only supports transaction isolation levels READ UNCOMMITTED and SERIALIZABLE.'); } } - - /** - * @inheritdoc - */ - public function createColumnSchemaBuilder($type, $length = null) - { - return new ColumnSchemaBuilder($type, $length); - } } diff --git a/tests/framework/db/QueryBuilderTest.php b/tests/framework/db/QueryBuilderTest.php index 602ac6e29d..fa01341c1b 100644 --- a/tests/framework/db/QueryBuilderTest.php +++ b/tests/framework/db/QueryBuilderTest.php @@ -916,7 +916,27 @@ abstract class QueryBuilderTest extends DatabaseTestCase ], ], [ - + Schema::TYPE_INTEGER . " COMMENT 'test comment'", + $this->integer()->comment('test comment'), + [ + 'mysql' => "int(11) COMMENT 'test comment'", + 'postgres' => 'integer', + 'oci' => "NUMBER(10)", + 'sqlsrv' => 'int', + 'cubrid' => "int COMMENT 'test comment'", + ], + ], + [ + Schema::TYPE_PK . " COMMENT 'test comment'", + $this->primaryKey()->comment('test comment'), + [ + 'mysql' => "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'test comment'", + 'postgres' => 'serial NOT NULL PRIMARY KEY', + 'sqlite' => 'integer PRIMARY KEY AUTOINCREMENT NOT NULL', + 'oci' => 'NUMBER(10) NOT NULL PRIMARY KEY', + 'sqlsrv' => 'int IDENTITY PRIMARY KEY', + 'cubrid' => "int NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'test comment'", + ], ], ]; diff --git a/tests/framework/db/mysql/MysqlQueryBuilderTest.php b/tests/framework/db/mysql/MysqlQueryBuilderTest.php index f9c682ca63..e0ea3fe724 100644 --- a/tests/framework/db/mysql/MysqlQueryBuilderTest.php +++ b/tests/framework/db/mysql/MysqlQueryBuilderTest.php @@ -48,6 +48,11 @@ class MysqlQueryBuilderTest extends QueryBuilderTest $this->primaryKey(8)->first()->after('col_before'), 'int(8) NOT NULL AUTO_INCREMENT PRIMARY KEY FIRST' ], + [ + Schema::TYPE_PK . " COMMENT 'test' AFTER `col_before`", + $this->primaryKey()->comment('test')->after('col_before'), + "int(11) NOT NULL AUTO_INCREMENT PRIMARY KEY COMMENT 'test' AFTER `col_before`" + ], ]); } } diff --git a/tests/framework/db/oci/OracleQueryBuilderTest.php b/tests/framework/db/oci/OracleQueryBuilderTest.php index fd0527ada3..19f7efa7d9 100644 --- a/tests/framework/db/oci/OracleQueryBuilderTest.php +++ b/tests/framework/db/oci/OracleQueryBuilderTest.php @@ -37,7 +37,7 @@ class OracleQueryBuilderTest extends QueryBuilderTest $sql = $qb->addCommentOnColumn('comment', 'text', 'This is my column.'); $this->assertEquals($expected, $sql); - $expected = "COMMENT ON COLUMN \"comment\".\"text\" IS ' '"; + $expected = "COMMENT ON COLUMN \"comment\".\"text\" IS ''"; $sql = $qb->dropCommentFromColumn('comment', 'text'); $this->assertEquals($expected, $sql); } @@ -50,7 +50,7 @@ class OracleQueryBuilderTest extends QueryBuilderTest $sql = $qb->addCommentOnTable('comment', 'This is my table.'); $this->assertEquals($expected, $sql); - $expected = "COMMENT ON TABLE \"comment\" IS ' '"; + $expected = "COMMENT ON TABLE \"comment\" IS ''"; $sql = $qb->dropCommentFromTable('comment'); $this->assertEquals($expected, $sql); }