Skip to content

Commit

Permalink
Add basic describe() to MySQL.
Browse files Browse the repository at this point in the history
Primary key, indexes, and platform specifics still need to be implemented.
  • Loading branch information
markstory committed Mar 25, 2013
1 parent 001ecae commit c24d6e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
16 changes: 13 additions & 3 deletions lib/Cake/Model/Datasource/Database/Connection.php
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -242,8 +242,7 @@ public function testDescribeTable() {
'type' => 'biginteger',
'null' => false,
'default' => null,
'length' => 8,
'primary' => true
'length' => 20,
],
'title' => [
'type' => 'string',
Expand Down

0 comments on commit c24d6e6

Please sign in to comment.