/**
  * Metodo responsavel por popular valores nos itens necessarios, para uso em toda a classe
  *
  * @param array $arrInfosFilter
  */
 private function init(array $arrInfosForm = array())
 {
     $this->schema = $this->em->getConnection()->getSchemaManager()->createSchema();
     $this->newForm = new ClassGenerator();
     $this->initParams($arrInfosForm);
     $this->objTable = $this->schema->getTable($arrInfosForm['strTableName']);
     $arrForeignKeys = $this->objTable->getForeignKeys();
     $this->arrPrimaryKeys = $this->objTable->getPrimaryKey();
     foreach ($arrForeignKeys as $arrForeignKey) {
         $this->arrForeignKeys[$arrForeignKey->getColumns()[0]] = ['strColumns' => $arrForeignKey->getColumns()[0], 'strForeignColumns' => $arrForeignKey->getForeignColumns()[0], 'strForeignTableName' => $arrForeignKey->getForeignTableName()];
     }
 }
Example #2
0
 public function __construct(TableInformation $parent, \Doctrine\DBAL\Schema\Table $table, \Doctrine\DBAL\Schema\Column $column)
 {
     $this->table = $parent;
     foreach ($table->getForeignKeys() as $foreign) {
         if (in_array($column->getName(), $foreign->getColumns())) {
             $foreign_columns = $foreign->getForeignColumns();
             $this->foreignTable = $foreign->getForeignTableName();
             $this->foreignColumn = reset($foreign_columns);
             $this->isForeign = true;
         }
     }
     if ($primary_key = $table->getPrimaryKey()) {
         $this->isPrimary = in_array($column->getName(), $primary_key->getColumns());
     }
     $this->name = $column->getName();
     $this->type = $column->getType()->getName();
     $this->length = $column->getLength();
     $this->precision = $column->getPrecision();
     $this->default = $column->getDefault();
     $this->isNotNull = $column->getNotnull();
     $this->isUnsigned = $column->getUnsigned();
     $this->isFixed = $column->getFixed();
     $this->isAutoIncrement = $column->getAutoincrement();
     $this->comment = $column->getComment();
     if ($this->type === \Doctrine\DBAL\Types\Type::BLOB) {
         $this->length = min($this->bytesFromIni('post_max_size'), $this->bytesFromIni('upload_max_filesize'));
     }
 }
Example #3
0
 public function describe($namespace) : array
 {
     if (substr($namespace, -1) != "\\") {
         $namespace .= "\\";
     }
     $tableIdentifier = $this->dbalSchemaTable->getName();
     $methods = ['fetchAll' => $this->describeQueryMethod([], $this->describeQuerySelect('*', $tableIdentifier, []))];
     foreach ($this->dbalSchemaTable->getForeignKeys() as $foreignKeyIdentifier => $foreignKey) {
         $words = explode('_', $foreignKeyIdentifier);
         $camelCased = array_map('ucfirst', $words);
         $foreignKeyMethodIdentifier = join('', $camelCased);
         $where = array_map(function ($methodParameter) {
             return $methodParameter . ' = :' . $methodParameter;
         }, $foreignKey->getLocalColumns());
         $query = $this->describeQuerySelect('*', $tableIdentifier, $where);
         $methods["fetchBy" . $foreignKeyMethodIdentifier] = $this->describeQueryMethod($foreignKey->getLocalColumns(), $query);
     }
     return ['identifier' => $namespace . $this->dbalSchemaTable->getName(), 'properties' => ['columns' => array_keys($this->dbalSchemaTable->getColumns())], 'methods' => $methods];
 }
Example #4
0
 /**
  * @param Schema $schema
  * @param Table $table
  * @param string $keyName
  */
 protected function setOwnerCascadeDelete(Schema $schema, Table $table, $keyName)
 {
     foreach ($table->getForeignKeys() as $foreignKey) {
         if ($foreignKey->getLocalColumns() == ['owner_id']) {
             $table->removeForeignKey($foreignKey->getName());
             $table->addForeignKeyConstraint($schema->getTable('orocrm_contact'), ['owner_id'], ['id'], ['onDelete' => 'CASCADE', 'onUpdate' => null], $keyName);
             break;
         }
     }
 }
Example #5
0
 /**
  * @group DBAL-132
  */
 public function testGenerateForeignKeySQL()
 {
     $tableOld = new Table("test");
     $tableOld->addColumn('foo_id', 'integer');
     $tableOld->addUnnamedForeignKeyConstraint('test_foreign', array('foo_id'), array('foo_id'));
     $sqls = array();
     foreach ($tableOld->getForeignKeys() as $fk) {
         $sqls[] = $this->platform->getCreateForeignKeySQL($fk, $tableOld);
     }
     $this->assertEquals(array("ALTER TABLE test ADD CONSTRAINT FK_D87F7E0C8E48560F FOREIGN KEY (foo_id) REFERENCES test_foreign (foo_id)"), $sqls);
 }
Example #6
0
 /**
  * Convert all the table columns into form elements
  *
  * @return array
  * @throws \Exception
  */
 public function getElements()
 {
     if (!$this->table instanceof Table) {
         throw new \Exception('Table not set');
     }
     $pkColumns = $this->table->getPrimaryKey()->getColumns();
     $elements = [];
     $fks = [];
     $fk = $this->table->getForeignKeys();
     if (!empty($fk)) {
         foreach ($fk as $f) {
             $fks = array_merge($fks, $f->getLocalColumns());
         }
     }
     foreach ($this->table->getColumns() as $column) {
         $isPrimaryKey = in_array($column->getName(), $pkColumns);
         if ($this->helper->isExcluded($column) || $isPrimaryKey) {
             continue;
         }
         $elements[] = $this->mapColumn($column, $fks);
     }
     return $elements;
 }
 public function testEncodedForeignKeyConstraintNameIsTheSameAsDoctrineDefault()
 {
     $tableName1 = 'tbl123456789012345';
     $columnName1 = 'clmn1234567890';
     $tableName2 = 'tbl1234567890';
     $columnName2 = 'clmn12345';
     $table1 = new Table($tableName1, [new Column($columnName1, Type::getType('integer'))]);
     $table2 = new Table($tableName2, [new Column($columnName2, Type::getType('integer'))]);
     $table2->setPrimaryKey([$columnName2]);
     $table1->addForeignKeyConstraint($table2, [$columnName1], [$columnName2]);
     $foreignKeys = $table1->getForeignKeys();
     $doctrineResult = array_pop($foreignKeys)->getName();
     $generator = new DbIdentifierNameGenerator();
     $result = $generator->generateForeignKeyConstraintName($tableName1, [$columnName1]);
     $this->assertEquals($doctrineResult, $result);
 }
Example #8
0
 /**
  * Add a table object to the schema
  *
  * @param Table $table table object to add
  *
  * @return void
  */
 public function addTable(Table $table)
 {
     //echo '<h2>addTable()</h2>';
     try {
         $name = $table->getName();
         $len = strlen($this->xPrefix);
         if (substr_compare($name, $this->xPrefix, 0, $len) === 0) {
             $name = substr($name, $len);
             if (empty($this->tableList) || in_array($name, $this->tableList)) {
                 $idGeneratorType = 0;
                 // how should we handle this?
                 $newtable = new Table($name, $table->getColumns(), $table->getIndexes(), $table->getForeignKeys(), $idGeneratorType, $table->getOptions());
                 $this->_addTable($newtable);
             }
         }
         //Debug::dump($table);
     } catch (\Exception $e) {
         \Xoops::getInstance()->events()->triggerEvent('core.exception', $e);
         throw $e;
     }
 }
Example #9
0
 /**
  * @param \TYPO3\CMS\Core\Database\Schema\Parser\AST\CreateIndexDefinitionItem $item
  * @return \Doctrine\DBAL\Schema\Index
  * @throws \Doctrine\DBAL\Schema\SchemaException
  * @throws \InvalidArgumentException
  */
 protected function addIndex(CreateIndexDefinitionItem $item) : Index
 {
     $indexName = $item->indexName->getQuotedName();
     $columnNames = array_map(function (IndexColumnName $columnName) {
         if ($columnName->length) {
             return $columnName->columnName->getQuotedName() . '(' . $columnName->length . ')';
         }
         return $columnName->columnName->getQuotedName();
     }, $item->columnNames);
     if ($item->isPrimary) {
         $this->table->setPrimaryKey($columnNames);
         $index = $this->table->getPrimaryKey();
     } else {
         $index = GeneralUtility::makeInstance(Index::class, $indexName, $columnNames, $item->isUnique, $item->isPrimary);
         if ($item->isFulltext) {
             $index->addFlag('fulltext');
         } elseif ($item->isSpatial) {
             $index->addFlag('spatial');
         }
         $this->table = GeneralUtility::makeInstance(Table::class, $this->table->getQuotedName($this->platform), $this->table->getColumns(), array_merge($this->table->getIndexes(), [strtolower($indexName) => $index]), $this->table->getForeignKeys(), 0, $this->table->getOptions());
     }
     return $index;
 }
 public function testAddForeignKeyConstraint()
 {
     $table = new Table("foo");
     $table->addColumn("id", 'integer');
     $foreignTable = new Table("bar");
     $foreignTable->addColumn("id", 'integer');
     $table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar"));
     $constraints = $table->getForeignKeys();
     $this->assertEquals(1, count($constraints));
     $constraint = current($constraints);
     $this->assertInstanceOf('Doctrine\\DBAL\\Schema\\ForeignKeyConstraint', $constraint);
     $this->assertTrue($constraint->hasOption("foo"));
     $this->assertEquals("bar", $constraint->getOption("foo"));
 }
Example #11
0
 /**
  * Returns the difference between the tables $table1 and $table2.
  *
  * If there are no differences this method returns the boolean false.
  *
  * @param \Doctrine\DBAL\Schema\Table $table1
  * @param \Doctrine\DBAL\Schema\Table $table2
  *
  * @return boolean|\Doctrine\DBAL\Schema\TableDiff
  */
 public function diffTable(Table $table1, Table $table2)
 {
     $changes = 0;
     $tableDifferences = new TableDiff($table1->getName());
     $tableDifferences->fromTable = $table1;
     $table1Columns = $table1->getColumns();
     $table2Columns = $table2->getColumns();
     /* See if all the fields in table 1 exist in table 2 */
     foreach ($table2Columns as $columnName => $column) {
         if (!$table1->hasColumn($columnName)) {
             $tableDifferences->addedColumns[$columnName] = $column;
             $changes++;
         }
     }
     /* See if there are any removed fields in table 2 */
     foreach ($table1Columns as $columnName => $column) {
         // See if column is removed in table 2.
         if (!$table2->hasColumn($columnName)) {
             $tableDifferences->removedColumns[$columnName] = $column;
             $changes++;
             continue;
         }
         // See if column has changed properties in table 2.
         $changedProperties = $this->diffColumn($column, $table2->getColumn($columnName));
         if (!empty($changedProperties)) {
             $columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties);
             $columnDiff->fromColumn = $column;
             $tableDifferences->changedColumns[$column->getName()] = $columnDiff;
             $changes++;
         }
     }
     // #BUG-2317 Avoid column renaming when both enable and disable different modules
     // $this->detectColumnRenamings($tableDifferences);
     $table1Indexes = $table1->getIndexes();
     $table2Indexes = $table2->getIndexes();
     foreach ($table2Indexes as $index2Name => $index2Definition) {
         foreach ($table1Indexes as $index1Name => $index1Definition) {
             if ($this->diffIndex($index1Definition, $index2Definition) === false) {
                 /*if ( ! $index1Definition->isPrimary() && $index1Name != $index2Name) {
                       $tableDifferences->renamedIndexes[$index1Name] = $index2Definition;
                       $changes++;
                   }*/
                 unset($table1Indexes[$index1Name]);
                 unset($table2Indexes[$index2Name]);
             } else {
                 if ($index1Name == $index2Name) {
                     $tableDifferences->changedIndexes[$index2Name] = $table2Indexes[$index2Name];
                     unset($table1Indexes[$index1Name]);
                     unset($table2Indexes[$index2Name]);
                     $changes++;
                 }
             }
         }
     }
     foreach ($table1Indexes as $index1Name => $index1Definition) {
         $tableDifferences->removedIndexes[$index1Name] = $index1Definition;
         $changes++;
     }
     foreach ($table2Indexes as $index2Name => $index2Definition) {
         $tableDifferences->addedIndexes[$index2Name] = $index2Definition;
         $changes++;
     }
     $fromFkeys = $table1->getForeignKeys();
     $toFkeys = $table2->getForeignKeys();
     foreach ($fromFkeys as $key1 => $constraint1) {
         foreach ($toFkeys as $key2 => $constraint2) {
             if ($this->diffForeignKey($constraint1, $constraint2) === false) {
                 unset($fromFkeys[$key1]);
                 unset($toFkeys[$key2]);
             } else {
                 if (strtolower($constraint1->getName()) == strtolower($constraint2->getName())) {
                     $tableDifferences->changedForeignKeys[] = $constraint2;
                     $changes++;
                     unset($fromFkeys[$key1]);
                     unset($toFkeys[$key2]);
                 }
             }
         }
     }
     foreach ($fromFkeys as $constraint1) {
         $tableDifferences->removedForeignKeys[] = $constraint1;
         $changes++;
     }
     foreach ($toFkeys as $constraint2) {
         $tableDifferences->addedForeignKeys[] = $constraint2;
         $changes++;
     }
     return $changes ? $tableDifferences : false;
 }
Example #12
0
 /**
  * Gathers columns and fk constraints that are required for one part of relationship.
  *
  * @param array         $joinColumns
  * @param Table         $theJoinTable
  * @param ClassMetadata $class
  * @param array         $mapping
  * @param array         $primaryKeyColumns
  * @param array         $addedFks
  * @param array         $blacklistedFks
  *
  * @return void
  *
  * @throws \Doctrine\ORM\ORMException
  */
 private function gatherRelationJoinColumns($joinColumns, $theJoinTable, $class, $mapping, &$primaryKeyColumns, &$addedFks, &$blacklistedFks)
 {
     $localColumns = array();
     $foreignColumns = array();
     $fkOptions = array();
     $foreignTableName = $this->quoteStrategy->getTableName($class, $this->platform);
     $uniqueConstraints = array();
     foreach ($joinColumns as $joinColumn) {
         list($definingClass, $referencedFieldName) = $this->getDefiningClass($class, $joinColumn['referencedColumnName']);
         if (!$definingClass) {
             throw new \Doctrine\ORM\ORMException("Column name `" . $joinColumn['referencedColumnName'] . "` referenced for relation from " . $mapping['sourceEntity'] . " towards " . $mapping['targetEntity'] . " does not exist.");
         }
         $quotedColumnName = $this->quoteStrategy->getJoinColumnName($joinColumn, $class, $this->platform);
         $quotedRefColumnName = $this->quoteStrategy->getReferencedJoinColumnName($joinColumn, $class, $this->platform);
         $primaryKeyColumns[] = $quotedColumnName;
         $localColumns[] = $quotedColumnName;
         $foreignColumns[] = $quotedRefColumnName;
         if (!$theJoinTable->hasColumn($quotedColumnName)) {
             // Only add the column to the table if it does not exist already.
             // It might exist already if the foreign key is mapped into a regular
             // property as well.
             $fieldMapping = $definingClass->getFieldMapping($referencedFieldName);
             $columnDef = null;
             if (isset($joinColumn['columnDefinition'])) {
                 $columnDef = $joinColumn['columnDefinition'];
             } elseif (isset($fieldMapping['columnDefinition'])) {
                 $columnDef = $fieldMapping['columnDefinition'];
             }
             $columnOptions = array('notnull' => false, 'columnDefinition' => $columnDef);
             if (isset($joinColumn['nullable'])) {
                 $columnOptions['notnull'] = !$joinColumn['nullable'];
             }
             if (isset($fieldMapping['options'])) {
                 $columnOptions['options'] = $fieldMapping['options'];
             }
             if ($fieldMapping['type'] == "string" && isset($fieldMapping['length'])) {
                 $columnOptions['length'] = $fieldMapping['length'];
             } elseif ($fieldMapping['type'] == "decimal") {
                 $columnOptions['scale'] = $fieldMapping['scale'];
                 $columnOptions['precision'] = $fieldMapping['precision'];
             }
             $theJoinTable->addColumn($quotedColumnName, $fieldMapping['type'], $columnOptions);
         }
         if (isset($joinColumn['unique']) && $joinColumn['unique'] == true) {
             $uniqueConstraints[] = array('columns' => array($quotedColumnName));
         }
         if (isset($joinColumn['onDelete'])) {
             $fkOptions['onDelete'] = $joinColumn['onDelete'];
         }
     }
     // Prefer unique constraints over implicit simple indexes created for foreign keys.
     // Also avoids index duplication.
     foreach ($uniqueConstraints as $indexName => $unique) {
         $theJoinTable->addUniqueIndex($unique['columns'], is_numeric($indexName) ? null : $indexName);
     }
     $compositeName = $theJoinTable->getName() . '.' . implode('', $localColumns);
     if (isset($addedFks[$compositeName]) && ($foreignTableName != $addedFks[$compositeName]['foreignTableName'] || 0 < count(array_diff($foreignColumns, $addedFks[$compositeName]['foreignColumns'])))) {
         foreach ($theJoinTable->getForeignKeys() as $fkName => $key) {
             if (0 === count(array_diff($key->getLocalColumns(), $localColumns)) && ($key->getForeignTableName() != $foreignTableName || 0 < count(array_diff($key->getForeignColumns(), $foreignColumns)))) {
                 $theJoinTable->removeForeignKey($fkName);
                 break;
             }
         }
         $blacklistedFks[$compositeName] = true;
     } elseif (!isset($blacklistedFks[$compositeName])) {
         $addedFks[$compositeName] = array('foreignTableName' => $foreignTableName, 'foreignColumns' => $foreignColumns);
         $theJoinTable->addUnnamedForeignKeyConstraint($foreignTableName, $localColumns, $foreignColumns, $fkOptions);
     }
 }
Example #13
0
 /**
  * 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);
 }
Example #14
0
 /**
  * Returns the difference between the tables $table1 and $table2.
  *
  * If there are no differences this method returns the boolean false.
  *
  * @param \Doctrine\DBAL\Schema\Table $table1
  * @param \Doctrine\DBAL\Schema\Table $table2
  *
  * @return boolean|\Doctrine\DBAL\Schema\TableDiff
  */
 public function diffTable(Table $table1, Table $table2)
 {
     $changes = 0;
     $tableDifferences = new TableDiff($table1->getName());
     $tableDifferences->fromTable = $table1;
     $table1Columns = $table1->getColumns();
     $table2Columns = $table2->getColumns();
     /* See if all the fields in table 1 exist in table 2 */
     foreach ($table2Columns as $columnName => $column) {
         if (!$table1->hasColumn($columnName)) {
             $tableDifferences->addedColumns[$columnName] = $column;
             $changes++;
         }
     }
     /* See if there are any removed fields in table 2 */
     foreach ($table1Columns as $columnName => $column) {
         // See if column is removed in table 2.
         if (!$table2->hasColumn($columnName)) {
             $tableDifferences->removedColumns[$columnName] = $column;
             $changes++;
             continue;
         }
         // See if column has changed properties in table 2.
         $changedProperties = $this->diffColumn($column, $table2->getColumn($columnName));
         if (!empty($changedProperties)) {
             $columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties);
             $columnDiff->fromColumn = $column;
             $tableDifferences->changedColumns[$column->getName()] = $columnDiff;
             $changes++;
         }
     }
     $this->detectColumnRenamings($tableDifferences);
     $table1Indexes = $table1->getIndexes();
     $table2Indexes = $table2->getIndexes();
     /* See if all the indexes in table 1 exist in table 2 */
     foreach ($table2Indexes as $indexName => $index) {
         if ($index->isPrimary() && $table1->hasPrimaryKey() || $table1->hasIndex($indexName)) {
             continue;
         }
         $tableDifferences->addedIndexes[$indexName] = $index;
         $changes++;
     }
     /* See if there are any removed indexes in table 2 */
     foreach ($table1Indexes as $indexName => $index) {
         // See if index is removed in table 2.
         if ($index->isPrimary() && !$table2->hasPrimaryKey() || !$index->isPrimary() && !$table2->hasIndex($indexName)) {
             $tableDifferences->removedIndexes[$indexName] = $index;
             $changes++;
             continue;
         }
         // See if index has changed in table 2.
         $table2Index = $index->isPrimary() ? $table2->getPrimaryKey() : $table2->getIndex($indexName);
         if ($this->diffIndex($index, $table2Index)) {
             $tableDifferences->changedIndexes[$indexName] = $table2Index;
             $changes++;
         }
     }
     $this->detectIndexRenamings($tableDifferences);
     $fromFkeys = $table1->getForeignKeys();
     $toFkeys = $table2->getForeignKeys();
     foreach ($fromFkeys as $key1 => $constraint1) {
         foreach ($toFkeys as $key2 => $constraint2) {
             if ($this->diffForeignKey($constraint1, $constraint2) === false) {
                 unset($fromFkeys[$key1]);
                 unset($toFkeys[$key2]);
             } else {
                 if (strtolower($constraint1->getName()) == strtolower($constraint2->getName())) {
                     $tableDifferences->changedForeignKeys[] = $constraint2;
                     $changes++;
                     unset($fromFkeys[$key1]);
                     unset($toFkeys[$key2]);
                 }
             }
         }
     }
     foreach ($fromFkeys as $constraint1) {
         $tableDifferences->removedForeignKeys[] = $constraint1;
         $changes++;
     }
     foreach ($toFkeys as $constraint2) {
         $tableDifferences->addedForeignKeys[] = $constraint2;
         $changes++;
     }
     return $changes ? $tableDifferences : false;
 }
Example #15
0
 /**
  * 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->getQuotedName($this);
     $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;
             }
         }
     }
     $columnSql = array();
     $columns = array();
     foreach ($table->getColumns() as $column) {
         /* @var \Doctrine\DBAL\Schema\Column $column */
         if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) {
             $eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this);
             $this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs);
             $columnSql = array_merge($columnSql, $eventArgs->getSql());
             if ($eventArgs->isDefaultPrevented()) {
                 continue;
             }
         }
         $columnData = array();
         $columnData['name'] = $column->getQuotedName($this);
         $columnData['type'] = $column->getType();
         $columnData['length'] = $column->getLength();
         $columnData['notnull'] = $column->getNotNull();
         $columnData['fixed'] = $column->getFixed();
         $columnData['unique'] = false;
         // TODO: what do we do about this?
         $columnData['version'] = $column->hasPlatformOption("version") ? $column->getPlatformOption('version') : false;
         if (strtolower($columnData['type']) == "string" && $columnData['length'] === null) {
             $columnData['length'] = 255;
         }
         $columnData['unsigned'] = $column->getUnsigned();
         $columnData['precision'] = $column->getPrecision();
         $columnData['scale'] = $column->getScale();
         $columnData['default'] = $column->getDefault();
         $columnData['columnDefinition'] = $column->getColumnDefinition();
         $columnData['autoincrement'] = $column->getAutoincrement();
         $columnData['comment'] = $this->getColumnComment($column);
         if (in_array($column->getName(), $options['primary'])) {
             $columnData['primary'] = true;
         }
         $columns[$columnData['name']] = $columnData;
     }
     if (($createFlags & self::CREATE_FOREIGNKEYS) > 0) {
         $options['foreignKeys'] = array();
         foreach ($table->getForeignKeys() as $fkConstraint) {
             $options['foreignKeys'][] = $fkConstraint;
         }
     }
     if (null !== $this->_eventManager && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) {
         $eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this);
         $this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs);
         if ($eventArgs->isDefaultPrevented()) {
             return array_merge($eventArgs->getSql(), $columnSql);
         }
     }
     $sql = $this->_getCreateTableSQL($tableName, $columns, $options);
     if ($this->supportsCommentOnStatement()) {
         foreach ($table->getColumns() as $column) {
             if ($this->getColumnComment($column)) {
                 $sql[] = $this->getCommentOnColumnSQL($tableName, $column->getName(), $this->getColumnComment($column));
             }
         }
     }
     return array_merge($sql, $columnSql);
 }
 /**
  * Retreive schema table definition foreign keys.
  *
  * @param \Doctrine\DBAL\Schema\Table $table
  *
  * @return array
  */
 private function getTableForeignKeys(Table $table)
 {
     return $this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints() ? $table->getForeignKeys() : array();
 }
 /**
  * @param Table $table
  * @return array [Collection, Collection]
  */
 protected function getForeignKeys(Table $table)
 {
     $foreignTables = Collection::make([]);
     $foreignKeyColumns = Collection::make([]);
     Collection::make($table->getForeignKeys())->each(function (ForeignKeyConstraint $key) use($foreignTables, $foreignKeyColumns) {
         if (count($key->getLocalColumns()) != 1) {
             return;
         }
         $column = $key->getLocalColumns()[0];
         $table = $key->getForeignTableName();
         $foreignKeyColumns->put($column, $table);
         if ($foreignTables->has($table)) {
             return;
         }
         $foreignTables->put($table, $this->connection->table($table)->orderBy('id')->lists('name', 'id'));
     });
     return [$foreignKeyColumns, $foreignTables];
 }