diff --git a/lib/xmldb/classes/generators/XMLDBGenerator.class.php b/lib/xmldb/classes/generators/XMLDBGenerator.class.php index 7d9aafbc382..7a42a553cec 100644 --- a/lib/xmldb/classes/generators/XMLDBGenerator.class.php +++ b/lib/xmldb/classes/generators/XMLDBGenerator.class.php @@ -390,10 +390,16 @@ class XMLDBgenerator { $name = ''; /// Implement one basic cache to avoid object name duplication + /// and to speed up repeated queries for the same objects if (!isset($used_names)) { static $used_names = array(); } + /// If this exact object has been requested, return it + if (array_key_exists($tablename.'-'.$fields.'-'.$suffix, $used_names)) { + return $used_names[$tablename.'-'.$fields.'-'.$suffix]; + } + /// Use standard naming. See http://docs.moodle.org/en/XMLDB_key_and_index_naming $tablearr = explode ('_', $tablename); foreach ($tablearr as $table) { @@ -434,7 +440,7 @@ class XMLDBgenerator { } /// Add the name to the cache - $used_names[] = $namewithsuffix; + $used_names[$tablename.'-'.$fields.'-'.$suffix] = $namewithsuffix; /// Quote it if necessary (reserved words) $namewithsuffix = $this->getEncQuoted($namewithsuffix); diff --git a/lib/xmldb/classes/generators/oci8po/oci8po.class.php b/lib/xmldb/classes/generators/oci8po/oci8po.class.php index e4a0a1bb83b..0a8f277999e 100644 --- a/lib/xmldb/classes/generators/oci8po/oci8po.class.php +++ b/lib/xmldb/classes/generators/oci8po/oci8po.class.php @@ -138,7 +138,9 @@ class XMLDBoci8po extends XMLDBgenerator { $trigger.= "\nON " . $this->getEncQuoted($this->prefix . $xmldb_table->getName()); $trigger.= "\n FOR EACH ROW"; $trigger.= "\nBEGIN"; - $trigger.= "\n SELECT " . $sequence_name . '.nextval INTO :new.' . $this->getEncQuoted($xmldb_field->getName()) . " FROM dual;"; + $trigger.= "\n IF :old." . $this->getEncQuoted($xmldb_field->getName()) . ' IS NOT NULL THEN'; + $trigger.= "\n SELECT " . $sequence_name . '.nextval INTO :new.' . $this->getEncQuoted($xmldb_field->getName()) . " FROM dual;"; + $trigger.= "\n END IF;"; $trigger.= "\nEND;"; return array($sequence, $trigger); }