예제 #1
0
 /**
  * @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
 /**
  * Adds Indexes to the specified table.
  *
  * @param Table $table The Table model class to add columns to.
  */
 protected function addIndexes(Table $table)
 {
     $stmt = $this->dbh->query("SELECT COLUMN_NAME, INDEX_NAME FROM USER_IND_COLUMNS WHERE TABLE_NAME = '" . $table->getName() . "' ORDER BY COLUMN_NAME");
     $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC);
     $indices = array();
     foreach ($rows as $row) {
         $indices[$row['INDEX_NAME']][] = $row['COLUMN_NAME'];
     }
     foreach ($indices as $indexName => $columnNames) {
         $index = new Index($indexName);
         foreach ($columnNames as $columnName) {
             // Oracle deals with complex indices using an internal reference, so...
             // let's ignore this kind of index
             if ($table->hasColumn($columnName)) {
                 $index->addColumn($table->getColumn($columnName));
             }
         }
         // since some of the columns are pruned above, we must only add an index if it has columns
         if ($index->hasColumns()) {
             $table->addIndex($index);
         }
     }
 }