Skip to content
Permalink
Browse files

Refactor case switch and add missing types.

  • Loading branch information...
markstory committed May 7, 2013
1 parent acbb923 commit 5bfa0295dedda71a2ec7bd2ac3a3bdd109393956
Showing with 45 additions and 25 deletions.
  1. +28 −25 lib/Cake/Database/Schema/MysqlSchema.php
  2. +17 −0 lib/Cake/Test/TestCase/Database/Schema/MysqlSchemaTest.php
@@ -182,31 +182,34 @@ public function createTableSql($table, $lines) {
public function columnSql(Table $table, $name) {
$data = $table->column($name);
$out = $this->_driver->quoteIdentifier($name);
switch ($data['type']) {
case 'string':
$out .= !empty($data['fixed']) ? ' CHAR' : ' VARCHAR';
if (!isset($data['length'])) {
$data['length'] = 255;
}
break;
case 'integer':
$out .= ' INTEGER';
break;
case 'biginteger':
$out .= ' BIGINT';
break;
case 'boolean':
$out .= ' BOOLEAN';
break;
case 'text':
$out .= ' TEXT';
break;
case 'datetime':
$out .= ' DATETIME';
break;
case 'timestamp':
$out .= ' TIMESTAMP';
break;
$typeMap = [
'integer' => ' INTEGER',
'biginteger' => ' BIGINT',
'boolean' => ' BOOLEAN',
'binary' => ' BLOB',
'float' => ' FLOAT',
'decimal' => ' DECIMAL',
'text' => ' TEXT',
'date' => ' DATE',
'time' => ' TIME',
'datetime' => ' DATETIME',
'timestamp' => ' TIMESTAMP',
];
$specialMap = [
'string' => true,
];
if (isset($typeMap[$data['type']])) {
$out .= $typeMap[$data['type']];
}
if (isset($specialMap[$data['type']])) {
switch ($data['type']) {
case 'string':
$out .= !empty($data['fixed']) ? ' CHAR' : ' VARCHAR';
if (!isset($data['length'])) {
$data['length'] = 255;
}
break;
}
}
$hasLength = [
'integer', 'string', 'float'
@@ -313,6 +313,12 @@ public static function columnSqlProvider() {
['type' => 'biginteger', 'length' => 20],
'`post_id` BIGINT'
],
// Float
[
'value',
['type' => 'float'],
'`value` FLOAT'
],
// Boolean
[
'checked',
@@ -330,6 +336,17 @@ public static function columnSqlProvider() {
['type' => 'datetime', 'comment' => 'Created timestamp'],
'`created` DATETIME COMMENT "Created timestamp"'
],
// Date & Time
[
'start_date',
['type' => 'date'],
'`start_date` DATE'
],
[
'start_time',
['type' => 'time'],
'`start_time` TIME'
],
// timestamps
[
'created',

0 comments on commit 5bfa029

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