Merge #16634 - Fix #16575 - move timestamp column with default value

Pull-request: #16634
Fixes: #16575

Signed-off-by: William Desportes <williamdes@wdes.fr>
This commit is contained in:
William Desportes 2021-02-16 17:35:19 +01:00
commit af1e90be51
No known key found for this signature in database
GPG Key ID: 90A0EF1B8251A889
2 changed files with 81 additions and 0 deletions

View File

@ -591,6 +591,9 @@ class Table
// a TIMESTAMP does not accept DEFAULT '0'
// but DEFAULT 0 works
$query .= ' DEFAULT 0';
} elseif ($is_timestamp
&& preg_match('/^\'\d\d\d\d-\d\d-\d\d \d\d:\d\d:\d\d(\.\d{1,6})?\'$/', $default_value)) {
$query .= ' DEFAULT ' . $default_value;
} elseif ($type === 'BIT') {
$query .= ' DEFAULT b\''
. preg_replace('/[^01]/', '0', (string) $default_value)

View File

@ -649,6 +649,84 @@ class TableTest extends AbstractTestCase
$query
);
$type = 'TIMESTAMP';
$length = '';
$extra = '';
$default_type = 'USER_DEFINED';
$default_value = '\'0000-00-00 00:00:00\'';
$query = Table::generateFieldSpec(
$name,
$type,
$length,
$attribute,
$collation,
$null,
$default_type,
$default_value,
$extra,
$comment,
$virtuality,
$expression,
$move_to
);
$this->assertEquals(
'`PMA_name` TIMESTAMP PMA_attribute NULL DEFAULT \'0000-00-00 00:00:00\' '
. "COMMENT 'PMA_comment' FIRST",
$query
);
$type = 'TIMESTAMP';
$length = '';
$extra = '';
$default_type = 'USER_DEFINED';
$default_value = '\'0000-00-00 00:00:00.0\'';
$query = Table::generateFieldSpec(
$name,
$type,
$length,
$attribute,
$collation,
$null,
$default_type,
$default_value,
$extra,
$comment,
$virtuality,
$expression,
$move_to
);
$this->assertEquals(
'`PMA_name` TIMESTAMP PMA_attribute NULL DEFAULT \'0000-00-00 00:00:00.0\' '
. "COMMENT 'PMA_comment' FIRST",
$query
);
$type = 'TIMESTAMP';
$length = '';
$extra = '';
$default_type = 'USER_DEFINED';
$default_value = '\'0000-00-00 00:00:00.000000\'';
$query = Table::generateFieldSpec(
$name,
$type,
$length,
$attribute,
$collation,
$null,
$default_type,
$default_value,
$extra,
$comment,
$virtuality,
$expression,
$move_to
);
$this->assertEquals(
'`PMA_name` TIMESTAMP PMA_attribute NULL DEFAULT \'0000-00-00 00:00:00.000000\' '
. "COMMENT 'PMA_comment' FIRST",
$query
);
//$default_type is NONE
$type = 'BOOLEAN';
$default_type = 'NONE';