Example #1
0
 /**
  * create a new table
  *
  * @param string $name   Name of the database that should be created
  * @param array $fields  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:
  *
  * @return void
  * @override
  */
 public function getCreateTableSql($name, array $fields, array $options = array())
 {
     if (!$name) {
         throw DoctrineException::invalidTableName($name);
     }
     if (empty($fields)) {
         throw DoctrineException::noFieldsSpecifiedForTable($name);
     }
     $queryFields = $this->getColumnDeclarationListSql($fields);
     $autoinc = false;
     foreach ($fields as $field) {
         if (isset($field['autoincrement']) && $field['autoincrement']) {
             $autoinc = true;
             break;
         }
     }
     if (!$autoinc && isset($options['primary']) && !empty($options['primary'])) {
         $keyColumns = array_unique(array_values($options['primary']));
         $keyColumns = array_map(array($this, 'quoteIdentifier'), $keyColumns);
         $queryFields .= ', PRIMARY KEY(' . implode(', ', $keyColumns) . ')';
     }
     $sql = 'CREATE TABLE ' . $name . ' (' . $queryFields;
     /*if ($check = $this->getCheckDeclarationSql($fields)) {
                 $sql .= ', ' . $check;
             }
     
             if (isset($options['checks']) && $check = $this->getCheckDeclarationSql($options['checks'])) {
                 $sql .= ', ' . $check;
             }*/
     $sql .= ')';
     $query[] = $sql;
     if (isset($options['indexes']) && !empty($options['indexes'])) {
         foreach ($options['indexes'] as $index => $definition) {
             $query[] = $this->getCreateIndexSql($name, $index, $definition);
         }
     }
     return $query;
 }