diff --git a/libraries/Table.php b/libraries/Table.php index 95a8a2ebef..b4d5194473 100644 --- a/libraries/Table.php +++ b/libraries/Table.php @@ -365,6 +365,13 @@ class Table } else { if ($attribute != '') { $query .= ' ' . $attribute; + + if ($is_timestamp + && preg_match('/TIMESTAMP/i', $attribute) + && $length !== 0 + ) { + $query .= '(' . $length . ')'; + } } $matches = preg_match( @@ -420,6 +427,9 @@ class Table // else fall-through intended, no break here case 'CURRENT_TIMESTAMP' : $query .= ' DEFAULT ' . $default_type; + if ($length !== 0 && $is_timestamp) { + $query .= '(' . $length . ')'; + } break; case 'NONE' : default : diff --git a/test/classes/TableTest.php b/test/classes/TableTest.php index 02f85f9fc5..493dbcfc8d 100644 --- a/test/classes/TableTest.php +++ b/test/classes/TableTest.php @@ -516,7 +516,24 @@ class TableTest extends PMATestCase $query ); + // $type is 'TIMESTAMP(3), $default_type is CURRENT_TIMESTAMP(3) + $type = 'TIMESTAMP'; + $length = '3'; + $extra = ''; + $default_type = 'CURRENT_TIMESTAMP'; + $query = Table::generateFieldSpec( + $name, $type, $length, $attribute, $collation, + $null, $default_type, $default_value, $extra, $comment, + $virtuality, $expression, $move_to + ); + $this->assertEquals( + "`PMA_name` TIMESTAMP(3) PMA_attribute NULL DEFAULT CURRENT_TIMESTAMP(3) " + . "COMMENT 'PMA_comment' FIRST", + $query + ); + //$default_type is NONE + $type = 'BOOLEAN'; $default_type = 'NONE'; $extra = 'INCREMENT'; $move_to = '-first';