public override void ChangeColumn(IColumnStructure oldcol, IColumnStructure newcol, IEnumerable <IConstraint> constraints) { if (oldcol.ColumnName != newcol.ColumnName) { PutCmd("^alter ^table %f ^rename ^column %i ^to %i", oldcol.Table, oldcol.ColumnName, newcol.ColumnName); } if (!DbDiffTool.EqualTypes(oldcol.DataType, newcol.DataType, new DbDiffOptions())) { PutCmd("^alter ^table %f ^alter ^column %i ^type %s", newcol.Table, newcol.ColumnName, m_dialect.GenericTypeToSpecific(newcol.DataType)); } if (oldcol.IsNullable != newcol.IsNullable) { if (newcol.IsNullable) { PutCmd("^alter ^table %f ^alter ^column %i ^drop ^not ^null", newcol.Table, newcol.ColumnName); } else { PutCmd("^alter ^table %f ^alter ^column %i ^set ^not ^null", newcol.Table, newcol.ColumnName); } } if (oldcol.DefaultValue.SafeGetSql(m_dialect) != newcol.DefaultValue.SafeGetSql(m_dialect)) { if (newcol.DefaultValue == null) { PutCmd("^alter ^table %f ^alter ^column %i ^drop ^default", newcol.Table, newcol.ColumnName); } else { PutCmd("^alter ^table %f ^alter ^column %i ^set ^default %s", newcol.Table, newcol.ColumnName, newcol.DefaultValue.SafeGetSql(m_dialect)); } } this.CreateConstraints(constraints); }
public override void ChangeColumn(IColumnStructure oldcol, IColumnStructure newcol, IEnumerable <IConstraint> constrains) { if (oldcol.ColumnName != newcol.ColumnName) { RenameColumn(oldcol, newcol.ColumnName); } if (oldcol.IsNullable != newcol.IsNullable) { PutCmd("^alter ^table %f ^modify %i %k", newcol.Table, newcol.ColumnName, newcol.IsNullable ? "null" : "not null"); } if (!DbDiffTool.EqualDefaultValues(oldcol, newcol)) { if (newcol.DefaultValue == null) { PutCmd("^alter ^table %f ^modify %i ^default ^null", newcol.Table, newcol.ColumnName); } else { Put("^alter ^table %f ^modify %i ", newcol.Table, newcol.ColumnName); ColumnDefinition_Default(newcol); this.EndCommand(); } } if (!DbDiffTool.EqualTypes(oldcol.DataType, newcol.DataType, new DbDiffOptions())) { Put("^alter ^table %f ^modify %i ", newcol.Table, newcol.ColumnName); ColumnDefinition(newcol, false, false, false); } EndCommand(); }
public override void ChangeColumn(ColumnInfo oldcol, ColumnInfo newcol, IEnumerable <ConstraintInfo> constraints) { if (oldcol.Name != newcol.Name) { PutCmd("^alter ^table %f ^rename ^column %i ^to %i", oldcol.OwnerTable, oldcol.Name, newcol.Name); } if (!DbDiffTool.EqualTypes(oldcol, newcol, new DbDiffOptions())) { PutCmd("^alter ^table %f ^alter ^column %i ^type %s", newcol.OwnerTable, newcol.Name, newcol.DataType); } if (oldcol.NotNull != newcol.NotNull) { if (newcol.NotNull) { PutCmd("^alter ^table %f ^alter ^column %i ^set ^not ^null", newcol.OwnerTable, newcol.Name); } else { PutCmd("^alter ^table %f ^alter ^column %i ^drop ^not ^null", newcol.OwnerTable, newcol.Name); } } if (oldcol.DefaultValue != newcol.DefaultValue) { if (newcol.DefaultValue == null) { PutCmd("^alter ^table %f ^alter ^column %i ^drop ^default", newcol.OwnerTable, newcol.Name); } else { PutCmd("^alter ^table %f ^alter ^column %i ^set ^default %s", newcol.OwnerTable, newcol.Name, newcol.DefaultValue); } } this.CreateConstraints(constraints); }
public override void ChangeColumn(IColumnStructure oldcol, IColumnStructure newcol, IEnumerable <IConstraint> constraints) { if (oldcol.DefaultValue != null) { PutCmd("^alter ^table %f ^alter ^column %i ^drop ^default", newcol.Table, newcol.ColumnName); } if (oldcol.ColumnName != newcol.ColumnName) { RenameColumn(oldcol, newcol.ColumnName); } // change data type if (!DbDiffTool.EqualTypes(oldcol.DataType, newcol.DataType, new DbDiffOptions())) { Put("^alter ^table %f ^alter ^column %i ", newcol.Table, newcol.ColumnName); // remove autoincrement flag ColumnStructure newcol2 = new ColumnStructure(newcol); newcol2.SetDummyTable(newcol.Table.FullName); newcol2.DataType.SetAutoincrement(false); ColumnDefinition(newcol2, false, false, false); EndCommand(); } if (oldcol.IsNullable != newcol.IsNullable) { PutCmd("^alter ^table %f ^alter ^column %i ^set %k ^null", oldcol.Table, newcol.ColumnName, newcol.IsNullable ? "" : "not"); } CreateDefault(newcol); if (oldcol.DataType.IsAutoIncrement() != newcol.DataType.IsAutoIncrement()) { if (oldcol.DataType.IsAutoIncrement()) { PutCmd("^alter ^table %f ^alter ^column %i ^drop ^generated", newcol.Table.FullName, newcol.ColumnName); } if (newcol.DataType.IsAutoIncrement()) { PutCmd("^alter ^table %f ^alter ^column %i %s ^generated ^always ^as ^identity (^start ^with %s)", newcol.Table.FullName, newcol.ColumnName, m_dialect.GenericTypeToSpecific(newcol.DataType), 1); } } this.CreateConstraints(constraints); }