本文整理汇总了PHP中Doctrine\DBAL\Schema\Index类的典型用法代码示例。如果您正苦于以下问题:PHP Index类的具体用法?PHP Index怎么用?PHP Index使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Index类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: populatePrimaryKey
/**
* Populates a primary key based on a index.
*
* @param Attrs $attrs
* @param Index $index
*/
private function populatePrimaryKey($attrs, $index)
{
if (!$index->isPrimary()) {
return;
}
$columns = $index->getColumns();
$key = current($columns);
// We don't support composite primary keys quite yet.
if (count($columns) > 1) {
return;
}
$attrs->set($this->deriveName($key), ['key' => $key, 'type' => 'primary']);
}
示例2: getCreateSpatialIndexSQL
/**
* Generates the sql to create a spatial index.
*
* @param SpatialIndex $index
* @param Table | string $table
* @return string The sql to create a spatial index on the database.
* @throws \InvalidArgumentException
*/
public function getCreateSpatialIndexSQL(Index $index, $table)
{
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
}
$name = $index->getQuotedName($this);
$columns = $index->getColumns();
if (count($columns) == 0) {
throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
}
$query = 'CREATE INDEX ' . $name . ' ON ' . $table;
$query .= ' USING GIST (' . $this->getIndexFieldDeclarationListSQL($columns) . ')';
return $query;
}
示例3: getSql
public function getSql(Index $index, $table)
{
if ($table instanceof Table) {
$table = $table->getQuotedName($this->platform);
}
$name = $index->getQuotedName($this->platform);
$columns = $index->getQuotedColumns($this->platform);
if (count($columns) == 0) {
throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
}
if ($index->isPrimary()) {
return $this->platform->getCreatePrimaryKeySQL($index, $table);
}
$query = 'CREATE INDEX ' . $name . ' ON ' . $table;
$query .= ' USING gist(' . $this->platform->getIndexFieldDeclarationListSQL($columns) . ')';
return $query;
}
示例4: getAdvancedIndexOptionsSQL
/**
* {@inheritdoc}
*/
protected function getAdvancedIndexOptionsSQL(Index $index)
{
if ($index->hasFlag('with_nulls_distinct') && $index->hasFlag('with_nulls_not_distinct')) {
throw new UnexpectedValueException('An Index can either have a "with_nulls_distinct" or "with_nulls_not_distinct" flag but not both.');
}
if (!$index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_distinct')) {
return ' WITH NULLS DISTINCT' . parent::getAdvancedIndexOptionsSQL($index);
}
return parent::getAdvancedIndexOptionsSQL($index);
}
示例5: indexToArray
/**
* @param string $table
* @param \Doctrine\DBAL\Schema\Index $index
* @return array
*/
protected function indexToArray($table, $index)
{
if ($index->isPrimary()) {
$type = 'primary';
} elseif ($index->isUnique()) {
$type = 'unique';
} else {
$type = 'index';
}
$array = ['type' => $type, 'name' => null, 'columns' => $index->getColumns()];
if (!$this->isDefaultIndexName($table, $index->getName(), $type, $index->getColumns())) {
$array['name'] = $index->getName();
}
return $array;
}
示例6: indexToArray
/**
* @param string $table
* @param \Doctrine\DBAL\Schema\Index $index
* @return array
*/
protected function indexToArray($table, $index)
{
if ($index->isPrimary()) {
$type = 'primary';
} elseif ($index->isUnique()) {
$type = 'unique';
} else {
$type = 'index';
}
$array = ['type' => $type, 'name' => null, 'columns' => $index->getColumns()];
if (!$this->ignoreIndexNames and !$this->isDefaultIndexName($table, $index->getName(), $type, $index->getColumns())) {
// Sent Index name to exclude spaces
$array['name'] = str_replace(' ', '', $index->getName());
}
return $array;
}
示例7: getIndexDeclarationSQL
/**
* Obtains DBMS specific SQL code portion needed to set an index
* declaration to be used in statements like CREATE TABLE.
*
* @param string $name The name of the index.
* @param \Doctrine\DBAL\Schema\Index $index The index definition.
*
* @return string DBMS specific SQL code portion needed to set an index.
*
* @throws \InvalidArgumentException
*/
public function getIndexDeclarationSQL($name, Index $index)
{
$columns = $index->getQuotedColumns($this);
if (count($columns) === 0) {
throw new \InvalidArgumentException("Incomplete definition. 'columns' required.");
}
return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' (' . $this->getIndexFieldDeclarationListSQL($columns) . ')' . $this->getPartialIndexSQL($index);
}
示例8: _appendUniqueConstraintDefinition
/**
* Extend unique key constraint with required filters
*
* @param string $sql
* @param \Doctrine\DBAL\Schema\Index $index
*
* @return string
*/
private function _appendUniqueConstraintDefinition($sql, Index $index)
{
$fields = array();
foreach ($index->getQuotedColumns($this) as $field) {
$fields[] = $field . ' IS NOT NULL';
}
return $sql . ' WHERE ' . implode(' AND ', $fields);
}
示例9: checkIndex
/**
* Do checks for indexes.
*
* @param Index $index
* @param IgnoredChange $ignoredChange
*
* @return boolean
*/
protected function checkIndex(Index $index, IgnoredChange $ignoredChange)
{
// Not needed to be implemented yet
if ($ignoredChange->getPropertyName() !== $index->getName()) {
return false;
}
return false;
}
示例10: dropAndCreateIndex
/**
* Drops and creates a new index on a table.
*
* @param \Doctrine\DBAL\Schema\Index $index
* @param \Doctrine\DBAL\Schema\Table|string $table The name of the table on which the index is to be created.
*
* @return void
*/
public function dropAndCreateIndex(Index $index, $table)
{
$this->tryMethod('dropIndex', $index->getQuotedName($this->_platform), $table);
$this->createIndex($index, $table);
}
示例11: getCreateIndexSQLFlags
/**
* {@inheritdoc}
*/
protected function getCreateIndexSQLFlags(Index $index)
{
$type = '';
if ($index->hasFlag('virtual')) {
$type .= 'VIRTUAL ';
}
if ($index->isUnique()) {
$type .= 'UNIQUE ';
}
if ($index->hasFlag('clustered')) {
$type .= 'CLUSTERED ';
}
return $type;
}
示例12: _addIndex
/**
* Adds an index to the table.
*
* @param Index $indexCandidate
*
* @return self
*
* @throws SchemaException
*/
protected function _addIndex(Index $indexCandidate)
{
$indexName = $indexCandidate->getName();
$indexName = $this->normalizeIdentifier($indexName);
$replacedImplicitIndexes = array();
foreach ($this->implicitIndexes as $name => $implicitIndex) {
if ($implicitIndex->isFullfilledBy($indexCandidate) && isset($this->_indexes[$name])) {
$replacedImplicitIndexes[] = $name;
}
}
if (isset($this->_indexes[$indexName]) && !in_array($indexName, $replacedImplicitIndexes, true) || $this->_primaryKeyName != false && $indexCandidate->isPrimary()) {
throw SchemaException::indexAlreadyExists($indexName, $this->_name);
}
foreach ($replacedImplicitIndexes as $name) {
unset($this->_indexes[$name], $this->implicitIndexes[$name]);
}
if ($indexCandidate->isPrimary()) {
$this->_primaryKeyName = $indexName;
}
$this->_indexes[$indexName] = $indexCandidate;
return $this;
}
示例13: saveIndex
/**
* @param Index $index
* @param \SimpleXMLElement $xml
*/
private static function saveIndex($index, $xml)
{
$xml->addChild('name', $index->getName());
if ($index->isPrimary()) {
$xml->addChild('primary', 'true');
} elseif ($index->isUnique()) {
$xml->addChild('unique', 'true');
}
foreach ($index->getColumns() as $column) {
$field = $xml->addChild('field');
$field->addChild('name', $column);
$field->addChild('sorting', 'ascending');
}
}
示例14: getRenameIndexSQL
/**
* {@inheritdoc}
*/
protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName)
{
if (strpos($tableName, '.') !== false) {
list($schema) = explode('.', $tableName);
$oldIndexName = $schema . '.' . $oldIndexName;
}
return array('ALTER INDEX ' . $oldIndexName . ' RENAME TO ' . $index->getQuotedName($this));
}
示例15: getCreateIndexSQLFlags
/**
* {@inheritDoc}
*/
protected function getCreateIndexSQLFlags(Index $index)
{
$type = '';
if ($index->isUnique()) {
$type .= 'UNIQUE ';
} elseif ($index->hasFlag('fulltext')) {
$type .= 'FULLTEXT ';
} elseif ($index->hasFlag('spatial')) {
$type .= 'SPATIAL ';
}
return $type;
}