Skip to content

Commit

Permalink
Fix #14951 - Moving Columns with DEFAULT NULL doesn't work on MariaDB…
Browse files Browse the repository at this point in the history
… 10.2+

Ref: 98a7479
Signed-off-by: William Desportes <williamdes@wdes.fr>
  • Loading branch information
williamdes committed Nov 9, 2019
1 parent e9ad2bc commit 8aad190
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
Expand Up @@ -404,6 +404,9 @@ protected function moveColumns()
$column_names = array_keys($columns);
$changes = array();

// @see https://mariadb.com/kb/en/library/changes-improvements-in-mariadb-102/#information-schema
$usesLiteralNull = $this->dbi->isMariaDB() && $this->dbi->getVersion() >= 100200;
$defaultNullValue = $usesLiteralNull ? 'NULL' : null;
// move columns from first to last
for ($i = 0, $l = count($_POST['move_columns']); $i < $l; $i++) {
$column = $_POST['move_columns'][$i];
Expand All @@ -426,7 +429,8 @@ protected function moveColumns()
&& ($data['Default'] == 'CURRENT_TIMESTAMP'
|| $data['Default'] == 'current_timestamp()');

if ($data['Null'] === 'YES' && $data['Default'] === null) {
// @see https://mariadb.com/kb/en/library/information-schema-columns-table/#examples
if ($data['Null'] === 'YES' && in_array($$data['Default'], [$defaultNullValue, null])) {
$default_type = 'NULL';
} elseif ($current_timestamp) {
$default_type = 'CURRENT_TIMESTAMP';
Expand Down Expand Up @@ -454,7 +458,7 @@ protected function moveColumns()
$extracted_columnspec['spec_in_brackets'],
$extracted_columnspec['attribute'],
isset($data['Collation']) ? $data['Collation'] : '',
$data['Null'] === 'YES' ? 'NULL' : 'NOT NULL',
$data['Null'] === 'YES' ? 'YES' : 'NO',
$default_type,
$current_timestamp ? '' : $data['Default'],
isset($data['Extra']) && $data['Extra'] !== '' ? $data['Extra']
Expand Down
2 changes: 1 addition & 1 deletion libraries/classes/CreateAddField.php
Expand Up @@ -93,7 +93,7 @@ private function buildColumnCreationStatement(
: '',
isset($_POST['field_null'][$i])
? $_POST['field_null'][$i]
: 'NOT NULL',
: 'NO',
$_POST['field_default_type'][$i],
$_POST['field_default_value'][$i],
isset($_POST['field_extra'][$i])
Expand Down

0 comments on commit 8aad190

Please sign in to comment.