예제 #1
0
 /**
  * @dataProvider provideTableSpecificAttributes
  *
  */
 public function testCreateDefaultIndexName($tableName, $maxColumnNameLength, $indexName)
 {
     $table = $this->getTableMock($tableName, array('common_name' => $tableName, 'indices' => array(new Index(), new Index()), 'database' => $this->getDatabaseMock('bookstore', array('platform' => $this->getPlatformMock(true, array('max_column_name_length' => $maxColumnNameLength))))));
     $index = new Index();
     $index->setTable($table);
     $this->assertSame($indexName, $index->getName());
 }
예제 #2
0
 /**
  * @dataProvider provideTableSpecificAttributes
  *
  */
 public function testCreateDefaultIndexName($tableName, $maxColumnNameLength, $indexName)
 {
     $database = $this->getDatabaseMock('bookstore');
     $database->expects($this->any())->method('getMaxColumnNameLength')->will($this->returnValue($maxColumnNameLength));
     $table = $this->getTableMock($tableName, ['common_name' => $tableName, 'indices' => [new Index(), new Index()], 'database' => $database]);
     $index = new Index();
     $index->setTable($table);
     $this->assertSame($indexName, $index->getName());
 }
 /**
  * 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()));
 }
예제 #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));
 }
예제 #5
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);
     }
 }
 /**
  * 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()));
 }
예제 #7
0
파일: Table.php 프로젝트: disider/Propel2
 /**
  * Adds a new index to the indices list and set the
  * parent table of the column to the current table.
  *
  * @param  Index|array $index
  * @return Index
  *
  * @throw  InvalidArgumentException
  */
 public function addIndex($index)
 {
     if ($index instanceof Index) {
         if ($this->hasIndex($index->getName())) {
             throw new InvalidArgumentException(sprintf('Index "%s" already exist.', $index->getName()));
         }
         if (!$index->getColumns()) {
             throw new InvalidArgumentException(sprintf('Index "%s" has no columns.', $index->getName()));
         }
         $index->setTable($this);
         // force the name to be created if empty.
         $this->indices[] = $index;
         return $index;
     }
     $idx = new Index();
     $idx->loadMapping($index);
     foreach ((array) @$index['columns'] as $column) {
         $idx->addColumn($column);
     }
     return $this->addIndex($idx);
 }
예제 #8
0
파일: Table.php 프로젝트: robin850/Propel2
 /**
  * Adds a new index to the indices list and set the
  * parent table of the column to the current table.
  *
  * @param  Index $index
  * @return Index
  */
 public function addIndex($index)
 {
     if ($index instanceof Index) {
         $index->setTable($this);
         // force the name to be created if empty.
         $index->getName();
         $this->indices[] = $index;
         return $index;
     }
     $idx = new Index();
     $idx->loadMapping($index);
     return $this->addIndex($idx);
 }
예제 #9
0
 /**
  * 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);
     }
 }