This commit is contained in:
Sara Arjona 2020-11-02 15:44:41 +01:00
commit 88460c4b00
3 changed files with 38 additions and 4 deletions

View File

@ -149,7 +149,7 @@ abstract class XMLDBCheckAction extends XMLDBAction {
continue;
}
// Fetch metadata from physical DB. All the columns info.
if (!$metacolumns = $DB->get_columns($xmldb_table->getName())) {
if (!$metacolumns = $DB->get_columns($xmldb_table->getName(), false)) {
// / Skip table if no metacolumns is available for it
continue;
}

View File

@ -886,7 +886,7 @@ class mysqli_native_moodle_database extends moodle_database {
$info->type = $rawcolumn->data_type;
$info->meta_type = $this->mysqltype2moodletype($rawcolumn->data_type);
if ($this->has_breaking_change_quoted_defaults()) {
$info->default_value = trim($rawcolumn->column_default, "'");
$info->default_value = is_null($rawcolumn->column_default) ? null : trim($rawcolumn->column_default, "'");
if ($info->default_value === 'NULL') {
$info->default_value = null;
}

View File

@ -722,9 +722,13 @@ EOD;
$table->add_field('course', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('name', XMLDB_TYPE_CHAR, '255', null, null, null, 'lala');
$table->add_field('description', XMLDB_TYPE_TEXT, 'small', null, null, null, null);
$table->add_field('oneint', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0');
$table->add_field('oneintnodefault', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null);
$table->add_field('enumfield', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, 'test2');
$table->add_field('onenum', XMLDB_TYPE_NUMBER, '10,2', null, null, null, 200);
$table->add_field('onefloat', XMLDB_TYPE_FLOAT, '10,2', null, null, null, 300);
$table->add_field('onenumnodefault', XMLDB_TYPE_NUMBER, '10,2', null, null, null);
$table->add_field('onefloat', XMLDB_TYPE_FLOAT, '10,2', null, XMLDB_NOTNULL, null, 300);
$table->add_field('onefloatnodefault', XMLDB_TYPE_FLOAT, '10,2', null, XMLDB_NOTNULL, null);
$table->add_field('anotherfloat', XMLDB_TYPE_FLOAT, null, null, null, null, 400);
$table->add_field('negativedfltint', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '-1');
$table->add_field('negativedfltnumber', XMLDB_TYPE_NUMBER, '10', null, XMLDB_NOTNULL, null, '-2');
@ -785,6 +789,20 @@ EOD;
$this->assertNull($field->default_value);
$this->assertFalse($field->not_null);
$field = $columns['oneint'];
$this->assertSame('I', $field->meta_type);
$this->assertFalse($field->auto_increment);
$this->assertTrue($field->has_default);
$this->assertEquals(0, $field->default_value);
$this->assertTrue($field->not_null);
$field = $columns['oneintnodefault'];
$this->assertSame('I', $field->meta_type);
$this->assertFalse($field->auto_increment);
$this->assertFalse($field->has_default);
$this->assertNull($field->default_value);
$this->assertTrue($field->not_null);
$field = $columns['enumfield'];
$this->assertSame('C', $field->meta_type);
$this->assertFalse($field->auto_increment);
@ -800,12 +818,28 @@ EOD;
$this->assertEquals(200.0, $field->default_value);
$this->assertFalse($field->not_null);
$field = $columns['onenumnodefault'];
$this->assertSame('N', $field->meta_type);
$this->assertFalse($field->auto_increment);
$this->assertEquals(10, $field->max_length);
$this->assertEquals(2, $field->scale);
$this->assertFalse($field->has_default);
$this->assertNull($field->default_value);
$this->assertFalse($field->not_null);
$field = $columns['onefloat'];
$this->assertSame('N', $field->meta_type);
$this->assertFalse($field->auto_increment);
$this->assertTrue($field->has_default);
$this->assertEquals(300.0, $field->default_value);
$this->assertFalse($field->not_null);
$this->assertTrue($field->not_null);
$field = $columns['onefloatnodefault'];
$this->assertSame('N', $field->meta_type);
$this->assertFalse($field->auto_increment);
$this->assertFalse($field->has_default);
$this->assertNull($field->default_value);
$this->assertTrue($field->not_null);
$field = $columns['anotherfloat'];
$this->assertSame('N', $field->meta_type);