/** * Return DDL for table creation. * * @param string $dbType Database type (MYSQL, ORACLE or MSSQL). * * @return array|string */ public function getCreateDdl($dbType = '') { $result = array(); $items = array(); /** @var Column $column */ foreach ($this->columns->getList() as $column) { $items[] = $column->name . " " . $column->body; } if ($dbType !== 'MSSQL') { /** @var Constraint $constraint */ foreach ($this->constraints->getList() as $constraint) { if ($constraint->name === '') { $items[] = $constraint->body; } else { $items[] = "CONSTRAINT " . $constraint->name . " " . $constraint->body; } } } $result[] = "CREATE TABLE " . $this->name . "(\n\t" . implode(",\n\t", $items) . "\n)" . $this->body; if ($dbType === 'MSSQL') { /** @var Constraint $constraint */ foreach ($this->constraints->getList() as $constraint) { $result[] = $constraint->getCreateDdl($dbType); } } return $result; }
/** * Return DDL for table creation. * * @param string $dbType Database type (MYSQL, ORACLE or MSSQL). * * @return array|string */ public function getCreateDdl($dbType = '') { $items = array(); /** @var Column $column */ foreach ($this->columns->getList() as $column) { $items[] = $column->name . " " . $column->body; } /** @var Constraint $constraint */ foreach ($this->constraints->getList() as $constraint) { $items[] = "CONSTRAINT " . $constraint->name . " " . $constraint->body; } return "CREATE TABLE " . $this->name . "(\n\t" . implode(",\n\t", $items) . "\n)" . $this->body; }