예제 #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());
 }
예제 #2
0
 /**
  * Computes the difference between two index objects.
  *
  * @param  Index   $fromIndex
  * @param  Index   $toIndex
  * @param  boolean $caseInsensitive
  * @return boolean
  */
 public static function computeDiff(Index $fromIndex, Index $toIndex, $caseInsensitive = false)
 {
     // Check for removed index columns in $toIndex
     $fromIndexColumns = $fromIndex->getColumns();
     $max = count($fromIndexColumns);
     for ($i = 0; $i < $max; $i++) {
         $indexColumn = $fromIndexColumns[$i];
         if (!$toIndex->hasColumnAtPosition($i, $indexColumn, $fromIndex->getColumnSize($indexColumn), $caseInsensitive)) {
             return true;
         }
     }
     // Check for new index columns in $toIndex
     $toIndexColumns = $toIndex->getColumns();
     $max = count($toIndexColumns);
     for ($i = 0; $i < $max; $i++) {
         $indexColumn = $toIndexColumns[$i];
         if (!$fromIndex->hasColumnAtPosition($i, $indexColumn, $toIndex->getColumnSize($indexColumn), $caseInsensitive)) {
             return true;
         }
     }
     // Check for difference in unicity
     return $fromIndex->isUnique() !== $toIndex->isUnique();
 }
 protected function getIndexType(Index $index)
 {
     $type = '';
     $vendorInfo = $index->getVendorInfoForType($this->getDatabaseType());
     if ($vendorInfo && $vendorInfo->getParameter('Index_type')) {
         $type = $vendorInfo->getParameter('Index_type') . ' ';
     } elseif ($index->isUnique()) {
         $type = 'UNIQUE ';
     }
     return $type;
 }
예제 #4
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));
 }
 /**
  * Builds the DDL SQL for an Index object.
  *
  * @param  Index  $index
  * @return string
  */
 public function getIndexDDL(Index $index)
 {
     return sprintf('%sINDEX %s (%s)', $index->isUnique() ? 'UNIQUE ' : '', $this->quoteIdentifier($index->getName()), $this->getColumnListDDL($index->getColumnObjects()));
 }