/** * @group DDC-1657 */ public function testIsAutoincrementFor() { $table = new Table("foo"); $table->addColumn("id", "integer", array("autoincrement" => true)); $table->setPrimaryKey(array("id")); $sequence = new Sequence("foo_id_seq"); $sequence2 = new Sequence("bar_id_seq"); $sequence3 = new Sequence("other.foo_id_seq"); $this->assertTrue($sequence->isAutoIncrementsFor($table)); $this->assertFalse($sequence2->isAutoIncrementsFor($table)); $this->assertFalse($sequence3->isAutoIncrementsFor($table)); }
/** * Cache definition for sequences * * @param Sequence $sequence * * @return string */ private function getSequenceCacheSQL(Sequence $sequence) { if ($sequence->getCache() > 1) { return ' CACHE ' . $sequence->getCache(); } return ''; }
/** * @param \Doctrine\DBAL\Schema\Sequence $sequence * * @return void * * @throws \Doctrine\DBAL\Schema\SchemaException */ protected function _addSequence(Sequence $sequence) { $seqName = $sequence->getFullQualifiedName($this->getName()); if (isset($this->_sequences[$seqName])) { throw SchemaException::sequenceAlreadyExists($seqName); } $this->_sequences[$seqName] = $sequence; }
/** * Drops and create a new sequence. * * @param \Doctrine\DBAL\Schema\Sequence $sequence * * @return void * * @throws \Doctrine\DBAL\ConnectionException If something fails at database level. */ public function dropAndCreateSequence(Sequence $sequence) { $this->tryMethod('dropSequence', $sequence->getQuotedName($this->_platform)); $this->createSequence($sequence); }
/** * Cache definition for sequences * * @param Sequence $sequence * * @return string */ private function getSequenceCacheSQL(Sequence $sequence) { if ($sequence->getCache() === 0) { return ' NOCACHE'; } else { if ($sequence->getCache() === 1) { return ' NOCACHE'; } else { if ($sequence->getCache() > 1) { return ' CACHE ' . $sequence->getCache(); } } } return ''; }
/** * @param \Doctrine\DBAL\Schema\Sequence $sequence1 * @param \Doctrine\DBAL\Schema\Sequence $sequence2 * * @return boolean */ public function diffSequence(Sequence $sequence1, Sequence $sequence2) { if ($sequence1->getAllocationSize() != $sequence2->getAllocationSize()) { return true; } if ($sequence1->getInitialValue() != $sequence2->getInitialValue()) { return true; } return false; }
/** * @param \Doctrine\DBAL\Schema\Schema $schema * @param \Doctrine\DBAL\Schema\Sequence $sequence * * @return boolean */ private function isAutoIncrementSequenceInSchema($schema, $sequence) { foreach ($schema->getTables() as $table) { if ($sequence->isAutoIncrementsFor($table)) { return true; } } return false; }
/** * @param Sequence $sequence */ public function acceptSequence(Sequence $sequence) { $this->_sequences[] = $this->_platform->getDropSequenceSQL($sequence->getQuotedName($this->_platform)); }
public function testReturnsSequenceSQL() { $sequence = new Sequence('test_seq', 1, 10); $this->assertEquals('CREATE SEQUENCE ' . $sequence->getQuotedName($this->_platform) . ' START WITH ' . $sequence->getInitialValue() . ' INCREMENT BY ' . $sequence->getAllocationSize() . ' MINVALUE ' . $sequence->getInitialValue(), $this->_platform->getCreateSequenceSQL($sequence)); $this->assertEquals('ALTER SEQUENCE ' . $sequence->getQuotedName($this->_platform) . ' INCREMENT BY ' . $sequence->getAllocationSize(), $this->_platform->getAlterSequenceSQL($sequence)); $this->assertEquals('DROP SEQUENCE ' . $sequence->getName(), $this->_platform->getDropSequenceSQL($sequence)); $this->assertEquals('DROP SEQUENCE ' . $sequence->getName(), $this->_platform->getDropSequenceSQL($sequence->getName())); }
/** * {@inheritdoc} */ public function acceptSequence(Sequence $sequence) { if (!$sequence->isInDefaultNamespace($this->schema->getName())) { $this->schema->dropSequence($sequence->getName()); } }
/** * @param \Doctrine\DBAL\Schema\Sequence $sequence * * @return void * * @throws \Doctrine\DBAL\Schema\SchemaException */ protected function _addSequence(Sequence $sequence) { $namespaceName = $sequence->getNamespaceName(); $seqName = $sequence->getFullQualifiedName($this->getName()); if (isset($this->_sequences[$seqName])) { throw SchemaException::sequenceAlreadyExists($seqName); } if (!$sequence->isInDefaultNamespace($this->getName()) && !$this->hasNamespace($namespaceName)) { $this->createNamespace($namespaceName); } $this->_sequences[$seqName] = $sequence; }
/** * @param Sequence $sequence */ public function acceptSequence(Sequence $sequence) { $this->_sequences[] = $this->_platform->getDropSequenceSql($sequence->getName()); }
/** * {@inheritDoc} * * Need to specifiy minvalue, since start with is hidden in the system and MINVALUE <= START WITH. * Therefore we can use MINVALUE to be able to get a hint what START WITH was for later introspection * in {@see listSequences()} */ public function getCreateSequenceSQL(Sequence $sequence) { return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) . ' START WITH ' . $sequence->getInitialValue() . ' MINVALUE ' . $sequence->getInitialValue() . ' INCREMENT BY ' . $sequence->getAllocationSize() . $this->getSequenceCacheSQL($sequence); }
/** * {@inheritDoc} */ public function getAlterSequenceSQL(Sequence $sequence) { return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) . ' INCREMENT BY ' . $sequence->getAllocationSize() . $this->getSequenceCacheSQL($sequence); }
public function getAlterSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) { return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) . ' INCREMENT BY ' . $sequence->getAllocationSize(); }
/** * Cache definition for sequences * * @return string */ private function getSequenceCacheSQL(\Doctrine\DBAL\Schema\Sequence $sequence) { if ($sequence->getCache() > 1) { return ' CACHE ' . $sequence->getCache(); } return ''; }
/** * Gets the SQL used to create a sequence that starts with a given value * and increments by the given allocation size. * * Need to specifiy minvalue, since start with is hidden in the system and MINVALUE <= START WITH. * Therefore we can use MINVALUE to be able to get a hint what START WITH was for later introspection * in {@see listSequences()} * * @param \Doctrine\DBAL\Schema\Sequence $sequence * @return string */ public function getCreateSequenceSQL(\Doctrine\DBAL\Schema\Sequence $sequence) { return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) . ' START WITH ' . $sequence->getInitialValue() . ' MINVALUE ' . $sequence->getInitialValue() . ' INCREMENT BY ' . $sequence->getAllocationSize(); }
/** * Accept an sequence * * @param Sequence $sequence a sequence object * * @return void */ public function acceptSequence(Sequence $sequence) { $this->schemaArray['sequence'][$sequence->getName()] = array('name' => $sequence->getName(), 'allocationsize' => $sequence->getAllocationSize(), 'initialvalue' => $sequence->getInitialValue()); }