public function testIdGeneratorType() { $table = new Table("foo"); $table->setIdGeneratorType(Table::ID_IDENTITY); $this->assertTrue($table->isIdGeneratorIdentity()); $table->setIdGeneratorType(Table::ID_SEQUENCE); $this->assertTrue($table->isIdGeneratorSequence()); }
/** * Gets the SQL statement(s) to create a table with the specified name, columns and constraints * on this platform. * * @param string $table The name of the table. * @param int $createFlags * @return array The sequence of SQL statements. */ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES) { if (!is_int($createFlags)) { throw new \InvalidArgumentException("Second argument of AbstractPlatform::getCreateTableSQL() has to be integer."); } if (count($table->getColumns()) == 0) { throw DBALException::noColumnsSpecifiedForTable($table->getName()); } $tableName = $table->getName(); $options = $table->getOptions(); $options['uniqueConstraints'] = array(); $options['indexes'] = array(); $options['primary'] = array(); if (($createFlags & self::CREATE_INDEXES) > 0) { foreach ($table->getIndexes() as $index) { /* @var $index Index */ if ($index->isPrimary()) { $options['primary'] = $index->getColumns(); } else { $options['indexes'][$index->getName()] = $index; } } } $columns = array(); foreach ($table->getColumns() as $column) { /* @var \Doctrine\DBAL\Schema\Column $column */ $columnData = array(); $columnData['name'] = $column->getName(); $columnData['type'] = $column->getType(); $columnData['length'] = $column->getLength(); $columnData['notnull'] = $column->getNotNull(); $columnData['unique'] = $column->hasPlatformOption("unique") ? $column->getPlatformOption('unique') : false; $columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false; if (strtolower($columnData['type']) == "string" && $columnData['length'] === null) { $columnData['length'] = 255; } $columnData['precision'] = $column->getPrecision(); $columnData['scale'] = $column->getScale(); $columnData['default'] = $column->getDefault(); $columnData['columnDefinition'] = $column->getColumnDefinition(); if (in_array($column->getName(), $options['primary'])) { $columnData['primary'] = true; if ($table->isIdGeneratorIdentity()) { $columnData['autoincrement'] = true; } } $columns[$columnData['name']] = $columnData; } if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) { $options['foreignKeys'] = array(); foreach ($table->getForeignKeys() as $fkConstraint) { $options['foreignKeys'][] = $fkConstraint; } } return $this->_getCreateTableSQL($tableName, $columns, $options); }