$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) {
}
/// 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);
$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);
}