diff --git a/phalcon/Db/Dialect/Mysql.zep b/phalcon/Db/Dialect/Mysql.zep index cdc312f4b76..94e622e765c 100644 --- a/phalcon/Db/Dialect/Mysql.zep +++ b/phalcon/Db/Dialect/Mysql.zep @@ -798,7 +798,7 @@ class Mysql extends Dialect { string sql; - let sql = "SELECT TABLES.TABLE_TYPE AS table_type,TABLES.AUTO_INCREMENT AS auto_increment,TABLES.ENGINE AS engine,TABLES.TABLE_COLLATION AS table_collation FROM INFORMATION_SCHEMA.TABLES WHERE "; + let sql = "SELECT TABLES.TABLE_TYPE AS table_type,TABLES.AUTO_INCREMENT AS auto_increment,TABLES.ENGINE AS engine,TABLES.TABLE_COLLATION AS table_collation, TABLES.TABLE_COMMENT AS table_comment FROM INFORMATION_SCHEMA.TABLES WHERE "; if schema { return sql . "TABLES.TABLE_SCHEMA = '" . schema . "' AND TABLES.TABLE_NAME = '" . table . "'"; @@ -840,7 +840,7 @@ class Mysql extends Dialect */ protected function getTableOptions(array! definition) -> string { - var options, engine, autoIncrement, tableCollation, collationParts; + var options, engine, autoIncrement, tableCollation, collationParts, comment; array tableOptions; if !fetch options, definition["options"] { @@ -878,6 +878,16 @@ class Mysql extends Dialect } } + /** + * Check if there is an comment option + */ + if fetch comment, options["TABLE_COMMENT"] { + if comment { + let tableOptions[] = "COMMENT=" . comment; + } + } + + return join(" ", tableOptions); } diff --git a/phalcon/Db/Dialect/Postgresql.zep b/phalcon/Db/Dialect/Postgresql.zep index d95d555e4e6..b5d4fb7514d 100644 --- a/phalcon/Db/Dialect/Postgresql.zep +++ b/phalcon/Db/Dialect/Postgresql.zep @@ -124,7 +124,7 @@ class Postgresql extends Dialect { var temporary, options, table, columns, column, indexes, index, reference, references, indexName, indexType, onDelete, onUpdate, - columnDefinition; + columnDefinition, tableComment; array createLines, primaryColumns; string indexSql, indexSqlAfterCreate, columnLine, referenceSql, sql; @@ -257,6 +257,16 @@ class Postgresql extends Dialect let sql .= join(",\n\t", createLines) . "\n)"; if isset definition["options"] { let sql .= " " . this->getTableOptions(definition); + if fetch options, definition["options"] { + /** + * Check if there is an comment option + */ + if fetch tableComment, options["TABLE_COMMENT"] { + if tableComment { + let sql .= "; COMMENT ON TABLE " . table . " IS '".tableComment."'"; + } + } + } } let sql .= ";" . indexSqlAfterCreate; @@ -656,7 +666,10 @@ class Postgresql extends Dialect */ public function tableOptions(string! table, string schema = null) -> string { - return ""; + string sql; + + let sql = "select cast(obj_description(relfilenode,'pg_class') as varchar) as table_comment from pg_class where relname ='" . table . "'" ; + return sql; } /** diff --git a/tests/_data/assets/db/schemas/mysql_schema.sql b/tests/_data/assets/db/schemas/mysql_schema.sql index af77d6e531f..8330adff8af 100644 --- a/tests/_data/assets/db/schemas/mysql_schema.sql +++ b/tests/_data/assets/db/schemas/mysql_schema.sql @@ -118,7 +118,7 @@ CREATE TABLE `personas` KEY `estado` (`estado`), KEY `ciudad_id` (`ciudad_id`), KEY `estado_2` (`estado`,`nombres`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE =utf8_unicode_ci; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE =utf8_unicode_ci COMMENT='test table options'; INSERT INTO `personas` VALUES ('1', 3, 'HUANG ZHENGQUIN', '191821112', 'CRA 25 CALLE 100', '@yahoo.es', '2011-02-03', 127591, '2011-05-18', '6930.00', 'I'), @@ -12764,7 +12764,7 @@ create table dialect_table unique key dialect_table_unique (field_integer), key dialect_table_index (field_bigint), key dialect_table_two_fields (field_char, field_char_default) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='test table options'; drop table if exists `dialect_table_remote`; create table dialect_table_remote diff --git a/tests/tocheck-database/Db/Adapter/Pdo/DbDescribeMysqlCest.php b/tests/tocheck-database/Db/Adapter/Pdo/DbDescribeMysqlCest.php index 947c1097e38..8bdcdbda7da 100644 --- a/tests/tocheck-database/Db/Adapter/Pdo/DbDescribeMysqlCest.php +++ b/tests/tocheck-database/Db/Adapter/Pdo/DbDescribeMysqlCest.php @@ -97,6 +97,7 @@ public function dbMySqlTableOptions(IntegrationTester $I) 'auto_increment' => null, 'engine' => 'InnoDB', 'table_collation' => 'utf8_unicode_ci', + 'table_comment' => 'test table options', ]; $I->assertEquals( diff --git a/tests/tocheck-database/Db/Adapter/Pdo/Mysql/TableOptionsCest.php b/tests/tocheck-database/Db/Adapter/Pdo/Mysql/TableOptionsCest.php index a7b5233234e..6a970b0d377 100644 --- a/tests/tocheck-database/Db/Adapter/Pdo/Mysql/TableOptionsCest.php +++ b/tests/tocheck-database/Db/Adapter/Pdo/Mysql/TableOptionsCest.php @@ -37,6 +37,7 @@ public function dbAdapterPdoMysqlTableOptions(IntegrationTester $I) 'engine' => 'InnoDB', 'table_collation' => 'utf8_general_ci', 'table_type' => 'BASE TABLE', + 'table_comment' => 'test table options', ]; $actual = $this->connection->tableOptions(