Skip to content
Permalink
Browse files

Inline extraSchemaColumns()

It was only used by Mysql in a small way. Inline the features to save
complexity/time. Also fix issues related to describing tables that don't
exist in Sqlite.
  • Loading branch information...
markstory committed Jun 2, 2013
1 parent be529eb commit 2a58e164462bfcdbc113c9c6115a5b0feff98a9d
@@ -72,7 +72,7 @@ public function listTables() {
*
* @param string $name The name of the table to describe.
* @return Cake\Schema\Table|null Object with column metadata, or null.
* @see Collection::fullDescribe()
* @throws Cake\Error\Exception when table cannot be described.
*/
public function describe($name) {
list($sql, $params) = $this->_dialect->describeTableSql(
@@ -82,19 +82,15 @@ public function describe($name) {
try {
$statement = $this->_connection->execute($sql, $params);
} catch (\PDOException $e) {
return null;
throw new Error\Exception($e->getMessage(), 500, $e);
}
if (count($statement) == 0) {
return null;
if (count($statement) === 0) {
throw new Error\Exception(__d('cake_dev', 'Cannot describe %s. It has 0 columns.', $name));
}
$table = new Table($name);
$fieldParams = [];
if (method_exists($this->_dialect, 'extraSchemaColumns')) {
$fieldParams = $this->_dialect->extraSchemaColumns();
}
foreach ($statement->fetchAll('assoc') as $row) {
$this->_dialect->convertFieldDescription($table, $row, $fieldParams);
$this->_dialect->convertFieldDescription($table, $row);
}
list($sql, $params) = $this->_dialect->describeIndexSql(
@@ -104,7 +100,7 @@ public function describe($name) {
try {
$statement = $this->_connection->execute($sql, $params);
} catch (\PDOException $e) {
return null;
throw new Error\Exception($e->getMessage(), 500, $e);
}
foreach ($statement->fetchAll('assoc') as $row) {
$this->_dialect->convertIndexDescription($table, $row);
@@ -137,20 +137,16 @@ public function convertColumn($column) {
*
* @param Cake\Database\Schema\Table $table The table object to append fields to.
* @param array $row The row data from describeTableSql
* @param array $fieldParams Additional field parameters to parse.
* @return void
*/
public function convertFieldDescription(Table $table, $row, $fieldParams = []) {
public function convertFieldDescription(Table $table, $row) {
$field = $this->convertColumn($row['Type']);
$field += [
'null' => $row['Null'] === 'YES' ? true : false,
'default' => $row['Default'],
'collate' => $row['Collation'],
'comment' => $row['Comment'],
];
foreach ($fieldParams as $key => $metadata) {
if (!empty($row[$metadata['column']])) {
$field[$key] = $row[$metadata['column']];
}
}
$table->addColumn($row['Field'], $field);
if (!empty($row['Key']) && $row['Key'] === 'PRI') {
$table->addConstraint('primary', [
@@ -221,25 +217,6 @@ public function convertIndexDescription(Table $table, $row) {
}
}
/**
* Get additional column meta data used in schema reflections.
*
* @return array
*/
public function extraSchemaColumns() {
return [
'charset' => [
'column' => false,
],
'collate' => [
'column' => 'Collation',
],
'comment' => [
'column' => 'Comment',
]
];
}
/**
* Generate the SQL to truncate a table.
*
@@ -150,10 +150,9 @@ public function convertColumn($column) {
*
* @param Cake\Database\Schema\Table $table The table object to append fields to.
* @param array $row The row data from describeTableSql
* @param array $fieldParams Additional field parameters to parse.
* @return void
*/
public function convertFieldDescription(Table $table, $row, $fieldParams = []) {
public function convertFieldDescription(Table $table, $row) {
$field = $this->convertColumn($row['type']);
if ($field['type'] === 'boolean') {
@@ -119,9 +119,8 @@ public function describeTableSql($table) {
*
* @param Cake\Database\Schema\Table $table The table object to append fields to.
* @param array $row The row data from describeTableSql
* @param array $fieldParams Additional field parameters to parse.
*/
public function convertFieldDescription(Table $table, $row, $fieldParams = []) {
public function convertFieldDescription(Table $table, $row) {
$field = $this->convertColumn($row['type']);
$field += [
'null' => !$row['notnull'],
@@ -53,6 +53,7 @@ public function tearDown() {
* Tests for positive describe() calls are in each platformSchema
* test case.
*
* @expectedException Cake\Error\Exception
* @return void
*/
public function testDescribeIncorrectTable() {

0 comments on commit 2a58e16

Please sign in to comment.
You can’t perform that action at this time.