Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db supper table comment #15258

Open
wants to merge 7 commits into
base: 4.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 12 additions & 2 deletions phalcon/Db/Dialect/Mysql.zep
Expand Up @@ -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 . "'";
Expand Down Expand Up @@ -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"] {
Expand Down Expand Up @@ -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);
}

Expand Down
17 changes: 15 additions & 2 deletions phalcon/Db/Dialect/Postgresql.zep
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/_data/assets/db/schemas/mysql_schema.sql
Expand Up @@ -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'),
Expand Down Expand Up @@ -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
Expand Down
Expand Up @@ -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(
Expand Down
Expand Up @@ -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(
Expand Down