Compares two columns.

@param \Fridge\DBAL\Schema\Column $oldColumn The old column.
@param \Fridge\DBAL\Schema\Column $newColumn The new column.

@return \Fridge\DBAL\Schema\Diff\ColumnDiff The difference between the two columns.
484104
public function compare(Column $oldColumn, Column $newColumn)
    {
        $differences = array();

        if ($oldColumn->getType() !== $newColumn->getType()) {
            $differences[] = 'type';
        }

        if ($oldColumn->getLength() !== $newColumn->getLength()) {
            $differences[] = 'length';
        }

        if ($oldColumn->getPrecision() !== $newColumn->getPrecision()) {
            $differences[] = 'precision';
        }

        if ($oldColumn->getScale() !== $newColumn->getScale()) {
            $differences[] = 'scale';
        }

        if ($oldColumn->isUnsigned() !== $newColumn->isUnsigned()) {
            $differences[] = 'unsigned';
        }

        if ($oldColumn->isFixed() !== $newColumn->isFixed()) {
            $differences[] = 'fixed';
        }

        if ($oldColumn->isNotNull() !== $newColumn->isNotNull()) {
            $differences[] = 'not_null';
        }

        if ($oldColumn->getDefault() !== $newColumn->getDefault()) {
            $differences[] = 'default';
        }

        if ($oldColumn->isAutoIncrement() !== $newColumn->isAutoIncrement()) {
            $differences[] = 'auto_increment';
        }

        if ($oldColumn->getComment() !== $newColumn->getComment()) {
            $differences[] = 'comment';
        }

        return new ColumnDiff($oldColumn, $newColumn, $differences);
    }
659794
public function checkDiff($tableName, TableDiff $diff)
    {
        $this->diffs[$tableName] = $diff;

        // Adds
        $this->getAddedColumns($tableName, $diff);
        $this->getAddedIndexes($tableName, $diff);
        $this->getAddedForeignKeys($tableName, $diff);

        // Changes
        $this->getChangedColumns($tableName, $diff);
        $this->getChangedIndexes($tableName, $diff);
        $this->getChangedForeignKeys($tableName, $diff);

        // Renames
        $this->getRenamedColumns($tableName, $diff);

        // Removes
        $this->getRemovedColumns($tableName, $diff);
        $this->getRemovedIndexes($tableName, $diff);
        $this->getRemovedForeignKeys($tableName, $diff);

        if (count($diff->removedColumns) > 0) {
            $hint = sprintf(
                'The following fields in the `%s` table are not defined in your configuration. You can safely delete them manually if they are no longer needed: `%s`',
                $tableName,
                implode('`, `', array_keys($diff->removedColumns))
            );
            $this->hints[] = $hint;
        }
    }
478920
public function insertNewColumnBeforeByIndex($pBefore = 0, $pNumCols = 1)
    {
        if ($pBefore >= 0) {
            return $this->insertNewColumnBefore(PHPExcel_Cell::stringFromColumnIndex($pBefore), $pNumCols);
        } else {
            throw new PHPExcel_Exception("Columns can only be inserted before at least column A (0).");
        }
    }
945246
private function getAddedColumns($tableName, TableDiff $diff)
    {
        /** @var $col \Doctrine\DBAL\Schema\Column */
        foreach ($diff->addedColumns as $col) {
            $this->addMessage($tableName, sprintf('missing column `%s`', $col->getName()));
        }
    }
669149
public function compareIndexes(Index $oldIndex, Index $newIndex)
    {
        return ($oldIndex->getName() !== $newIndex->getName())
            || ($oldIndex->getColumnNames() !== $newIndex->getColumnNames())
            || ($oldIndex->isUnique() !== $newIndex->isUnique());
    }
949179
def _compare_columns(self, new_columns, old_columns):
        
        '''  '''
        
        # print(new_columns)
        # print(old_columns)
        
        add_columns = {}
        remove_columns = {}
        rename_columns = {}
        retype_columns = {}
        resize_columns = {}
        for key, value in new_columns.items():
            if key not in old_columns.keys():
                add_columns[key] = True
                if value[2]:
                    if value[2] in old_columns.keys():
                        rename_columns[key] = value[2]
                        del add_columns[key]
            else:
                if value[1] != old_columns[key][1]:
                    retype_columns[key] = value[1]
                if value[3] != old_columns[key][3]:
                    resize_columns[key] = value[3]
        remove_keys = set(old_columns.keys()) - set(new_columns.keys())
        if remove_keys:
            for key in list(remove_keys):
                remove_columns[key] = True
        
        return add_columns, remove_columns, rename_columns, retype_columns, resize_columns
836566
void retypeColumn(ColumnSchema oldCol, ColumnSchema newCol) {

        boolean allowed = true;
        int     oldType = oldCol.getDataType().typeCode;
        int     newType = newCol.getDataType().typeCode;

        if (!table.isEmpty(session) && oldType != newType) {
            allowed =
                newCol.getDataType().canConvertFrom(oldCol.getDataType());

            switch (oldType) {

                case Types.SQL_BLOB :
                case Types.SQL_CLOB :
                case Types.OTHER :
                case Types.JAVA_OBJECT :
                    allowed = false;
                    break;
            }
        }

        if (!allowed) {
            throw Error.error(ErrorCode.X_42561);
        }

        int colIndex = table.getColumnIndex(oldCol.getName().name);

        // if there is a multi-column PK, do not change the PK attributes
        if (newCol.isIdentity() && table.hasIdentityColumn()
                && table.identityColumn != colIndex) {
            throw Error.error(ErrorCode.X_42525);
        }

        if (table.getPrimaryKey().length > 1) {
            newCol.setPrimaryKey(oldCol.isPrimaryKey());

            if (ArrayUtil.find(table.getPrimaryKey(), colIndex) != -1) {}
        } else if (table.hasPrimaryKey()) {
            if (oldCol.isPrimaryKey()) {
                newCol.setPrimaryKey(true);
            } else if (newCol.isPrimaryKey()) {
                throw Error.error(ErrorCode.X_42532);
            }
        } else if (newCol.isPrimaryKey()) {
            throw Error.error(ErrorCode.X_42530);
        }

        // apply and return if only metadata change is required
        boolean meta = newType == oldType;

        meta &= oldCol.isNullable() == newCol.isNullable();
        meta &= oldCol.getDataType().scale == newCol.getDataType().scale;
        meta &= (oldCol.isIdentity() == newCol.isIdentity());
        meta &=
            (oldCol.getDataType().precision == newCol.getDataType().precision
             || (oldCol.getDataType().precision
                 < newCol.getDataType().precision && (oldType
                     == Types.SQL_VARCHAR || oldType == Types.SQL_VARBINARY)));

        if (meta) {

            // size of some types may be increased with this command
            // default expressions can change
            oldCol.setType(newCol);
            oldCol.setDefaultExpression(newCol.getDefaultExpression());

            if (newCol.isIdentity()) {
                oldCol.setIdentity(newCol.getIdentitySequence());
            }

            table.setColumnTypeVars(colIndex);
            table.resetDefaultsFlag();

            return;
        }

        database.schemaManager.checkColumnIsReferenced(table.getName(),
                table.getColumn(colIndex).getName());
        table.checkColumnInCheckConstraint(colIndex);
        table.checkColumnInFKConstraint(colIndex);
        checkConvertColDataType(oldCol, newCol);
        retypeColumn(newCol, colIndex);
    }
42256
private void validateColumn(final Column<?> newColumn) {
        Preconditions.checkNotNull(newColumn, "Attempted to add a null to the columns in table " + name);
        List<String> stringList = new ArrayList<>();
        for (String name : columnNames()) {
            stringList.add(name.toLowerCase());
        }
        if (stringList.contains(newColumn.name().toLowerCase())) {
            String message = String.format("Cannot add column with duplicate name %s to table %s", newColumn, name);
            throw new IllegalArgumentException(message);
        }

        checkColumnSize(newColumn);
    }
526809
protected function getChangeDefault($tableName, Column $newColumn)
    {
        $constraintName = "DF_{$tableName}_{$newColumn->getName()}";
        $default = $newColumn->getDefault();
        $instructions = new AlterInstructions();

        if ($default === null) {
            $default = 'DEFAULT NULL';
        } else {
            $default = ltrim($this->getDefaultValueDefinition($default));
        }

        if (empty($default)) {
            return $instructions;
        }

        $instructions->addPostStep(sprintf(
            'ALTER TABLE %s ADD CONSTRAINT %s %s FOR %s',
            $this->quoteTableName($tableName),
            $constraintName,
            $default,
            $this->quoteColumnName($newColumn->getName())
        ));

        return $instructions;
    }
78550
protected function getNewCellNode(TableCell $oldCell = null, TableCell $newCell = null)
    {
        // If only one cell exists, use it
        if (!$oldCell || !$newCell) {
            $clone = $newCell
                ? $newCell->getDomNode()->cloneNode(false)
                : $oldCell->getDomNode()->cloneNode(false);
        } else {
            $oldNode = $oldCell->getDomNode();
            $newNode = $newCell->getDomNode();

            /* @var $clone \DOMElement */
            $clone = $newNode->cloneNode(false);

            $oldRowspan = $oldNode->getAttribute('rowspan') ?: 1;
            $oldColspan = $oldNode->getAttribute('colspan') ?: 1;
            $newRowspan = $newNode->getAttribute('rowspan') ?: 1;
            $newColspan = $newNode->getAttribute('colspan') ?: 1;

            $clone->setAttribute('rowspan', max($oldRowspan, $newRowspan));
            $clone->setAttribute('colspan', max($oldColspan, $newColspan));
        }

        return $this->diffDom->importNode($clone);
    }
753241
protected function updateColumn($name, \Doctrine\DBAL\Schema\ColumnDiff $col) {
		$res = "\n\t\$table->changeColumn('$name', [";

		$type_changed = in_array('type', $col->changedProperties);
		foreach($col->column->toArray() as $propName=>$prop) {
			if(($type_changed && $prop && $propName !== 'name') || in_array($propName, $col->changedProperties)) {
				if($propName === 'type')
					$res .= "\n\t\t'$propName' => '".strtolower($prop)."',";
				else
					$res .= "\n\t\t'$propName' => '$prop',";
			}
		}
		$res .= "\n\t]);";

		return $res;
	}
200843
public Table replaceColumn(final int colIndex, final Column<?> newColumn) {
        removeColumns(column(colIndex));
        return insertColumn(colIndex, newColumn);
    }
760028
func (c *Columns) NewColumn(name, caption string, width int, aling Align) (*Column, error) {
	if c.FindByName(name) != nil {
		return nil, ErrorAlreadyExists
	}
	column := &Column{
		Name:    name,
		Caption: caption,
		Width:   width,
		Aling:   aling,
		Visible: true,
	}
	c.columns = append(c.columns, column)
	return column, nil
}
266627
public function renameCheck($oldName, $newName)
    {
        if (!$this->hasCheck($oldName)) {
            throw SchemaException::tableCheckDoesNotExist($this->getName(), $oldName);
        }

        if ($this->hasCheck($newName)) {
            throw SchemaException::tableCheckAlreadyExists($this->getName(), $newName);
        }

        $this->checks[$oldName]->setName($newName);
        $this->checks[$newName] = $this->checks[$oldName];
        unset($this->checks[$oldName]);
    }
94402
public function move(string $old, string $new){
    if (
      !empty($old) &&
      !empty($new) &&
      ($old = $this->checkFilePath($old)) &&
      ftp_rename($this->cn, $old, $new)
    ){
      return true;
    }
    return false;
  }
92695
public function upgrade(Table $old_table)
        {
            $old_columns = $old_table->getColumns();
            $new_columns = $this->getColumns();

            $added_columns = \array_diff_key($new_columns, $old_columns);
            $altered_columns = Tools::array_diff_recursive($old_columns, $new_columns);
            $dropped_columns = \array_keys(array_diff_key($old_columns, $new_columns));

            /** @var RawQuery[] $queries */
            $queries = [];
            foreach ($added_columns as $details) {
                $queries[] = $this->getAddColumnQuery($details);
            }

            foreach ($queries as $query) {
                if ($query instanceof QueryInterface) {
                    Statement::getPreparedStatement($query)->execute();
                }
            }

            $this->migrateData($old_table);

            $queries = [];
            foreach ($altered_columns as $column => $details) {
                if (in_array($column, $dropped_columns)) continue;

                $queries[] = $this->getAlterColumnQuery($new_columns[$column]);
                $queries[] = $this->getAlterColumnDefaultQuery($new_columns[$column]);
            }
            foreach ($dropped_columns as $details) {
                $queries[] = $this->getDropColumnQuery($details);
            }
            foreach ($queries as $query) {
                if ($query instanceof RawQuery) {
                    Statement::getPreparedStatement($query)->execute();
                }
            }
        }
183883
public function diffColumn(Column $column1, Column $column2)
    {
        $properties1 = $column1->toArray();
        $properties2 = $column2->toArray();

        $changedProperties = [];

        foreach (['type', 'notnull', 'unsigned', 'autoincrement'] as $property) {
            if ($properties1[$property] === $properties2[$property]) {
                continue;
            }

            $changedProperties[] = $property;
        }

        // This is a very nasty hack to make comparator work with the legacy json_array type, which should be killed in v3
        if ($this->isALegacyJsonComparison($properties1['type'], $properties2['type'])) {
            array_shift($changedProperties);

            $changedProperties[] = 'comment';
        }

        // Null values need to be checked additionally as they tell whether to create or drop a default value.
        // null != 0, null != false, null != '' etc. This affects platform's table alteration SQL generation.
        if (($properties1['default'] === null) !== ($properties2['default'] === null)
            || $properties1['default'] != $properties2['default']) {
            $changedProperties[] = 'default';
        }

        if (($properties1['type'] instanceof Types\StringType && ! $properties1['type'] instanceof Types\GuidType) ||
            $properties1['type'] instanceof Types\BinaryType
        ) {
            // check if value of length is set at all, default value assumed otherwise.
            $length1 = $properties1['length'] ?: 255;
            $length2 = $properties2['length'] ?: 255;
            if ($length1 !== $length2) {
                $changedProperties[] = 'length';
            }

            if ($properties1['fixed'] !== $properties2['fixed']) {
                $changedProperties[] = 'fixed';
            }
        } elseif ($properties1['type'] instanceof Types\DecimalType) {
            if (($properties1['precision'] ?: 10) !== ($properties2['precision'] ?: 10)) {
                $changedProperties[] = 'precision';
            }
            if ($properties1['scale'] !== $properties2['scale']) {
                $changedProperties[] = 'scale';
            }
        }

        // A null value and an empty string are actually equal for a comment so they should not trigger a change.
        if ($properties1['comment'] !== $properties2['comment'] &&
            ! ($properties1['comment'] === null && $properties2['comment'] === '') &&
            ! ($properties2['comment'] === null && $properties1['comment'] === '')
        ) {
            $changedProperties[] = 'comment';
        }

        $customOptions1 = $column1->getCustomSchemaOptions();
        $customOptions2 = $column2->getCustomSchemaOptions();

        foreach (array_merge(array_keys($customOptions1), array_keys($customOptions2)) as $key) {
            if (! array_key_exists($key, $properties1) || ! array_key_exists($key, $properties2)) {
                $changedProperties[] = $key;
            } elseif ($properties1[$key] !== $properties2[$key]) {
                $changedProperties[] = $key;
            }
        }

        $platformOptions1 = $column1->getPlatformOptions();
        $platformOptions2 = $column2->getPlatformOptions();

        foreach (array_keys(array_intersect_key($platformOptions1, $platformOptions2)) as $key) {
            if ($properties1[$key] === $properties2[$key]) {
                continue;
            }

            $changedProperties[] = $key;
        }

        return array_unique($changedProperties);
    }