本文整理汇总了PHP中Doctrine\DBAL\Schema\Table::getIndex方法的典型用法代码示例。如果您正苦于以下问题:PHP Table::getIndex方法的具体用法?PHP Table::getIndex怎么用?PHP Table::getIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\DBAL\Schema\Table
的用法示例。
在下文中一共展示了Table::getIndex方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: fulltext
/**
* Adds a fulltext index to the table
*
* @param array $fields fields
* @param string $name index name
* @return $this
*/
public function fulltext($fields, $name)
{
$this->table->addIndex((array) $fields, $name);
$index = $this->table->getIndex($name);
$index->addFlag('fulltext');
return $this;
}
示例2: testFulltextIndex
public function testFulltextIndex()
{
$table = new Table('fulltext_index');
$table->addColumn('text', 'text');
$table->addIndex(array('text'), 'f_index');
$table->addOption('engine', 'MyISAM');
$index = $table->getIndex('f_index');
$index->addFlag('fulltext');
$this->_sm->dropAndCreateTable($table);
$indexes = $this->_sm->listTableIndexes('fulltext_index');
$this->assertArrayHasKey('f_index', $indexes);
$this->assertTrue($indexes['f_index']->hasFlag('fulltext'));
}
示例3: testSpatialIndex
public function testSpatialIndex()
{
$table = new Table('spatial_index');
$table->addColumn('point', 'point');
$table->addIndex(array('point'), 's_index');
$table->addOption('engine', 'MyISAM');
$index = $table->getIndex('s_index');
$index->addFlag('spatial');
$this->_sm->dropAndCreateTable($table);
$indexes = $this->_sm->listTableIndexes('spatial_index');
$this->assertArrayHasKey('s_index', $indexes);
$this->assertTrue($indexes['s_index']->hasFlag('spatial'));
}
示例4: testAddIndexWithCaseSensitiveColumnProblem
public function testAddIndexWithCaseSensitiveColumnProblem()
{
$table = new Table("foo");
$table->addColumn("id", 'integer');
$table->addIndex(array("ID"), "my_idx");
$this->assertTrue($table->hasIndex('my_idx'));
$this->assertEquals(array("ID"), $table->getIndex("my_idx")->getColumns());
$this->assertTrue($table->getIndex('my_idx')->spansColumns(array('id')));
}
示例5: testCreateTableWithFulltextIndex
public function testCreateTableWithFulltextIndex()
{
$table = new Table('fulltext_table');
$table->addOption('engine', 'MyISAM');
$table->addColumn('text', 'text');
$table->addIndex(array('text'), 'fulltext_text');
$index = $table->getIndex('fulltext_text');
$index->addFlag('fulltext');
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals(array('CREATE TABLE fulltext_table (text LONGTEXT NOT NULL, FULLTEXT INDEX fulltext_text (text)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql);
}
示例6: diffTable
/**
* Returns the difference between the tables $table1 and $table2.
*
* If there are no differences this method returns the boolean false.
*
* @param \Doctrine\DBAL\Schema\Table $table1
* @param \Doctrine\DBAL\Schema\Table $table2
*
* @return boolean|\Doctrine\DBAL\Schema\TableDiff
*/
public function diffTable(Table $table1, Table $table2)
{
$changes = 0;
$tableDifferences = new TableDiff($table1->getName());
$tableDifferences->fromTable = $table1;
$table1Columns = $table1->getColumns();
$table2Columns = $table2->getColumns();
/* See if all the fields in table 1 exist in table 2 */
foreach ($table2Columns as $columnName => $column) {
if (!$table1->hasColumn($columnName)) {
$tableDifferences->addedColumns[$columnName] = $column;
$changes++;
}
}
/* See if there are any removed fields in table 2 */
foreach ($table1Columns as $columnName => $column) {
// See if column is removed in table 2.
if (!$table2->hasColumn($columnName)) {
$tableDifferences->removedColumns[$columnName] = $column;
$changes++;
continue;
}
// See if column has changed properties in table 2.
$changedProperties = $this->diffColumn($column, $table2->getColumn($columnName));
if (!empty($changedProperties)) {
$columnDiff = new ColumnDiff($column->getName(), $table2->getColumn($columnName), $changedProperties);
$columnDiff->fromColumn = $column;
$tableDifferences->changedColumns[$column->getName()] = $columnDiff;
$changes++;
}
}
$this->detectColumnRenamings($tableDifferences);
$table1Indexes = $table1->getIndexes();
$table2Indexes = $table2->getIndexes();
/* See if all the indexes in table 1 exist in table 2 */
foreach ($table2Indexes as $indexName => $index) {
if ($index->isPrimary() && $table1->hasPrimaryKey() || $table1->hasIndex($indexName)) {
continue;
}
$tableDifferences->addedIndexes[$indexName] = $index;
$changes++;
}
/* See if there are any removed indexes in table 2 */
foreach ($table1Indexes as $indexName => $index) {
// See if index is removed in table 2.
if ($index->isPrimary() && !$table2->hasPrimaryKey() || !$index->isPrimary() && !$table2->hasIndex($indexName)) {
$tableDifferences->removedIndexes[$indexName] = $index;
$changes++;
continue;
}
// See if index has changed in table 2.
$table2Index = $index->isPrimary() ? $table2->getPrimaryKey() : $table2->getIndex($indexName);
if ($this->diffIndex($index, $table2Index)) {
$tableDifferences->changedIndexes[$indexName] = $table2Index;
$changes++;
}
}
$this->detectIndexRenamings($tableDifferences);
$fromFkeys = $table1->getForeignKeys();
$toFkeys = $table2->getForeignKeys();
foreach ($fromFkeys as $key1 => $constraint1) {
foreach ($toFkeys as $key2 => $constraint2) {
if ($this->diffForeignKey($constraint1, $constraint2) === false) {
unset($fromFkeys[$key1]);
unset($toFkeys[$key2]);
} else {
if (strtolower($constraint1->getName()) == strtolower($constraint2->getName())) {
$tableDifferences->changedForeignKeys[] = $constraint2;
$changes++;
unset($fromFkeys[$key1]);
unset($toFkeys[$key2]);
}
}
}
}
foreach ($fromFkeys as $constraint1) {
$tableDifferences->removedForeignKeys[] = $constraint1;
$changes++;
}
foreach ($toFkeys as $constraint2) {
$tableDifferences->addedForeignKeys[] = $constraint2;
$changes++;
}
return $changes ? $tableDifferences : false;
}
示例7: testCreateTableWithSpatialIndex
public function testCreateTableWithSpatialIndex()
{
$table = new Table('spatial_table');
$table->addOption('engine', 'MyISAM');
$table->addColumn('point', 'text');
// This should be a point type
$table->addIndex(array('point'), 'spatial_text');
$index = $table->getIndex('spatial_text');
$index->addFlag('spatial');
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals(array('CREATE TABLE spatial_table (point LONGTEXT NOT NULL, SPATIAL INDEX spatial_text (point)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = MyISAM'), $sql);
}
示例8: testNormalizesColumnNames
/**
* @dataProvider getNormalizesAssetNames
* @group DBAL-831
*/
public function testNormalizesColumnNames($assetName)
{
$table = new Table('test');
$table->addColumn($assetName, 'integer');
$table->addIndex(array($assetName), $assetName);
$table->addForeignKeyConstraint('test', array($assetName), array($assetName), array(), $assetName);
$this->assertTrue($table->hasColumn($assetName));
$this->assertTrue($table->hasColumn('foo'));
$this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Column', $table->getColumn($assetName));
$this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Column', $table->getColumn('foo'));
$this->assertTrue($table->hasIndex($assetName));
$this->assertTrue($table->hasIndex('foo'));
$this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Index', $table->getIndex($assetName));
$this->assertInstanceOf('Doctrine\\DBAL\\Schema\\Index', $table->getIndex('foo'));
$this->assertTrue($table->hasForeignKey($assetName));
$this->assertTrue($table->hasForeignKey('foo'));
$this->assertInstanceOf('Doctrine\\DBAL\\Schema\\ForeignKeyConstraint', $table->getForeignKey($assetName));
$this->assertInstanceOf('Doctrine\\DBAL\\Schema\\ForeignKeyConstraint', $table->getForeignKey('foo'));
$table->renameIndex($assetName, $assetName);
$this->assertTrue($table->hasIndex($assetName));
$this->assertTrue($table->hasIndex('foo'));
$table->renameIndex($assetName, 'foo');
$this->assertTrue($table->hasIndex($assetName));
$this->assertTrue($table->hasIndex('foo'));
$table->renameIndex('foo', $assetName);
$this->assertTrue($table->hasIndex($assetName));
$this->assertTrue($table->hasIndex('foo'));
$table->renameIndex($assetName, 'bar');
$this->assertFalse($table->hasIndex($assetName));
$this->assertFalse($table->hasIndex('foo'));
$this->assertTrue($table->hasIndex('bar'));
$table->renameIndex('bar', $assetName);
$table->dropColumn($assetName);
$table->dropIndex($assetName);
$table->removeForeignKey($assetName);
$this->assertFalse($table->hasColumn($assetName));
$this->assertFalse($table->hasColumn('foo'));
$this->assertFalse($table->hasIndex($assetName));
$this->assertFalse($table->hasIndex('foo'));
$this->assertFalse($table->hasForeignKey($assetName));
$this->assertFalse($table->hasForeignKey('foo'));
}
示例9: testAlterTable
public function testAlterTable()
{
$table = new Table('user');
$table->addColumn('id', 'integer');
$table->addColumn('article', 'integer');
$table->addColumn('post', 'integer');
$table->addColumn('parent', 'integer');
$table->setPrimaryKey(array('id'));
$table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true));
$table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true));
$table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true));
$table->addIndex(array('article', 'post'), 'index1');
$diff = new TableDiff('user');
$diff->fromTable = $table;
$diff->newName = 'client';
$diff->renamedColumns['id'] = new \Doctrine\DBAL\Schema\Column('key', \Doctrine\DBAL\Types\Type::getType('integer'), array());
$diff->renamedColumns['post'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array());
$diff->removedColumns['parent'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array());
$diff->removedIndexes['index1'] = $table->getIndex('index1');
$sql = array('DROP INDEX IDX_8D93D64923A0E66', 'DROP INDEX IDX_8D93D6495A8A6C8D', 'DROP INDEX IDX_8D93D6493D8E604F', 'DROP INDEX index1', 'CREATE TEMPORARY TABLE __temp__user AS SELECT id, article, post FROM user', 'DROP TABLE user', 'CREATE TABLE user (' . '"key" INTEGER NOT NULL, article INTEGER NOT NULL, comment INTEGER NOT NULL' . ', PRIMARY KEY("key")' . ', CONSTRAINT FK_8D93D64923A0E66 FOREIGN KEY (article) REFERENCES article (id) DEFERRABLE INITIALLY IMMEDIATE' . ', CONSTRAINT FK_8D93D6495A8A6C8D FOREIGN KEY (comment) REFERENCES post (id) NOT DEFERRABLE INITIALLY DEFERRED' . ')', 'INSERT INTO user ("key", article, comment) SELECT id, article, post FROM __temp__user', 'DROP TABLE __temp__user', 'ALTER TABLE user RENAME TO client', 'CREATE INDEX IDX_8D93D64923A0E66 ON client (article)', 'CREATE INDEX IDX_8D93D6495A8A6C8D ON client (comment)');
$this->assertEquals($sql, $this->_platform->getAlterTableSQL($diff));
}
示例10: testAddForeignKeyIndexImplicitly
/**
* @group DBAL-50
*/
public function testAddForeignKeyIndexImplicitly()
{
$table = new Table("foo");
$table->addColumn("id", 'integer');
$foreignTable = new Table("bar");
$foreignTable->addColumn("id", 'integer');
$table->addForeignKeyConstraint($foreignTable, array("id"), array("id"), array("foo" => "bar"));
$this->assertEquals(1, count($table->getIndexes()));
$this->assertTrue($table->hasIndex("foo_id_idx"));
$this->assertEquals(array('id'), $table->getIndex('foo_id_idx')->getColumns());
}
示例11: index
/**
* Assert that the column is indexed.
*
* @return $this
*/
public function index()
{
$index = $this->getIndexName();
$this->assertTrue($this->table->hasIndex($index), "The {$this->name} column is not indexed.");
$this->assertTrue($this->table->getIndex($index)->isSimpleIndex(), "The {$this->name} column is not a simple index.");
}
示例12: testCreateNonClusteredPrimaryKeyInTable
/**
* @group DBAL-220
*/
public function testCreateNonClusteredPrimaryKeyInTable()
{
$table = new \Doctrine\DBAL\Schema\Table("tbl");
$table->addColumn("id", "integer");
$table->setPrimaryKey(array("id"));
$table->getIndex('primary')->addFlag('nonclustered');
$this->assertEquals(array('CREATE TABLE tbl (id INT NOT NULL, PRIMARY KEY NONCLUSTERED (id))'), $this->_platform->getCreateTableSQL($table));
}