From: stronk7 Date: Sun, 1 Oct 2006 16:02:09 +0000 (+0000) Subject: Avoid some double updates under PG X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=51517ddc6d4933a5ca406d924afad7dfc57720ee;p=moodle.git Avoid some double updates under PG --- diff --git a/lib/xmldb/classes/generators/postgres7/postgres7.class.php b/lib/xmldb/classes/generators/postgres7/postgres7.class.php index e787f31735..c8dd0e14e3 100644 --- a/lib/xmldb/classes/generators/postgres7/postgres7.class.php +++ b/lib/xmldb/classes/generators/postgres7/postgres7.class.php @@ -171,25 +171,36 @@ class XMLDBpostgres7 extends XMLDBgenerator { $defaultvalue = null; + /// Save old flags + $old_skip_default = $this->alter_column_skip_default; + $old_skip_notnull = $this->alter_column_skip_notnull; + /// Prevent default clause and launch parent getAddField() $this->alter_column_skip_default = true; $this->alter_column_skip_notnull = true; $results = parent::getAddFieldSQL($xmldb_table, $xmldb_field); - /// Add default - if ($defaultclause = $this->getDefaultClause($xmldb_field)) { - $defaultvalue = $this->getDefaultValue($xmldb_field); - $results[] = 'ALTER TABLE ' . $tablename . ' ALTER COLUMN ' . $fieldname . ' SET' . $defaultclause; /// Add default clause - } + /// Re-set old flags + $this->alter_column_skip_default = $old_skip_default; + $this->alter_column_skip_notnull = $old_skip_notnull; - /// Update default value (if exists) to all the records - if ($defaultvalue !== null) { - $results[] = 'UPDATE ' . $tablename . ' SET ' . $fieldname . '=' . $defaultvalue; + /// Add default (only if not skip_default) + if (!$this->alter_column_skip_default) { + if ($defaultclause = $this->getDefaultClause($xmldb_field)) { + $defaultvalue = $this->getDefaultValue($xmldb_field); + $results[] = 'ALTER TABLE ' . $tablename . ' ALTER COLUMN ' . $fieldname . ' SET' . $defaultclause; /// Add default clause + } + /// Update default value (if exists) to all the records + if ($defaultvalue !== null) { + $results[] = 'UPDATE ' . $tablename . ' SET ' . $fieldname . '=' . $defaultvalue; + } } - /// Add not null - if ($xmldb_field->getNotnull()) { - $results[] = 'ALTER TABLE ' . $tablename . ' ALTER COLUMN ' . $fieldname . ' SET NOT NULL'; /// Add not null + /// Add not null (only if no skip_notnull) + if (!$this->alter_column_skip_notnull) { + if ($xmldb_field->getNotnull()) { + $results[] = 'ALTER TABLE ' . $tablename . ' ALTER COLUMN ' . $fieldname . ' SET NOT NULL'; /// Add not null + } } return $results;