예제 #1
0
 /**
  * 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];
 }