/** * @param string $name Index name. */ function __construct($name = '') { parent::__construct($name); $this->columns = new Collection(); $this->indexes = new Collection(); $this->constraints = new Collection(); $this->triggers = new Collection(); }
/** * @param BaseObject $source Source object. * @param BaseObject $target Target object. * * @return void */ protected function handleChange(BaseObject $source, BaseObject $target) { if ($source instanceof Sequence || $source instanceof Procedure) { $this->conditions[""][] = $this->multiLinePhp("\t\t\$DB->Query(\"", $source->getDropDdl($this->dbType), "\", true);\n") . $this->multiLinePhp("\t\t\$DB->Query(\"", $target->getCreateDdl($this->dbType), "\", true);\n"); $dropStmt = $this->createStatement("\$DB->Query(\"", $source->getDropDdl($this->dbType), "\", true);"); $createStmt = $this->createStatement("\$DB->Query(\"", $target->getCreateDdl($this->dbType), "\", true);"); $stmt = new Php\Statement(); $stmt->merge($dropStmt); $stmt->merge($createStmt); $stmt->addCondition("\$updater->CanUpdateDatabase()"); $stmt->addCondition("\$DB->type == \"" . EscapePHPString($this->dbType) . "\""); $stmt->addCondition("\$updater->TableExists(\"" . EscapePHPString($this->tableCheck->getLowercasedName()) . "\")"); } elseif ($target instanceof Column) { $ddl = $source->getModifyDdl($target, $this->dbType); $predicate = "\$updater->TableExists(\"" . EscapePHPString($source->parent->name) . "\")"; $cond = "\t\tif ({$predicate})\n"; $predicate2 = "\$DB->Query(\"SELECT " . EscapePHPString($source->name) . " FROM " . EscapePHPString($source->parent->name) . " WHERE 1=0\", true)"; $this->conditions[$cond][] = "\t\t\tif ({$predicate2})\n" . "\t\t\t{\n" . $this->multiLinePhp("\t\t\t\t\$DB->Query(\"", $ddl, "\");\n") . "\t\t\t}\n"; $stmt = $this->createStatement("\$DB->Query(\"", $ddl, "\");"); $stmt->addCondition("\$updater->CanUpdateDatabase()"); $stmt->addCondition("\$DB->type == \"" . EscapePHPString($this->dbType) . "\""); $stmt->addCondition("\$updater->TableExists(\"" . EscapePHPString($source->parent->getLowercasedName()) . "\")"); $stmt->addCondition("\$DB->Query(\"SELECT " . EscapePHPString($source->name) . " FROM " . EscapePHPString($source->parent->getLowercasedName()) . " WHERE 1=0\", true)"); } elseif ($source instanceof Index) { $this->conditions["\t\tif (\$updater->TableExists(\"" . EscapePHPString($source->parent->name) . "\"))\n"][] = "\t\t\tif (\$DB->IndexExists(\"" . EscapePHPString($source->parent->name) . "\", array(" . $this->multiLinePhp("\"", $source->columns, "\", ") . ")))\n" . "\t\t\t{\n" . $this->multiLinePhp("\t\t\t\t\$DB->Query(\"", $source->getDropDdl($this->dbType), "\");\n") . $this->multiLinePhp("\t\t\t\t\$DB->Query(\"", $target->getCreateDdl($this->dbType), "\");\n") . "\t\t\t}\n"; $dropStmt = $this->createStatement("\$DB->Query(\"", $source->getDropDdl($this->dbType), "\", true);"); $createStmt = $this->createStatement("\$DB->Query(\"", $target->getCreateDdl($this->dbType), "\", true);"); $stmt = new Php\Statement(); $stmt->merge($dropStmt); $stmt->merge($createStmt); $stmt->addCondition("\$updater->CanUpdateDatabase()"); $stmt->addCondition("\$DB->type == \"" . EscapePHPString($this->dbType) . "\""); $stmt->addCondition("\$updater->TableExists(\"" . EscapePHPString($source->parent->getLowercasedName()) . "\")"); $stmt->addCondition("\$DB->IndexExists(\"" . EscapePHPString($source->parent->getLowercasedName()) . "\", array(" . $this->multiLinePhp("\"", $source->columns, "\", ") . "))"); $stmt->addCondition("!\$DB->IndexExists(\"" . EscapePHPString($target->parent->getLowercasedName()) . "\", array(" . $this->multiLinePhp("\"", $target->columns, "\", ") . "))"); } elseif ($source instanceof Trigger || $source instanceof Constraint) { $ddl = $source->getModifyDdl($target, $this->dbType); $predicate = "\$updater->TableExists(\"" . EscapePHPString($source->parent->name) . "\")"; $cond = "\t\tif ({$predicate})\n"; $this->conditions[$cond][] = $this->multiLinePhp("\t\t\t\$DB->Query(\"", $ddl, "\", true);\n"); $stmt = $this->createStatement("\$DB->Query(\"", $ddl, "\", true);"); $stmt->addCondition("\$updater->CanUpdateDatabase()"); $stmt->addCondition("\$DB->type == \"" . EscapePHPString($this->dbType) . "\""); $stmt->addCondition("\$updater->TableExists(\"" . EscapePHPString($source->parent->getLowercasedName()) . "\")"); } else { $this->conditions[""][] = "\t\t//change for " . get_class($source) . " not supported yet\n"; $stmt = $this->createStatement("", "//change for " . get_class($source) . " not supported yet", ""); } if ($stmt) { $this->statements[] = $stmt; } }
/** * @param BaseObject $source Source object. * @param BaseObject $target Target object. * * @return void */ protected function handleChange(BaseObject $source, BaseObject $target) { if ($source instanceof Sequence || $source instanceof Procedure) { $this->conditions[""][] = $this->multiLinePhp("\t\t\$DB->Query(\"", $source->getDropDdl($this->dbType), "\", true);\n") . $this->multiLinePhp("\t\t\$DB->Query(\"", $target->getCreateDdl($this->dbType), "\", true);\n"); } elseif ($target instanceof Column) { $this->conditions["\t\tif (\$DB->TableExists(\"" . EscapePHPString($source->parent->name) . "\"))\n"][] = "\t\t\tif (\$DB->Query(\"SELECT " . EscapePHPString($source->name) . " FROM " . EscapePHPString($source->parent->name) . " WHERE 1=0\", true))\n" . "\t\t\t{\n" . $this->multiLinePhp("\t\t\t\t\$DB->Query(\"", $source->getModifyDdl($target, $this->dbType), "\");\n") . "\t\t\t}\n"; } elseif ($source instanceof Index) { $this->conditions["\t\tif (\$DB->TableExists(\"" . EscapePHPString($source->parent->name) . "\"))\n"][] = "\t\t\tif (\$DB->IndexExists(\"" . EscapePHPString($source->parent->name) . "\", array(" . $this->multiLinePhp("\"", $source->columns, "\", ") . ")))\n" . "\t\t\t{\n" . $this->multiLinePhp("\t\t\t\t\$DB->Query(\"", $source->getDropDdl($this->dbType), "\");\n") . $this->multiLinePhp("\t\t\t\t\$DB->Query(\"", $target->getCreateDdl($this->dbType), "\");\n") . "\t\t\t}\n"; } elseif ($source instanceof Trigger || $source instanceof Constraint) { $this->conditions["\t\tif (\$DB->TableExists(\"" . EscapePHPString($source->parent->name) . "\"))\n"][] = $this->multiLinePhp("\t\t\t\$DB->Query(\"", $source->getModifyDdl($target, $this->dbType), "\", true);\n"); } else { $this->conditions[""][] = "\t\t//change for " . get_class($source) . " not supported yet\n"; } }
/** * Return DDL for trigger modification (drop with subsequent create). * * @param BaseObject $target Target object. * @param string $dbType Database type (MYSQL, ORACLE or MSSQL). * * @return array|string */ public function getModifyDdl(BaseObject $target, $dbType = '') { return array($this->getDropDdl($dbType), $target->getCreateDdl($dbType)); }