/**
  * Gets all queries collected so far.
  *
  * @return array
  */
 public function getQueries()
 {
     $sql = array();
     foreach (array_keys($this->createTableQueries) as $namespace) {
         if ($this->platform->supportsSchemas() && $this->platform->schemaNeedsCreation($namespace)) {
             $query = $this->platform->getCreateSchemaSQL($namespace);
             array_push($sql, $query);
         }
     }
     foreach ($this->createTableQueries as $schemaSql) {
         $sql = array_merge($sql, $schemaSql);
     }
     foreach ($this->createSequenceQueries as $schemaSql) {
         $sql = array_merge($sql, $schemaSql);
     }
     foreach ($this->createFkConstraintQueries as $schemaSql) {
         $sql = array_merge($sql, $schemaSql);
     }
     return $sql;
 }
Esempio n. 2
0
 /**
  * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform
  * @param boolean                                   $saveMode
  *
  * @return array
  */
 protected function _toSql(AbstractPlatform $platform, $saveMode = false)
 {
     $sql = array();
     if ($platform->supportsSchemas()) {
         foreach ($this->newNamespaces as $newNamespace) {
             $sql[] = $platform->getCreateSchemaSQL($newNamespace);
         }
     }
     if ($platform->supportsForeignKeyConstraints() && $saveMode == false) {
         foreach ($this->orphanedForeignKeys as $orphanedForeignKey) {
             $sql[] = $platform->getDropForeignKeySQL($orphanedForeignKey, $orphanedForeignKey->getLocalTableName());
         }
     }
     if ($platform->supportsSequences() == true) {
         foreach ($this->changedSequences as $sequence) {
             $sql[] = $platform->getAlterSequenceSQL($sequence);
         }
         if ($saveMode === false) {
             foreach ($this->removedSequences as $sequence) {
                 $sql[] = $platform->getDropSequenceSQL($sequence);
             }
         }
         foreach ($this->newSequences as $sequence) {
             $sql[] = $platform->getCreateSequenceSQL($sequence);
         }
     }
     $foreignKeySql = array();
     foreach ($this->newTables as $table) {
         $sql = array_merge($sql, $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES));
         if ($platform->supportsForeignKeyConstraints()) {
             foreach ($table->getForeignKeys() as $foreignKey) {
                 $foreignKeySql[] = $platform->getCreateForeignKeySQL($foreignKey, $table);
             }
         }
     }
     $sql = array_merge($sql, $foreignKeySql);
     if ($saveMode === false) {
         foreach ($this->removedTables as $table) {
             $sql[] = $platform->getDropTableSQL($table);
         }
     }
     foreach ($this->changedTables as $tableDiff) {
         $sql = array_merge($sql, $platform->getAlterTableSQL($tableDiff));
     }
     return $sql;
 }
 /**
  * {@inheritdoc}
  */
 public function acceptNamespace($namespaceName)
 {
     if ($this->platform->supportsSchemas()) {
         $this->createNamespaceQueries[] = $this->platform->getCreateSchemaSQL($namespaceName);
     }
 }
 /**
  * {@inheritdoc}
  */
 public function acceptNamespace($namespaceName)
 {
     if ($this->platform->supportsSchemas()) {
         $this->createNamespaceQueries = array_merge($this->createNamespaceQueries, (array) $this->platform->getCreateSchemaSQL($namespaceName));
     }
 }
 /**
  * @expectedException \Doctrine\DBAL\DBALException
  */
 public function testGetCreateSchemaSQL()
 {
     $this->_platform->getCreateSchemaSQL('schema');
 }