diff --git a/lib/Cake/Model/Datasource/Database/Connection.php b/lib/Cake/Model/Datasource/Database/Connection.php index 8f6e7dfe287..c95d2ec9d87 100644 --- a/lib/Cake/Model/Datasource/Database/Connection.php +++ b/lib/Cake/Model/Datasource/Database/Connection.php @@ -452,8 +452,9 @@ public function describe($table) { list($sql, $params) = $this->_driver->describeTableSql($table); $statement = $this->execute($sql, $params); $schema = []; - // TODO complete. - // TODO add tableParameters for platform specific features. + + $fieldParams = $this->_driver->extraSchemaColumns(); + while ($row = $statement->fetch('assoc')) { list($type, $length) = $this->_driver->columnType($row['Type']); $schema[$row['Field']] = [ @@ -465,6 +466,11 @@ public function describe($table) { if (!empty($row['Key'])) { $schema[$row['Field']]['key'] = $this->_driver->keyType($row['Key']); } + foreach ($fieldParams as $key => $metadata) { + if (!empty($row[$metadata['column']])) { + $schema[$row['Field']][$key] = $row[$metadata['column']]; + } + } } return $schema; } diff --git a/lib/Cake/Model/Datasource/Database/Dialect/MysqlDialectTrait.php b/lib/Cake/Model/Datasource/Database/Dialect/MysqlDialectTrait.php index 9ace166d4a1..249024159fd 100644 --- a/lib/Cake/Model/Datasource/Database/Dialect/MysqlDialectTrait.php +++ b/lib/Cake/Model/Datasource/Database/Dialect/MysqlDialectTrait.php @@ -131,4 +131,23 @@ public function columnType($column) { return 'text'; } +/** + * Get additional column meta data used in schema reflections. + * + * @return array + */ + public function extraSchemaColumns() { + return [ + 'charset' => [ + 'column' => false, + ], + 'collate' => [ + 'column' => 'Collation', + ], + 'comment' => [ + 'column' => 'Comment', + ] + ]; + } + } diff --git a/lib/Cake/Model/Datasource/Database/SqlDialectTrait.php b/lib/Cake/Model/Datasource/Database/SqlDialectTrait.php index 537fe89edc9..cb2b68e9c88 100644 --- a/lib/Cake/Model/Datasource/Database/SqlDialectTrait.php +++ b/lib/Cake/Model/Datasource/Database/SqlDialectTrait.php @@ -176,4 +176,14 @@ public function rollbackSavePointSQL($name) { return 'ROLLBACK TO SAVEPOINT LEVEL' . $name; } +/** + * Get extra schema metadata columns + * + * This method returns information about additional metadata present in the data + * generated by describeTableSql + * + * @return void + */ + abstract function extraSchemaColumns(); + } diff --git a/lib/Cake/Test/TestCase/Model/Datasource/Database/Driver/MysqlTest.php b/lib/Cake/Test/TestCase/Model/Datasource/Database/Driver/MysqlTest.php index f3f48256cf0..00f8cbb97bc 100644 --- a/lib/Cake/Test/TestCase/Model/Datasource/Database/Driver/MysqlTest.php +++ b/lib/Cake/Test/TestCase/Model/Datasource/Database/Driver/MysqlTest.php @@ -129,7 +129,7 @@ protected function _createTables($connection) { body TEXT, author_id INT(11) NOT NULL, created DATETIME -) +) COLLATE=utf8_general_ci SQL; $connection->execute($table); } @@ -250,12 +250,14 @@ public function testDescribeTable() { 'null' => true, 'default' => null, 'length' => 20, + 'collate' => 'utf8_general_ci', ], 'body' => [ 'type' => 'text', 'null' => true, 'default' => null, 'length' => null, + 'collate' => 'utf8_general_ci', ], 'author_id' => [ 'type' => 'integer',