Skip to content

Commit

Permalink
Merge branch 'MDL-69973' of https://github.com/stronk7/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
sarjona committed Nov 2, 2020
2 parents 7e44e7d + 12e273d commit 88460c4
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion admin/tool/xmldb/actions/XMLDBCheckAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function invoke() {
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;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/dml/mysqli_native_moodle_database.php
Original file line number Diff line number Diff line change
Expand Up @@ -886,7 +886,7 @@ private function get_column_info(stdClass $rawcolumn) {
$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;
}
Expand Down
38 changes: 36 additions & 2 deletions lib/dml/tests/dml_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -722,9 +722,13 @@ public function test_get_columns() {
$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');
Expand Down Expand Up @@ -785,6 +789,20 @@ public function test_get_columns() {
$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);
Expand All @@ -800,12 +818,28 @@ public function test_get_columns() {
$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);
Expand Down

0 comments on commit 88460c4

Please sign in to comment.