Add column index by type.

@param \CsvMigrations\FieldHandlers\DbField $dbField DbField object
@param string $type Index type
@param bool $exists Table exists flag
@return bool
514671
private function addIndex(DbField $dbField, string $type, bool $exists = true) : bool
    {
        if (empty($type)) {
            return false;
        }

        // skip if table exists and has specified index
        if ($exists && $this->table->hasIndex($dbField->getName())) {
            return false;
        }

        $options = [];
        $options['name'] = $type . '_' . $dbField->getName();
        if ('unique' === $type) {
            $options['unique'] = true;
        }

        $this->table->addIndex($dbField->getName(), $options);

        return true;
    }
445705
protected function indexCommand($type, $columns, $index)
    {
        $columns = (array) $columns;

        // If no name was specified for this index, we will create one using a basic
        // convention of the table name, followed by the columns, followed by an
        // index type, such as primary or index, which makes the index unique.
        if (is_null($index)) {
            $index = $this->createIndexName($type, $columns);
        }

        return $this->addCommand($type, compact('index', 'columns'));
    }
1205085
protected function _alter_table($alter_type, $table, $field)
 	{
		if (in_array($alter_type, array('DROP', 'ADD'), TRUE))
		{
			return parent::_alter_table($alter_type, $table, $field);
		}

		$sql = 'ALTER TABLE '.$this->db->escape_identifiers($table);
		$sqls = array();
		for ($i = 0, $c = count($field); $i < $c; $i++)
		{
			if ($field[$i]['_literal'] !== FALSE)
			{
				return FALSE;
			}

			if (version_compare($this->db->version(), '8', '>=') && isset($field[$i]['type']))
			{
				$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
					.' TYPE '.$field[$i]['type'].$field[$i]['length'];
			}

			if ( ! empty($field[$i]['default']))
			{
				$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
					.' SET DEFAULT '.$field[$i]['default'];
			}

			if (isset($field[$i]['null']))
			{
				$sqls[] = $sql.' ALTER COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
					.($field[$i]['null'] === TRUE ? ' DROP NOT NULL' : ' SET NOT NULL');
			}

			if ( ! empty($field[$i]['new_name']))
			{
				$sqls[] = $sql.' RENAME COLUMN '.$this->db->escape_identifiers($field[$i]['name'])
					.' TO '.$this->db->escape_identifiers($field[$i]['new_name']);
			}

			if ( ! empty($field[$i]['comment']))
			{
				$sqls[] = 'COMMENT ON COLUMN '
					.$this->db->escape_identifiers($table).'.'.$this->db->escape_identifiers($field[$i]['name'])
					.' IS '.$field[$i]['comment'];
			}
		}

		return $sqls;
 	}
633982
public void add(Rec fieldList) throws DBException
    {
        if (this.getBaseRecord() == fieldList)    // If so, set the correct record for write
            fieldList = this.moveToCurrentRecord((Record)fieldList);   // Hopefully, they supplied a default record type and this will switch it.
        if (fieldList == null)
            throw new DBException("Unknown shared record type");
        if (fieldList == this.getBaseRecord())
            super.add(fieldList);
        else
        {
            this.getBaseRecord().matchListeners((Record)fieldList, false, true, true, true, true);      // Clone the listeners that are not there already.
            fieldList.getTable().add(fieldList);
        }
    }
523049
public function addSimpleSelectFieldsAsAlias($field, $alias, $table = false): self
    {
        if (!$table) {
            $table = $this->getDbTableName();
        }
        // Translation field
        if (\in_array($field, $this->getTranslationFields(), true)) {
            ++$this->translation_join_count;
            $this->addJoinTable(['cms_translations', $this->getTranslationTableJoinAlias() . $this->translation_join_count], 'id', $field, 'LEFT', $table);

            $this->sql_select_fields[] = [
                'table' => $this->getTranslationTableJoinAlias() . $this->translation_join_count . '',
                'field' => $this->getLanguage(),
                'as'    => $alias,
                'type'  => TableStructure::FIELD_TYPE_TRANSLATION
            ];
        } else {
            $this->sql_select_fields[] = [
                'table' => $table,
                'field' => $field,
                'as'    => $alias,
                'type'  => 'simple'
            ];
        }

        return $this;
    }
499383
public function addIndex($type, $columns = [], $name = null, $comment = null, $options = [])
    {
        if (!$type instanceof Key) {
            if (!$columns) {
                throw new \InvalidArgumentException('No columns given.');
            }

            $columns = (array) $columns;

            $index = new Key($type, $columns, $name, $comment);
        } else {
            $index = $type;
        }

        if ($this->hasIndex($index->getName())) {
            $this->dropIndex($index->getName());
        }

        $query = MysqlGrammar::addIndex(
            $this->getName(),
            $index->getType(),
            $index->getColumns(),
            $index->getName(),
            $index->getComment()
        );

        $this->db->setQuery($query)->execute();

        return $this->reset();
    }
974103
public function addWhereFieldIsNotLike($field, $like_value, $left_any = true, $right_any = true, $table = ''): self
    {
        if (!$table) {
            $table = $this->getDbTableName();
        }

        $this->addWhereFieldAsString('`'. $table .'`.`'. $field .'` NOT LIKE "'. ($left_any ? '%' : '') . sql_prepare($like_value, true) . ($right_any ? '%' : '') .'"');

        return $this;
    }
826136
protected function _alter_table($alter_type, $table, $field)
	{
		if (in_array($alter_type, array('ADD', 'DROP'), TRUE))
		{
			return parent::_alter_table($alter_type, $table, $field);
		}

		// No method of modifying columns is supported
		return FALSE;
	}
1356345
public function change_field_type(xmldb_table $xmldb_table, xmldb_field $xmldb_field) {
        if (!$this->table_exists($xmldb_table)) {
            throw new ddl_table_missing_exception($xmldb_table->getName());
        }
        // Check the field exists
        if (!$this->field_exists($xmldb_table, $xmldb_field)) {
            throw new ddl_field_missing_exception($xmldb_field->getName(), $xmldb_table->getName());
        }
        // Check for dependencies in the DB before performing any action
        $this->check_field_dependencies($xmldb_table, $xmldb_field);

        if (!$sqlarr = $this->generator->getAlterFieldSQL($xmldb_table, $xmldb_field)) {
            return; // probably nothing to do
        }

        $this->execute_sql_arr($sqlarr, array($xmldb_table->getName()));
    }
1151263
protected function addColumn($field)
    {
        // Let's see if they're setting
        // a limit, like: string[50]
        if ( str_contains($field->type, '[') )
        {
            preg_match('/([^\[]+?)\[(\d+)\]/', $field->type, $matches);
            $field->type = $matches[1]; // string
            $field->limit = $matches[2]; // 50
        }

        // We'll start building the appropriate Schema method
        $html = "\$table->{$field->type}";

        $html .= isset($field->limit)
            ? "('{$field->name}', {$field->limit})"
            : "('{$field->name}')";

        // Take care of any potential indexes or options
        if (isset($field->options))
        {
            $html .= $field->options;
        }

        return $html.';';
    }
1343099
public function orderBy(string $field, string $type=''): QueryBuilderInterface
	{
		// When ordering by random, do an ascending order if the driver
		// doesn't support random ordering
		if (stripos($type, 'rand') !== FALSE)
		{
			$rand = $this->driver->getSql()->random();
			$type = $rand ?? 'ASC';
		}

		// Set fields for later manipulation
		$field = $this->driver->quoteIdent($field);
		$this->state->setOrderArray($field, $type);

		$orderClauses = [];

		// Flatten key/val pairs into an array of space-separated pairs
		foreach($this->state->getOrderArray() as $k => $v)
		{
			$orderClauses[] = $k . ' ' . strtoupper($v);
		}

		// Set the final string
		$orderString =  ! isset($rand)
			? "\nORDER BY ".implode(', ', $orderClauses)
			: "\nORDER BY".$rand;

		$this->state->setOrderString($orderString);

		return $this;
	}
42757
public function addOption($type, $value = true)
    {
        //====================================================================//
        // Safety Checks ==> Verify a new Field Exists
        if (empty($this->new)) {
            Splash::log()->err("ErrFieldsNoNew");
        } elseif (empty($type)) {
            Splash::log()->err("Field Option Type Cannot be Empty");
        } else {
            //====================================================================//
            // Update New Field structure
            $this->new->options[$type] = $value;
        }

        return $this;
    }
1204114
public function hasDatabaseField($field)
    {
        $spec = static::getSchema()->fieldSpec(static::class, $field, DataObjectSchema::DB_ONLY);
        return !empty($spec);
    }
946212
public function registerDoctrineTypeMapping($dbType, $doctrineType)
    {
        if ($this->doctrineTypeMapping === null) {
            $this->initializeAllDoctrineTypeMappings();
        }

        if (! Types\Type::hasType($doctrineType)) {
            throw DBALException::typeNotFound($doctrineType);
        }

        $dbType                             = strtolower($dbType);
        $this->doctrineTypeMapping[$dbType] = $doctrineType;

        $doctrineType = Type::getType($doctrineType);

        if (! $doctrineType->requiresSQLCommentHint($this)) {
            return;
        }

        $this->markDoctrineTypeCommented($doctrineType);
    }
778347
public static function addIndex($table, $type, $columns, $name, $comment = null)
    {
        $query = static::getQuery();
        $cols = static::buildIndexDeclare($name, $columns);

        $comment = $comment ? 'COMMENT ' . $query->quote($comment) : '';

        return static::build(
            'ALTER TABLE',
            $query->quoteName($table),
            'ADD',
            strtoupper($type),
            $cols,
            $comment
        );
    }
171833
public function addColumn($acronym, $type = null, array $options = [])
    {
        if (in_array($acronym, $this->reservedColumnAcronyms)) {
            throw new ReservedColumnAcronymException($acronym);
        }

        if ($type === null) {
            $type = Column::class;
        }

        $column = new $type($acronym, $options);

        // only DoctrineTable can sort nested properties. Therefore disable them for other tables.
        if (!$this instanceof DoctrineTable && $column instanceof SortableColumnInterface && $column->isSortable()) {
            if (strpos($column->getSortExpression(), '.') !== false) {
                $column->setSortable(false);
            }
        }

        if ($column instanceof TemplateableColumnInterface) {
            $column->setTemplating($this->templating);
        }

        if ($column instanceof SortableColumnInterface) {
            $column->setTableIdentifier($this->getIdentifier());
        }

        if ($column instanceof FormattableColumnInterface) {
            $column->setFormatterManager($this->formatterManager);
        }

        $this->columns->set($acronym, $column);

        return $this;
    }
193503
public static function forField(IField $field) : ColumnComponentType
    {
        return new self(
                $field->getProcessedType(),
                StandardConditions::forField($field, $field->getProcessedType()->getConditionOperators())
        );
    }