diff --git a/framework/db/oci/QueryBuilder.php b/framework/db/oci/QueryBuilder.php index 334c9a0..65f196f 100644 --- a/framework/db/oci/QueryBuilder.php +++ b/framework/db/oci/QueryBuilder.php @@ -257,4 +257,27 @@ EOD; return 'INSERT ALL ' . $tableAndColumns . implode($tableAndColumns, $values) . ' SELECT 1 FROM SYS.DUAL'; } + + /** + * 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 + */ + public function dropCommentFromColumn($table, $column) + { + 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 + */ + public function dropCommentFromTable($table) + { + return 'COMMENT ON TABLE ' . $this->db->quoteTableName($table) . " IS ' '"; + } } diff --git a/tests/framework/db/oci/OracleQueryBuilderTest.php b/tests/framework/db/oci/OracleQueryBuilderTest.php index fcba907..e495eec 100644 --- a/tests/framework/db/oci/OracleQueryBuilderTest.php +++ b/tests/framework/db/oci/OracleQueryBuilderTest.php @@ -82,6 +82,33 @@ class OracleQueryBuilderTest extends QueryBuilderTest [Schema::TYPE_MONEY . ' CHECK (value > 0.0)', $this->money()->check('value > 0.0'), 'NUMBER(19,4) CHECK (value > 0.0)'], [Schema::TYPE_MONEY . '(16,2) CHECK (value > 0.0)', $this->money(16, 2)->check('value > 0.0'), 'NUMBER(16,2) CHECK (value > 0.0)'], [Schema::TYPE_MONEY . ' NOT NULL', $this->money()->notNull(), 'NUMBER(19,4) NOT NULL'], + [Schema::TYPE_MONEY . ' NOT NULL', $this->money()->notNull()->comment('this is money column'), 'NUMBER(19,4) NOT NULL'], ]; } + + public function testCommentColumn() + { + $qb = $this->getQueryBuilder(); + + $expected = "COMMENT ON COLUMN \"comment\".\"text\" IS 'This is my column.'"; + $sql = $qb->addCommentOnColumn('comment', 'text', 'This is my column.'); + $this->assertEquals($expected, $sql); + + $expected = "COMMENT ON COLUMN \"comment\".\"text\" IS ' '"; + $sql = $qb->dropCommentFromColumn('comment', 'text'); + $this->assertEquals($expected, $sql); + } + + public function testCommentTable() + { + $qb = $this->getQueryBuilder(); + + $expected = "COMMENT ON TABLE \"comment\" IS 'This is my table.'"; + $sql = $qb->addCommentOnTable('comment', 'This is my table.'); + $this->assertEquals($expected, $sql); + + $expected = "COMMENT ON TABLE \"comment\" IS ' '"; + $sql = $qb->dropCommentFromTable('comment'); + $this->assertEquals($expected, $sql); + } }