Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'MDL-29567_21' of git://github.com/stronk7/moodle into M…

…OODLE_21_STABLE
  • Loading branch information...
commit ddf0d0dcd75aa3d0b7d4a10d7d2f775f1b72f830 2 parents d85d6cc + 72a32ea
@samhemelryk samhemelryk authored
View
6 lib/dml/pgsql_native_moodle_database.php
@@ -415,7 +415,7 @@ public function get_columns($table, $usecache=true) {
$info->scale = null;
$info->not_null = ($rawcolumn->attnotnull === 't');
if ($info->has_default) {
- $info->default_value = $rawcolumn->adsrc;
+ $info->default_value = trim($rawcolumn->adsrc, '()');
} else {
$info->default_value = null;
}
@@ -433,7 +433,7 @@ public function get_columns($table, $usecache=true) {
$info->not_null = ($rawcolumn->attnotnull === 't');
$info->has_default = ($rawcolumn->atthasdef === 't');
if ($info->has_default) {
- $info->default_value = $rawcolumn->adsrc;
+ $info->default_value = trim($rawcolumn->adsrc, '()');
} else {
$info->default_value = null;
}
@@ -451,7 +451,7 @@ public function get_columns($table, $usecache=true) {
$info->not_null = ($rawcolumn->attnotnull === 't');
$info->has_default = ($rawcolumn->atthasdef === 't');
if ($info->has_default) {
- $info->default_value = $rawcolumn->adsrc;
+ $info->default_value = trim($rawcolumn->adsrc, '()');
} else {
$info->default_value = null;
}
View
16 lib/dml/simpletest/testdml.php
@@ -729,6 +729,9 @@ public function test_get_columns() {
$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('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');
+ $table->add_field('negativedfltfloat', XMLDB_TYPE_FLOAT, '10', null, XMLDB_NOTNULL, null, '-3');
$table->add_key('primary', XMLDB_KEY_PRIMARY, array('id'));
$dbman->create_table($table);
@@ -793,6 +796,19 @@ public function test_get_columns() {
$this->assertEqual(400.0, $field->default_value);
$this->assertFalse($field->not_null);
+ // Test negative defaults in numerical columns
+ $field = $columns['negativedfltint'];
+ $this->assertTrue($field->has_default);
+ $this->assertEqual(-1, $field->default_value);
+
+ $field = $columns['negativedfltnumber'];
+ $this->assertTrue($field->has_default);
+ $this->assertEqual(-2, $field->default_value);
+
+ $field = $columns['negativedfltfloat'];
+ $this->assertTrue($field->has_default);
+ $this->assertEqual(-3, $field->default_value);
+
for ($i = 0; $i < count($columns); $i++) {
if ($i == 0) {
$next_column = reset($columns);
Please sign in to comment.
Something went wrong with that request. Please try again.