Example #1
0
 /**
  * @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;
     }
 }