• Модуль: perfmon
  • Путь к файлу: ~/bitrix/modules/perfmon/lib/sql/column.php
  • Класс: BitrixPerfmonSqlColumn
  • Вызов: Column::getModifyDdl
public function getModifyDdl(BaseObject $target, $dbType = '')
{
	switch ($dbType)
	{
	case "MYSQL":
		return "ALTER TABLE ".$this->parent->name." CHANGE ".$this->name." ".$target->name." ".$target->body;
	case "MSSQL":
		if ($this->nullable !== $target->nullable)
		{
			$nullDdl = ($target->nullable? " NULL": " NOT NULL");
		}
		else
		{
			$nullDdl = "";
		}

		if (
			$this->type === $target->type
			&& $this->default === $target->default
			&& (
				intval($this->length) < intval($target->length)
				|| (
					intval($target->length) < intval($this->length)
					&& mb_strtoupper($this->type) === "CHAR"
				)
			)
		)
		{
			$sql = array();
			foreach ($this->parent->indexes->getList() as $index)
			{
				if (in_array($this->name, $index->columns))
				{
					$sql[] = $index->getDropDdl($dbType);
				}
			}
			$sql[] = "ALTER TABLE ".$this->parent->name." ALTER COLUMN ".$this->name." ".$target->body.$nullDdl;
			foreach ($this->parent->indexes->getList() as $index)
			{
				if (in_array($this->name, $index->columns))
				{
					$sql[] = $index->getCreateDdl($dbType);
				}
			}
			return $sql;
		}
		elseif (
			$this->type === $target->type
			&& $this->default === $target->default
			&& intval($this->length) === intval($target->length)
			&& $this->nullable !== $target->nullable
		)
		{
			return "ALTER TABLE ".$this->parent->name." ALTER COLUMN ".$this->name." ".$target->body;
		}
		else
		{
			return "// ".get_class($this).":getModifyDdl for database type [".$dbType."] not implemented. Change requested from [$this->body] to [$target->body].";
		}
	case "ORACLE":
		if (
			$this->type === $target->type
			&& $this->default === $target->default
			&& (
				intval($this->length) < intval($target->length)
				|| (
					intval($target->length) < intval($this->length)
					&& mb_strtoupper($this->type) === "CHAR"
				)
			)
		)
		{
			return "ALTER TABLE ".$this->parent->name." MODIFY (".$this->name." ".$target->type."(".$target->length.")".")";
		}
		elseif (
			$this->type === $target->type
			&& $this->default === $target->default
			&& intval($this->length) === intval($target->length)
			&& $this->nullable !== $target->nullable
		)
		{
			return "
				declare
					l_nullable varchar2(1);
				begin
					select nullable into l_nullable
					from user_tab_columns
					where table_name = '".$this->parent->name."'
					and   column_name = '".$this->name."';
					if l_nullable = '".($target->nullable? "N": "Y")."' then
						execute immediate 'alter table ".$this->parent->name." modify (".$this->name." ".($target->nullable? "NULL": "NOT NULL").")';
					end if;
				end;
			";
		}
		else
		{
			return "// ".get_class($this).":getModifyDdl for database type [".$dbType."] not implemented. Change requested from [$this->body] to [$target->body].";
		}
	default:
		return "// ".get_class($this).":getModifyDdl for database type [".$dbType."] not implemented. Change requested from [$this->body] to [$target->body].";
	}
}