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)); }
/** * 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. */ public function parse(Database $database) { $tables = array(); $stmt = $this->dbh->query("SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE = 'TABLE'"); $seqPattern = $this->getGeneratorConfig()->getBuildProperty('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); }
public function testGetDropTableWithSequenceDDL() { $table = new Table('foo'); $idMethodParameter = new IdMethodParameter(); $idMethodParameter->setValue('foo_sequence'); $table->addIdMethodParameter($idMethodParameter); $table->setIdMethod(IDMethod::NATIVE); $expected = "\nDROP TABLE foo CASCADE CONSTRAINTS;\n\nDROP SEQUENCE foo_sequence;\n"; $this->assertEquals($expected, $this->getPlatform()->getDropTableDDL($table)); }
public function testGetDropTableWithSequenceDDL() { $table = new Table('foo'); $idMethodParameter = new IdMethodParameter(); $idMethodParameter->setValue('foo_sequence'); $table->addIdMethodParameter($idMethodParameter); $table->setIdMethod(IDMethod::NATIVE); $expected = ' DROP TABLE IF EXISTS "foo" CASCADE; DROP SEQUENCE "foo_sequence"; '; $this->assertEquals($expected, $this->getPlatform()->getDropTableDDL($table)); }