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)); }
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)); }
/** * A utility function to create a new id method parameter * from attrib or object and add it to this table. */ public function addIdMethodParameter($impdata) { if ($impdata instanceof IdMethodParameter) { $imp = $impdata; $imp->setTable($this); if ($this->idMethodParameters === null) { $this->idMethodParameters = array(); } $this->idMethodParameters[] = $imp; return $imp; } else { $imp = new IdMethodParameter(); $imp->loadFromXML($impdata); return $this->addIdMethodParameter($imp); // call self w/ diff param } }
/** * 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); }
/** * Adds a new parameter for the strategy that generates primary keys. * * @param IdMethodParameter|array $idMethodParameter * @return IdMethodParameter */ public function addIdMethodParameter($idMethodParameter) { if ($idMethodParameter instanceof IdMethodParameter) { $idMethodParameter->setTable($this); $this->idMethodParameters[] = $idMethodParameter; return $idMethodParameter; } $imp = new IdMethodParameter(); $imp->setTable($this); $imp->loadMapping($idMethodParameter); return $this->addIdMethodParameter($imp); }
/** * Appends the generated <id-method-parameter> XML node to its parent node. * * @param IdMethodParameter $parameter The IdMethodParameter model instance * @param \DOMNode $parentNode The parent DOMNode object */ private function appendIdMethodParameterNode(IdMethodParameter $parameter, \DOMNode $parentNode) { $idMethodParameterNode = $parentNode->appendChild($this->document->createElement('id-method-parameter')); if ($name = $parameter->getName()) { $idMethodParameterNode->setAttribute('name', $name); } $idMethodParameterNode->setAttribute('value', $parameter->getValue()); }