Cache names for improved speed in long iterations requesting

the same name thousands of times.
Prepare Oracle Sequnces for the insert_record function.
This commit is contained in:
stronk7 2006-08-27 08:52:51 +00:00
parent c7a872cbcf
commit b8851b80eb
2 changed files with 10 additions and 2 deletions

View File

@ -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);

View File

@ -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);
}