/** * Generate the SQL to create a table. * * @param TableSchema $table Table instance. * @param array $columns The columns to go inside the table. * @param array $constraints The constraints for the table. * @param array $indexes The indexes for the table. * @return array SQL statements to create a table. */ public function createTableSql(TableSchema $table, $columns, $constraints, $indexes) { $content = implode(",\n", array_merge($columns, $constraints, $indexes)); $temporary = $table->temporary() ? ' TEMPORARY ' : ' '; $content = sprintf("CREATE%sTABLE `%s` (\n%s\n)", $temporary, $table->name(), $content); $options = $table->options(); if (isset($options['engine'])) { $content .= sprintf(' ENGINE=%s', $options['engine']); } if (isset($options['charset'])) { $content .= sprintf(' DEFAULT CHARSET=%s', $options['charset']); } if (isset($options['collate'])) { $content .= sprintf(' COLLATE=%s', $options['collate']); } return [$content]; }
/** * Generate the SQL to create a table. * * @param TableSchema $table Table instance. * @param array $columns The columns to go inside the table. * @param array $constraints The constraints for the table. * @param array $indexes The indexes for the table. * @return array SQL statements to create a table. */ public function createTableSql(TableSchema $table, $columns, $constraints, $indexes) { $content = array_merge($columns, $constraints); $content = implode(",\n", array_filter($content)); $tableName = $this->_driver->quoteIdentifier($table->name()); $temporary = $table->temporary() ? ' TEMPORARY ' : ' '; $out = []; $out[] = sprintf("CREATE%sTABLE %s (\n%s\n)", $temporary, $tableName, $content); foreach ($indexes as $index) { $out[] = $index; } foreach ($table->columns() as $column) { $columnData = $table->column($column); if (isset($columnData['comment'])) { $out[] = sprintf('COMMENT ON COLUMN %s.%s IS %s', $tableName, $this->_driver->quoteIdentifier($column), $this->_driver->schemaValue($columnData['comment'])); } } return $out; }
/** * Generate the SQL to create a table. * * @param TableSchema $table Table instance. * @param array $columns The columns to go inside the table. * @param array $constraints The constraints for the table. * @param array $indexes The indexes for the table. * @return array SQL statements to create a table. */ public function createTableSql(TableSchema $table, $columns, $constraints, $indexes) { $lines = array_merge($columns, $constraints); $content = implode(",\n", array_filter($lines)); $temporary = $table->temporary() ? ' TEMPORARY ' : ' '; $table = sprintf("CREATE%sTABLE \"%s\" (\n%s\n)", $temporary, $table->name(), $content); $out = [$table]; foreach ($indexes as $index) { $out[] = $index; } return $out; }