/** * @dataProvider provideTableSpecificAttributes * */ public function testCreateDefaultUniqueIndexName($tableName, $maxColumnNameLength, $indexName) { $table = $this->getTableMock($tableName, array('common_name' => $tableName, 'unices' => array(new Unique(), new Unique()), 'database' => $this->getDatabaseMock('bookstore', array('platform' => $this->getPlatformMock(true, array('max_column_name_length' => $maxColumnNameLength)))))); $index = new Unique(); $index->setTable($table); $this->assertTrue($index->isUnique()); $this->assertSame($indexName, $index->getName()); }
/** * @dataProvider provideTableSpecificAttributes * */ public function testCreateDefaultUniqueIndexName($tableName, $maxColumnNameLength, $indexName) { $database = $this->getDatabaseMock('bookstore'); $database->expects($this->any())->method('getMaxColumnNameLength')->will($this->returnValue($maxColumnNameLength)); $table = $this->getTableMock($tableName, ['common_name' => $tableName, 'unices' => [new Unique(), new Unique()], 'database' => $database]); $index = new Unique(); $index->setTable($table); $this->assertTrue($index->isUnique()); $this->assertSame($indexName, $index->getName()); }
public function getUniqueDDL(Unique $unique) { return sprintf('UNIQUE INDEX %s (%s)', $this->quoteIdentifier($unique->getName()), $this->getIndexColumnListDDL($unique)); }
public function getUniqueDDL(Unique $unique) { return sprintf('CONSTRAINT %s UNIQUE (%s)', $this->quoteIdentifier($unique->getName()), $this->getColumnListDDL($unique->getColumnObjects())); }
/** * Adds a new Unique index to the list of unique indices and set the * parent table of the column to the current table. * * @param Unique|array $unique * @return Unique */ public function addUnique($unique) { if ($unique instanceof Unique) { $unique->setTable($this); $unique->getName(); // we call this method so that the name is created now if it doesn't already exist. $this->unices[] = $unique; return $unique; } $unik = new Unique(); $unik->loadMapping($unique); return $this->addUnique($unik); }
/** * Builds the DDL SQL for a Unique constraint object. MS SQL Server CONTRAINT specific * * @param Unique $unique * @return string */ public function getUniqueDDL(Unique $unique) { $pattern = 'CONSTRAINT %s UNIQUE NONCLUSTERED (%s) ON [PRIMARY]'; return sprintf($pattern, $this->quoteIdentifier($unique->getName()), $this->getColumnListDDL($unique->getColumnObjects())); }