Ejemplo n.º 1
0
 public function testGetSequenceNameCustom()
 {
     $table = new Table('foo');
     $table->setIdMethod(IdMethod::NATIVE);
     $idMethodParameter = new IdMethodParameter();
     $idMethodParameter->setValue('foo_sequence');
     $table->addIdMethodParameter($idMethodParameter);
     $table->setIdMethod(IdMethod::NATIVE);
     $expected = 'foo_sequence';
     $this->assertEquals($expected, $this->getPlatform()->getSequenceName($table));
 }
Ejemplo n.º 2
0
 public function testGetDropTableWithSequenceDDL()
 {
     $table = new Table('foo');
     $idMethodParameter = new IdMethodParameter();
     $idMethodParameter->setValue('foo_sequence');
     $table->addIdMethodParameter($idMethodParameter);
     $table->setIdMethod(IdMethod::NATIVE);
     $expected = "\nDROP TABLE IF EXISTS foo CASCADE;\n\nDROP SEQUENCE foo_sequence;\n";
     $this->assertEquals($expected, $this->getPlatform()->getDropTableDDL($table));
 }
Ejemplo n.º 3
0
 /**
  * Searches for tables in the database. Maybe we want to search also the views.
  * @param Database $database The Database model class to add tables to.
  * @param Table[]  $additionalTables
  */
 public function parse(Database $database, array $additionalTables = array())
 {
     $tables = array();
     $stmt = $this->dbh->query("SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE = 'TABLE'");
     $seqPattern = $this->getGeneratorConfig()->get()['database']['adapters']['oracleAutoincrementSequencePattern'];
     // First load the tables (important that this happen before filling out details of tables)
     while ($row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
         if (false !== strpos($row['OBJECT_NAME'], '$')) {
             // this is an Oracle internal table or materialized view - prune
             continue;
         }
         if (strtoupper($row['OBJECT_NAME']) === strtoupper($this->getMigrationTable())) {
             continue;
         }
         $table = new Table($row['OBJECT_NAME']);
         $table->setIdMethod($database->getDefaultIdMethod());
         $database->addTable($table);
         // Add columns, primary keys and indexes.
         $this->addColumns($table);
         $this->addPrimaryKey($table);
         $this->addIndexes($table);
         $pkColumns = $table->getPrimaryKey();
         if (1 === count($pkColumns) && $seqPattern) {
             $seqName = str_replace('${table}', $table->getName(), $seqPattern);
             $seqName = strtoupper($seqName);
             $stmt2 = $this->dbh->query("SELECT * FROM USER_SEQUENCES WHERE SEQUENCE_NAME = '" . $seqName . "'");
             $hasSeq = $stmt2->fetch(\PDO::FETCH_ASSOC);
             if ($hasSeq) {
                 $pkColumns[0]->setAutoIncrement(true);
                 $idMethodParameter = new IdMethodParameter();
                 $idMethodParameter->setValue($seqName);
                 $table->addIdMethodParameter($idMethodParameter);
             }
         }
         $tables[] = $table;
     }
     foreach ($tables as $table) {
         $this->addForeignKeys($table);
     }
     return count($tables);
 }