Ejemplo n.º 1
0
 /**
  * Returns the code (array of statements) needed to execute extra statements on table rename
  */
 function getRenameTableExtraSQL($xmldb_table, $newname)
 {
     $results = array();
     $newt = new XMLDBTable($newname);
     $xmldb_field = new XMLDBField('id');
     // Fields having sequences should be exclusively, id.
     $oldseqname = $this->getTableName($xmldb_table) . '_' . $xmldb_field->getName() . '_seq';
     $newseqname = $this->getTableName($newt) . '_' . $xmldb_field->getName() . '_seq';
     /// Rename de sequence
     $results[] = 'ALTER TABLE ' . $oldseqname . ' RENAME TO ' . $newseqname;
     /// Rename all the check constraints in the table
     $oldtablename = $this->getTableName($xmldb_table);
     $newtablename = $this->getTableName($newt);
     $oldconstraintprefix = $this->getNameForObject($xmldb_table->getName(), '');
     $newconstraintprefix = $this->getNameForObject($newt->getName(), '', '');
     if ($constraints = $this->getCheckConstraintsFromDB($xmldb_table)) {
         foreach ($constraints as $constraint) {
             /// Drop the old constraint
             $results[] = 'ALTER TABLE ' . $newtablename . ' DROP CONSTRAINT ' . $constraint->name;
             /// Calculate the new constraint name
             $newconstraintname = str_replace($oldconstraintprefix, $newconstraintprefix, $constraint->name);
             /// Add the new constraint
             $results[] = 'ALTER TABLE ' . $newtablename . ' ADD CONSTRAINT ' . $newconstraintname . ' CHECK ' . $constraint->description;
         }
     }
     return $results;
 }
Ejemplo n.º 2
0
 /**
  * Returns the code (array of statements) needed to execute extra statements on table rename
  */
 function getRenameTableExtraSQL($xmldb_table, $newname)
 {
     $results = array();
     $xmldb_field = new XMLDBField('id');
     // Fields having sequences should be exclusively, id.
     $oldseqname = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'seq');
     $newseqname = $this->getNameForObject($newname, $xmldb_field->getName(), 'seq');
     /// Rename de sequence
     $results[] = 'RENAME ' . $oldseqname . ' TO ' . $newseqname;
     $oldtriggername = $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'trg');
     $newtriggername = $this->getNameForObject($newname, $xmldb_field->getName(), 'trg');
     /// Drop old trigger
     $results[] = "DROP TRIGGER " . $oldtriggername;
     $newt = new XMLDBTable($newname);
     /// Temp table for trigger code generation
     /// Create new trigger
     $results = array_merge($results, $this->getCreateTriggerSQL($newt, $xmldb_field));
     /// Rename all the check constraints in the table
     $oldtablename = $this->getTableName($xmldb_table);
     $newtablename = $this->getTableName($newt);
     $oldconstraintprefix = $this->getNameForObject($xmldb_table->getName(), '');
     $newconstraintprefix = $this->getNameForObject($newt->getName(), '', '');
     if ($constraints = $this->getCheckConstraintsFromDB($xmldb_table)) {
         foreach ($constraints as $constraint) {
             /// Drop the old constraint
             $results[] = 'ALTER TABLE ' . $newtablename . ' DROP CONSTRAINT ' . $constraint->name;
             /// Calculate the new constraint name
             $newconstraintname = str_replace($oldconstraintprefix, $newconstraintprefix, $constraint->name);
             /// Add the new constraint
             $results[] = 'ALTER TABLE ' . $newtablename . ' ADD CONSTRAINT ' . $newconstraintname . ' CHECK (' . $constraint->description . ')';
         }
     }
     return $results;
 }