コード例 #1
0
ファイル: IndexTest.php プロジェクト: robin850/Propel2
 /**
  * @dataProvider provideColumnDefinitions
  *
  */
 public function testAddIndexedColumns($columns)
 {
     $index = new Index();
     $index->setColumns($columns);
     $this->assertTrue($index->hasColumns());
     $this->assertCount(3, $index->getColumns());
     $this->assertSame(100, $index->getColumnSize('foo'));
     $this->assertTrue($index->hasColumnSize('foo'));
     $this->assertSame(5, $index->getColumnSize('bar'));
     $this->assertTrue($index->hasColumnSize('bar'));
     $this->assertNull($index->getColumnSize('baz'));
 }
コード例 #2
0
ファイル: IndexComparator.php プロジェクト: disider/Propel2
 /**
  * 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();
 }
コード例 #3
0
 /**
  * Creates a comma-separated list of column names for the index.
  * For MySQL unique indexes there is the option of specifying size, so we cannot simply use
  * the getColumnsList() method.
  * @param  Index  $index
  * @return string
  */
 protected function getIndexColumnListDDL(Index $index)
 {
     $list = array();
     foreach ($index->getColumns() as $col) {
         $list[] = $this->quoteIdentifier($col) . ($index->hasColumnSize($col) ? '(' . $index->getColumnSize($col) . ')' : '');
     }
     return implode(', ', $list);
 }
コード例 #4
0
ファイル: XmlDumper.php プロジェクト: SwissalpS/Propel2
 /**
  * Appends a generice <index> or <unique> XML node to its parent node.
  *
  * @param string   $nodeType   The node type (index or unique)
  * @param Index    $index      The Index model instance
  * @param \DOMNode $parentNode The parent DOMNode object
  */
 private function appendGenericIndexNode($nodeType, Index $index, \DOMNode $parentNode)
 {
     $indexNode = $parentNode->appendChild($this->document->createElement($nodeType));
     $indexNode->setAttribute('name', $index->getName());
     foreach ($index->getColumns() as $columnName) {
         $indexColumnNode = $indexNode->appendChild($this->document->createElement($nodeType . '-column'));
         $indexColumnNode->setAttribute('name', $columnName);
         if ($size = $index->getColumnSize($columnName)) {
             $indexColumnNode->setAttribute('size', $size);
         }
     }
     foreach ($index->getVendorInformation() as $vendorInformation) {
         $this->appendVendorInformationNode($vendorInformation, $indexNode);
     }
 }