コード例 #1
0
ファイル: ProxyAdapterTest.php プロジェクト: askzap/ultimate
 public function testProxyAdapterCanInvertAddIndex()
 {
     $table = new \Phinx\Db\Table('atable');
     $index = new \Phinx\Db\Table\Index();
     $index->setType(\Phinx\Db\Table\Index::INDEX)->setColumns(array('email'));
     $this->adapter->addIndex($table, $index);
     $commands = $this->adapter->getInvertedCommands();
     $this->assertEquals('dropIndex', $commands[0]['name']);
     $this->assertEquals('atable', $commands[0]['arguments'][0]);
     $this->assertContains('email', $commands[0]['arguments'][1]);
 }
コード例 #2
0
ファイル: SqlServerAdapter.php プロジェクト: lhas/pep
 /**
  * Gets the SqlServer Index Definition for an Index object.
  *
  * @param Index $index Index
  * @return string
  */
 protected function getIndexSqlDefinition(Index $index, $tableName)
 {
     if (is_string($index->getName())) {
         $indexName = $index->getName();
     } else {
         $columnNames = $index->getColumns();
         if (is_string($columnNames)) {
             $columnNames = array($columnNames);
         }
         $indexName = sprintf('%s_%s', $tableName, implode('_', $columnNames));
     }
     $def = sprintf("CREATE %s INDEX %s ON %s (%s);", $index->getType() === Index::UNIQUE ? 'UNIQUE' : '', $indexName, $this->quoteTableName($tableName), '[' . implode('],[', $index->getColumns()) . ']');
     return $def;
 }
コード例 #3
0
ファイル: MysqlAdapter.php プロジェクト: parkerj/eduTrac-SIS
 /**
  * Gets the MySQL Index Definition for an Index object.
  *
  * @param Index $index Index
  * @return string
  */
 protected function getIndexSqlDefinition(Index $index)
 {
     $def = '';
     $limit = '';
     if ($index->getLimit()) {
         $limit = '(' . $index->getLimit() . ')';
     }
     if ($index->getType() == Index::UNIQUE) {
         $def .= ' UNIQUE';
     }
     if ($index->getType() == Index::FULLTEXT) {
         $def .= ' FULLTEXT';
     }
     $def .= ' KEY';
     if (is_string($index->getName())) {
         $def .= ' `' . $index->getName() . '`';
     }
     $def .= ' (`' . implode('`,`', $index->getColumns()) . '`' . $limit . ')';
     return $def;
 }
コード例 #4
0
 /**
  * Gets the PostgreSQL Index Definition for an Index object.
  *
  * @param Index  $index Index
  * @param string $tableName Table name
  * @return string
  */
 protected function getIndexSqlDefinition(Index $index, $tableName)
 {
     $def = sprintf("CREATE %s INDEX %s ON %s (%s);", $index->getType() == Index::UNIQUE ? 'UNIQUE' : '', $this->getIndexName($tableName, $index->getColumns()), $this->quoteTableName($tableName), implode(',', $index->getColumns()));
     return $def;
 }
コード例 #5
0
ファイル: Table.php プロジェクト: stephenorr/phinx
 /**
  * Add an index to a database table.
  *
  * In $options you can specific unique = true/false or name (index name).
  *
  * @param string|array|Index $columns Table Column(s)
  * @param array $options Index Options
  * @return Table
  */
 public function addIndex($columns, $options = array())
 {
     // create a new index object if strings or an array of strings were supplied
     if (!$columns instanceof Index) {
         $index = new Index();
         if (is_string($columns)) {
             $columns = array($columns);
             // str to array
         }
         $index->setColumns($columns);
         $index->setOptions($options);
     } else {
         $index = $columns;
     }
     $this->indexes[] = $index;
     return $this;
 }
コード例 #6
0
 /**
  * Gets the MySQL Index Definition for an Index object.
  *
  * @param Index $index Index
  * @return string
  */
 protected function getIndexSqlDefinition(Index $index)
 {
     $def = '';
     if ($index->getType() == Index::UNIQUE) {
         $def .= ' UNIQUE KEY (`' . implode('`,`', $index->getColumns()) . '`)';
     } else {
         $def .= ' KEY (`' . implode('`,`', $index->getColumns()) . '`)';
     }
     return $def;
 }
コード例 #7
0
ファイル: SQLiteAdapter.php プロジェクト: elliotwms/phinx
 /**
  * Gets the SQLite Index Definition for an Index object.
  *
  * @param Index $index Index
  * @return string
  */
 protected function getIndexSqlDefinition(Table $table, Index $index)
 {
     if ($index->getType() == Index::UNIQUE) {
         $def = 'UNIQUE INDEX';
     } else {
         $def = 'INDEX';
     }
     if (is_string($index->getName())) {
         $indexName = $index->getName();
     } else {
         $indexName = $table->getName() . '_';
         foreach ($index->getColumns() as $column) {
             $indexName .= $column . '_';
         }
         $indexName .= 'index';
     }
     $def .= ' `' . $indexName . '`';
     return $def;
 }
コード例 #8
0
 /**
  * Utility method that maps an array of index options to this objects methods.
  *
  * @param array $options Options
  *
  * @throws \RuntimeException
  * @return $this
  */
 public function setOptions(array $options)
 {
     $this->index->setOptions($options);
     return $this;
 }
コード例 #9
0
ファイル: IndexTest.php プロジェクト: liammartens/xtend
 /**
  * @expectedException \RuntimeException
  * @expectedExceptionMessage "0" is not a valid index option.
  */
 public function testSetOptionThrowsExceptionIfOptionIsNotString()
 {
     $column = new Index();
     $column->setOptions(['type']);
 }