Example #1
0
 public function testCreateNamedIndex()
 {
     $index = new Index('foo_idx');
     $index->setTable($this->getTableMock('db_books'));
     $this->assertEquals('foo_idx', $index->getName());
     $this->assertFalse($index->isUnique());
     $this->assertInstanceOf('Propel\\Generator\\Model\\Table', $index->getTable());
     $this->assertSame('db_books', $index->getTableName());
     $this->assertCount(0, $index->getColumns());
     $this->assertFalse($index->hasColumns());
 }
 /**
  * Builds the DDL SQL to drop an Index.
  *
  * @param  Index  $index
  * @return string
  */
 public function getDropIndexDDL(Index $index)
 {
     $pattern = "\nDROP INDEX %s ON %s;\n";
     return sprintf($pattern, $this->quoteIdentifier($index->getName()), $this->quoteIdentifier($index->getTable()->getName()));
 }
Example #3
0
 /**
  * Builds the DDL SQL to add an Index.
  *
  * @param  Index  $index
  * @return string
  */
 public function getAddIndexDDL(Index $index)
 {
     // don't create index form primary key
     if ($this->getPrimaryKeyName($index->getTable()) == $this->quoteIdentifier($index->getName())) {
         return '';
     }
     $pattern = "\nCREATE %sINDEX %s ON %s (%s)%s;\n";
     return sprintf($pattern, $index->isUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->quoteIdentifier($index->getTable()->getName()), $this->getColumnListDDL($index->getColumnObjects()), $this->generateBlockStorage($index));
 }
Example #4
0
 /**
  * Overrides the implementation from DefaultPlatform
  *
  * @author     Niklas Närhinen <*****@*****.**>
  * @return     string
  * @see        DefaultPlatform::getDropIndexDDL
  */
 public function getDropIndexDDL(Index $index)
 {
     if ($index instanceof Unique) {
         $pattern = "\n    ALTER TABLE %s DROP CONSTRAINT %s;\n    ";
         return sprintf($pattern, $this->quoteIdentifier($index->getTable()->getName()), $this->quoteIdentifier($index->getName()));
     } else {
         return parent::getDropIndexDDL($index);
     }
 }
 /**
  * Returns the DDL SQL to add an Index.
  *
  * @param  Index  $index
  * @return string
  */
 public function getAddIndexDDL(Index $index)
 {
     $pattern = "\nCREATE %sINDEX %s ON %s (%s);\n";
     return sprintf($pattern, $index->isUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->quoteIdentifier($index->getTable()->getName()), $this->getColumnListDDL($index->getColumnObjects()));
 }