Exemplo n.º 1
0
 public function createTable(Table $table)
 {
     $createDefinition = array();
     $fields = $table->getFields();
     if (empty($fields)) {
         throw new SQLException('A table must have at least one field');
     }
     foreach ($fields as $field) {
         $createDefinition[] = $this->buildColumnDefinition($field);
     }
     $primary = $table->getPrimaryKey();
     if ($primary != null) {
         $createDefinition[] = $this->buildPrimaryKeyDefinition($primary);
     }
     $indices = $table->getIndices();
     foreach ($indices as $index) {
         $createDefinition[] = $this->buildIndexDefinition($index);
     }
     $foreignKeys = $table->getForeignKeys();
     foreach ($foreignKeys as $foreignKey) {
         $createDefinition[] = $this->buildForeignKeyDefinition($foreignKey);
     }
     $query = 'CREATE TABLE ' . $this->addPrefix($table->getName()) . "(\n";
     $query .= implode(",\n", $createDefinition) . "\n)";
     $query .= " ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci";
     $comment = $table->getComment();
     if (strlen($comment) > 0) {
         $query .= ' COMMENT=' . $this->pdoDriver->escapeString($comment);
     }
     $query .= ';';
     $this->pdoDriver->executeQuery($query, null, false);
 }