Пример #1
0
        //UNSAFE, not supported by MySQL: http://dev.mysql.com/doc/refman/5.1/en/rename-database.html
        //public override void RenameDatabase(string oldname, string newname)
        //{
        //    PutCmd("^rename ^database %i ^to %i", oldname, newname);
        //}

        public override void ChangeColumn(IColumnStructure oldcol, IColumnStructure newcol, IEnumerable <IConstraint> constraints)
        {
            Put("^alter ^table %f ^change ^column %i %i ", oldcol.Table, oldcol.ColumnName, newcol.ColumnName);
            ColumnDefinition(newcol, true, true, true);
            InlineConstraints(constraints);
            EndCommand();
        }
Пример #2
0
 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);
 }
Пример #3
0
 public virtual void ColumnDefinition(IColumnStructure col, bool includeDefault, bool includeNullable, bool includeCollate)
 {
     if (m_dialect.DialectCaps.Domains && col.Domain != null && m_props.UseDomains)
     {
         Put("%f", col.Domain);
     }
     else
     {
         WriteRaw(m_dialect.GenericTypeToSpecific(col.DataType).ToString());
     }
     WriteRaw(" ");
     if (includeNullable)
     {
         WriteRaw(col.IsNullable ? "NULL" : "NOT NULL");
     }
     if (includeCollate && m_dialect.SupportsColumnCollation(col.DataType) && !String.IsNullOrEmpty(col.Collation) && AllowWriteColumnCollation())
     {
         WriteRaw(" COLLATE ");
         WriteRaw(col.Collation);
     }
     if (includeDefault && col.DefaultValue != null)
     {
         ColumnDefinition_Default(col);
     }
 }
Пример #4
0
        public override void RenameColumn(IColumnStructure column, string newcol)
        {
            var newcoldef = new ColumnStructure(column);

            newcoldef.ColumnName = newcol;
            this.ChangeColumn(column, newcoldef);
        }
Пример #5
0
 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();
 }
Пример #6
0
 public void LoadFromTransform(IRowTransform tr)
 {
     lbtarget.Rows.Clear();
     if (tr is IdentityTransform)
     {
         foreach (IColumnStructure col in m_srcformat.Columns)
         {
             lbtarget.Rows.Add(col.ColumnName, new GenericTransform.ColumnColExprType().ToString(), col.ColumnName);
         }
     }
     if (tr is PermuteTransform)
     {
         var t = tr as PermuteTransform;
         foreach (int i in t.DestIndexes)
         {
             IColumnStructure col = m_srcformat.Columns[i];
             lbtarget.Rows.Add(col.ColumnName, new GenericTransform.ColumnColExprType().ToString(), col.ColumnName);
         }
     }
     if (tr is GenericTransform)
     {
         var t = tr as GenericTransform;
         foreach (var col in t.DestCols)
         {
             lbtarget.Rows.Add(col.Name, col.Type.ToString(), col.Expression);
         }
     }
 }
Пример #7
0
 public virtual void CreateColumn(IColumnStructure col, IEnumerable <IConstraint> constrains)
 {
     Put("^alter ^table %f add %i ", col.Table, col.ColumnName);
     ColumnDefinition(col, true, true, true);
     InlineConstraints(constrains);
     EndCommand();
 }
Пример #8
0
 public virtual void ChangeColumn(IColumnStructure oldcol, IColumnStructure newcol, IEnumerable <IConstraint> constrains)
 {
     Put("/*^alter ^table %f ^change ^column %i %i ", oldcol.Table, oldcol.ColumnName, newcol.ColumnName);
     ColumnDefinition(newcol, true, true, true);
     Put("*/");
     EndCommand();
 }
Пример #9
0
 public override void NotifyDropColumn(IColumnStructure column)
 {
     if (FullName == column.Table.FullName)
     {
         _Columns.RemoveIf(c => c.ColumnName == column.ColumnName);
     }
 }
Пример #10
0
        public void DropColumn(IColumnStructure column)
        {
            ColumnStructure col = Structure.FindOrCreateColumn(column);

            AddOperation(new AlterOperation_DropColumn {
                ParentTable = (TableStructure)col.Table, OldObject = col
            });
        }
Пример #11
0
 public override void NotifyDropColumn(IColumnStructure column)
 {
     base.NotifyDropColumn(column);
     if (PrimaryKeyTable == column.Table)
     {
         PrimaryKeyColumns.RemoveIf(c => c.ColumnName == column.ColumnName);
     }
 }
Пример #12
0
        public void RenameColumn(IColumnStructure column, string name)
        {
            ColumnStructure col = Structure.FindOrCreateColumn(column);

            AddOperation(new AlterOperation_RenameColumn {
                OldObject = col, ParentTable = (TableStructure)col.Table, NewName = new NameWithSchema(name)
            });
        }
Пример #13
0
        public void ChangeColumn(IColumnStructure column, IColumnStructure newcolumn)
        {
            ColumnStructure col = Structure.FindOrCreateColumn(column);

            AddOperation(new AlterOperation_ChangeColumn {
                OldObject = col, ParentTable = (TableStructure)col.Table, NewObject = new ColumnStructure(newcolumn)
            });
        }
Пример #14
0
        public void RenameColumn(IColumnStructure column, string newcol)
        {
            string oldcol = column.ColumnName;

            foreach (AbstractObjectStructure obj in this.GetAllObjects())
            {
                obj.NotifyRenameColumn(column.Table.FullName, oldcol, newcol);
            }
        }
Пример #15
0
        public override void ColumnDefinition_Default(IColumnStructure col)
        {
            string defsql = col.DefaultValue.GenerateSql(m_dialect, col.DataType, null);

            if (defsql != null)
            {
                Put(" ^constraint %i ^default %s ", GuessDefaultName(col), defsql);
            }
        }
Пример #16
0
        public void RenameColumn(string oldName, string newName)
        {
            IColumnStructure oldCol = _Columns.First(c => c.ColumnName == oldName);

            foreach (AbstractObjectStructure obj in this.GetAllObjects())
            {
                obj.NotifyRenameColumn(FullName, oldCol.ColumnName, newName);
            }
        }
Пример #17
0
        private void DropDefault(IColumnStructure col)
        {
            string defname = col.GetSpecificAttribute("mssql", "defname");

            if (defname != null)
            {
                PutCmd("^alter ^table %f ^drop ^constraint %i", col.Table, defname);
            }
        }
Пример #18
0
        public void ChangeColumn(IColumnStructure oldcol, IColumnStructure newcol, IEnumerable <IConstraint> constraints)
        {
            var col = this.FindColumn(oldcol) as ColumnStructure;

            col.AssignFrom(newcol);
            this.CreateConstraints(constraints);
            //if (oldcol.ColumnName != newcol.ColumnName) RenameColumn(oldcol, newcol.ColumnName);
            //FindTable(oldcol.Table.FullName).ChangeColumnDefinition(newcol);
            //foreach (AbstractObjectStructure obj in this.GetAllObjects()) obj.NotifyChangeColumnType_RefsOnly(newcol);
        }
Пример #19
0
        public static string GetSpecificAttribute(this IColumnStructure col, string dialect, string name)
        {
            string key = dialect + "." + name;

            if (col.SpecificData.ContainsKey(key))
            {
                return(col.SpecificData[key]);
            }
            return(null);
        }
Пример #20
0
        public virtual DbTypeBase MigrateDataType(IColumnStructure owningColumn, DbTypeBase type, IMigrationProfile profile, IProgressInfo progress)
        {
            ISpecificType spectype = GenericTypeToSpecific(type, profile, progress);

            //if (!DialectCaps.Arrays && type.ArraySpec.IsArray)
            //{
            //    return new DbTypeText(); // migrate arrays as text blob
            //}
            return(spectype.ToGenericType());
        }
Пример #21
0
        public virtual void ColumnDefinition_Default(IColumnStructure col)
        {
            string defsql = col.DefaultValue.GenerateSql(m_dialect, col.DataType, null);

            if (defsql != null)
            {
                WriteRaw(" DEFAULT ");
                WriteRaw(defsql);
            }
        }
Пример #22
0
        public override DbTypeBase MigrateDataType(IColumnStructure owningColumn, DbTypeBase type, IMigrationProfile profile, IProgressInfo progress)
        {
            if (type is DbTypeString && ((DbTypeString)type).Length <= 0)
            {
                // convert to BLOB variant, MySQL doesn't support varchar(max) notation
                return(((DbTypeString)type).ConvertToBlobVariant());
            }

            return(base.MigrateDataType(owningColumn, type, profile, progress));
        }
Пример #23
0
        private string GuessDefaultName(IColumnStructure col)
        {
            string defname = col.GetSpecificAttribute("mssql", "defname");

            if (defname == null)
            {
                defname = String.Format("DF_{0}_{1}_{2}", col.Table.FullName.Schema ?? "dbo", col.Table.FullName.Name, col.ColumnName);
            }
            return(defname);
        }
Пример #24
0
        //public override void RenameTable(NameWithSchema oldName, string newName)
        //{
        //    PutCmd("^rename ^table %i ^to %i", oldName.Name, newName);
        //}

        public override void ChangeColumn(IColumnStructure oldcol, IColumnStructure newcol, IEnumerable <IConstraint> constraints)
        {
            if (oldcol.ColumnName != newcol.ColumnName)
            {
                throw new Exception("DAE-00317 operation not supported");
            }
            Put("^alter ^table %f ^alter ^column %i ", oldcol.Table, newcol.ColumnName);
            ColumnDefinition(newcol, false, true, true);
            EndCommand();
            this.CreateConstraints(constraints);
        }
Пример #25
0
        public ColumnStructure AddColumn(IColumnStructure source, bool reuseGrouId)
        {
            ColumnStructure col = new ColumnStructure(source);

            if (!reuseGrouId)
            {
                col.GroupId = Guid.NewGuid().ToString();
            }
            _Columns.Add(col);
            return(col);
        }
Пример #26
0
        public void LoadFromTransform(IRowTransform tr)
        {
            bool[] activeCols = new bool[m_target.Columns.Count];
            if (tr is IdentityTransform)
            {
                for (int i = 0; i < m_combos.Count; i++)
                {
                    activeCols[i] = true;
                    int srcindex = m_source.Columns.GetIndex(m_target.Columns[i].ColumnName);
                    if (srcindex >= 0)
                    {
                        SetColumnBindings(i, new GenericTransform.ColumnColExprType(), m_source.Columns[srcindex].ColumnName);
                    }
                }
            }
            if (tr is PermuteTransform)
            {
                var t = tr as PermuteTransform;
                for (int i = 0; i < t.OutputFormat.Columns.Count; i++)
                {
                    var dstcol = t.OutputFormat.Columns[i];
                    int dsti   = m_target.Columns.GetIndex(dstcol.ColumnName);
                    if (dsti < 0)
                    {
                        continue;
                    }
                    int srci = t.DestIndexes[i];
                    IColumnStructure srccol = m_source.Columns[srci];
                    SetColumnBindings(dsti, new GenericTransform.ColumnColExprType(), srccol.ColumnName);
                    activeCols[dsti] = true;
                }
            }
            if (tr is GenericTransform)
            {
                var t = tr as GenericTransform;

                for (int i = 0; i < t.OutputFormat.Columns.Count; i++)
                {
                    var dstcol = t.OutputFormat.Columns[i];
                    int dsti   = m_target.Columns.GetIndex(dstcol.ColumnName);
                    if (dsti < 0)
                    {
                        continue;
                    }
                    var d = t.DestCols[i];
                    SetColumnBindings(dsti, d.Type, d.Expression);
                    activeCols[dsti] = true;
                }
            }
            for (int i = 0; i < activeCols.Length; i++)
            {
                m_checks[i].Checked = !activeCols[i];
            }
        }
Пример #27
0
        private void CreateDefault(IColumnStructure col)
        {
            if (col.DefaultValue == null)
            {
                return;
            }
            string defsql = col.DefaultValue.GenerateSql(m_dialect, col.DataType, null);

            if (defsql != null)
            {
                PutCmd("^alter ^table %f ^alter ^column %i ^set ^default %s", col.Table, col.ColumnName, defsql);
            }
        }
Пример #28
0
 public ColumnStructure(IColumnStructure src)
     : base(src)
 {
     m_columnName   = src.ColumnName;
     m_dataType     = src.DataType.Clone();
     m_isNullable   = src.IsNullable;
     m_defaultValue = src.DefaultValue;
     m_characterSet = src.CharacterSet;
     m_collation    = src.Collation;
     SpecificData.AddAll(src.SpecificData);
     //TableName = src.Table;
     //Table = src.Table;
     Domain = src.Domain;
 }
Пример #29
0
        private void CreateDefault(IColumnStructure col)
        {
            if (col.DefaultValue == null)
            {
                return;
            }
            string defsql = col.DefaultValue.GenerateSql(m_dialect, col.DataType, null);

            if (defsql != null)
            {
                var defname = GuessDefaultName(col);
                PutCmd("^alter ^table %f ^add ^constraint %i ^default %s for %i", col.Table, defname, defsql, col.ColumnName);
            }
        }
Пример #30
0
        public void DropColumn(IColumnStructure column)
        {
            ColumnStructure colcopy = new ColumnStructure(column);

            colcopy.SetDummyTable(column.Table.FullName);
            // we must send copy of column, because when dropping column, column.Table will be null
            foreach (AbstractObjectStructure obj in this.GetAllObjects())
            {
                obj.NotifyDropColumn(colcopy);
            }
            foreach (TableStructure tbl in Tables)
            {
                tbl.DropEmptyConstraints();
            }
        }