/** * create a new table * * @param string $tableName Name of the database that should be created * @param array $columns Associative array that contains the definition of each field of the new table * The indexes of the array entries are the names of the fields of the table an * the array entry values are associative arrays like those that are meant to be * passed with the field definitions to get[Type]Declaration() functions. * array( * 'id' => array( * 'type' => 'integer', * 'unsigned' => 1 * 'notnull' => 1 * 'default' => 0 * ), * 'name' => array( * 'type' => 'text', * 'length' => 12 * ), * 'password' => array( * 'type' => 'text', * 'length' => 12 * ) * ); * @param array $options An associative array of table options: * array( * 'comment' => 'Foo', * 'charset' => 'utf8', * 'collate' => 'utf8_unicode_ci', * 'type' => 'innodb', * ); * * @return void * @override */ protected function _getCreateTableSql($tableName, array $columns, array $options = array()) { if (!$tableName) { throw DoctrineException::missingTableName(); } if (empty($columns)) { throw DoctrineException::missingFieldsArrayForTable($tableName); } $queryFields = $this->getColumnDeclarationListSql($columns); if (isset($options['uniqueConstraints']) && !empty($options['uniqueConstraints'])) { foreach ($options['uniqueConstraints'] as $index => $definition) { $queryFields .= ', ' . $this->getUniqueConstraintDeclarationSql($index, $definition); } } // add all indexes if (isset($options['indexes']) && !empty($options['indexes'])) { foreach ($options['indexes'] as $index => $definition) { $queryFields .= ', ' . $this->getIndexDeclarationSql($index, $definition); } } // attach all primary keys if (isset($options['primary']) && !empty($options['primary'])) { $keyColumns = array_unique(array_values($options['primary'])); $queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')'; } $query = 'CREATE '; if (!empty($options['temporary'])) { $query .= 'TEMPORARY '; } $query .= 'TABLE ' . $tableName . ' (' . $queryFields . ')'; $optionStrings = array(); if (isset($options['comment'])) { $optionStrings['comment'] = 'COMMENT = ' . $this->quote($options['comment'], 'text'); } if (isset($options['charset'])) { $optionStrings['charset'] = 'DEFAULT CHARACTER SET ' . $options['charset']; if (isset($options['collate'])) { $optionStrings['charset'] .= ' COLLATE ' . $options['collate']; } } // get the type of the table if (isset($options['engine'])) { $optionStrings[] = 'ENGINE = ' . $engine; } else { // default to innodb $optionStrings[] = 'ENGINE = InnoDB'; } if (!empty($optionStrings)) { $query .= ' ' . implode(' ', $optionStrings); } $sql[] = $query; if (isset($options['foreignKeys'])) { foreach ((array) $options['foreignKeys'] as $definition) { $sql[] = $this->getCreateForeignKeySql($definition, $tableName); } } return $sql; }