diff --git a/lib/Cake/Model/Datasource/Database/Connection.php b/lib/Cake/Model/Datasource/Database/Connection.php index 69f76bc12d7..b05e9f7e709 100644 --- a/lib/Cake/Model/Datasource/Database/Connection.php +++ b/lib/Cake/Model/Datasource/Database/Connection.php @@ -449,10 +449,20 @@ public function listTables() { * @return array The schema data for the requested table. */ public function describe($table) { - $this->connect(); - $result = $this->execute($this->_driver->describeTableSql(), ['table' => $table]); + list($sql, $params) = $this->_driver->describeTableSql($table); + $statement = $this->execute($sql, $params); $schema = []; - + // TODO complete. + // TODO add tableParameters for platform specific features. + while ($row = $statement->fetch('assoc')) { + list($type, $length) = $this->_driver->columnType($row['Type']); + $schema[$row['Field']] = [ + 'type' => $type, + 'null' => $row['Null'] === 'YES' ? true : false, + 'default' => $row['Default'], + 'length' => $length, + ]; + } return $schema; } 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 ca1bc0f2c96..78303e8beda 100644 --- a/lib/Cake/Test/TestCase/Model/Datasource/Database/Driver/MysqlTest.php +++ b/lib/Cake/Test/TestCase/Model/Datasource/Database/Driver/MysqlTest.php @@ -242,8 +242,7 @@ public function testDescribeTable() { 'type' => 'biginteger', 'null' => false, 'default' => null, - 'length' => 8, - 'primary' => true + 'length' => 20, ], 'title' => [ 'type' => 'string',