예제 #1
0
        private void buttonApplySchema_Click(object sender, RoutedEventArgs e)
        {
            Db2SourceContext ctx  = Target.Context;
            List <string>    sqls = new List <string>();

            if ((Target.Comment != null) && Target.Comment.IsModified())
            {
                sqls.AddRange(ctx.GetSQL(Target.Comment, string.Empty, string.Empty, 0, false));
            }
            for (int i = 0; i < Target.Columns.Count; i++)
            {
                Column newC = Target.Columns[i, false];
                if (newC.IsModified())
                {
                    Column oldC = Target.Columns[i, true];
                    sqls.AddRange(ctx.GetAlterColumnSQL(newC, oldC));
                }
                if ((newC.Comment != null) && newC.Comment.IsModified())
                {
                    sqls.AddRange(ctx.GetSQL(newC.Comment, string.Empty, string.Empty, 0, false));
                }
            }
            if (sqls.Count != 0)
            {
                ctx.ExecSqlsWithLog(sqls);
            }
            ctx.Revert(Target);
            IsEditing = false;
        }
예제 #2
0
        private void UpdateTextBoxSource()
        {
            if (textBoxSource == null)
            {
                return;
            }
            if (Target == null)
            {
                textBoxSource.Text = string.Empty;
                return;
            }
            Db2SourceContext ctx = Target.Context;

            try
            {
                StringBuilder buf = new StringBuilder();
                if (IsChecked(checkBoxSourceMain))
                {
                    foreach (string s in ctx.GetSQL(Target, string.Empty, ";", 0, true))
                    {
                        buf.AppendLine(s);
                    }
                }
                int lastLength = buf.Length;
                if (IsChecked(checkBoxSourceComment))
                {
                    lastLength = buf.Length;
                    if (!string.IsNullOrEmpty(Target.CommentText))
                    {
                        foreach (string s in ctx.GetSQL(Target.Comment, string.Empty, ";", 0, true))
                        {
                            buf.Append(s);
                        }
                    }
                    foreach (Column c in Target.Columns)
                    {
                        if (!string.IsNullOrEmpty(c.CommentText))
                        {
                            foreach (string s in ctx.GetSQL(c.Comment, string.Empty, ";", 0, true))
                            {
                                buf.Append(s);
                            }
                        }
                    }
                    if (lastLength < buf.Length)
                    {
                        buf.AppendLine();
                    }
                }
                textBoxSource.Text = buf.ToString();
            }
            catch (Exception t)
            {
                textBoxSource.Text = t.ToString();
            }
        }
예제 #3
0
        private void UpdateTextBoxSource()
        {
            if (textBoxSource == null)
            {
                return;
            }
            if (Target == null)
            {
                textBoxSource.Text = string.Empty;
                return;
            }
            Db2SourceContext ctx = Target.Context;

            try
            {
                StringBuilder buf = new StringBuilder();
                if (IsChecked(checkBoxSourceDropReferredCons))
                {
                    foreach (ForeignKeyConstraint f in Target.ReferFrom)
                    {
                        buf.Append(ctx.GetDropSQL(f, string.Empty, ";", 0, false, true));
                    }
                    if (0 < buf.Length)
                    {
                        buf.AppendLine();
                    }
                }
                if (IsChecked(checkBoxSourceMain))
                {
                    foreach (string s in ctx.GetSQL(Target, string.Empty, ";", 0, true, true))
                    {
                        buf.Append(s);
                    }
                }
                List <Constraint> list = new List <Constraint>(Target.Constraints);
                list.Sort();
                int lastLength = buf.Length;
                foreach (Constraint c in list)
                {
                    switch (c.ConstraintType)
                    {
                    case ConstraintType.Primary:
                        if (!IsChecked(checkBoxSourceMain) && IsChecked(checkBoxSourceKeyCons))
                        {
                            // 本体ソース内で出力しているので本体を出力しない場合のみ
                            foreach (string s in ctx.GetSQL(c, string.Empty, ";", 0, true, true))
                            {
                                buf.Append(s);
                            }
                        }
                        break;

                    case ConstraintType.Unique:
                        if (IsChecked(checkBoxSourceKeyCons))
                        {
                            foreach (string s in ctx.GetSQL(c, string.Empty, ";", 0, true, true))
                            {
                                buf.Append(s);
                            }
                        }
                        break;

                    case ConstraintType.ForeignKey:
                        if (IsChecked(checkBoxSourceRefCons))
                        {
                            foreach (string s in ctx.GetSQL(c, string.Empty, ";", 0, true, true))
                            {
                                buf.Append(s);
                            }
                        }
                        break;

                    case ConstraintType.Check:
                        if (IsChecked(checkBoxSourceCons))
                        {
                            foreach (string s in ctx.GetSQL(c, string.Empty, ";", 0, true, true))
                            {
                                buf.Append(s);
                            }
                        }
                        break;
                    }
                }
                if (lastLength < buf.Length)
                {
                    buf.AppendLine();
                }
                if (IsChecked(checkBoxSourceComment))
                {
                    lastLength = buf.Length;
                    if (!string.IsNullOrEmpty(Target.CommentText))
                    {
                        foreach (string s in ctx.GetSQL(Target.Comment, string.Empty, ";", 0, true))
                        {
                            buf.Append(s);
                        }
                    }
                    foreach (Column c in Target.Columns)
                    {
                        if (!string.IsNullOrEmpty(c.CommentText))
                        {
                            foreach (string s in ctx.GetSQL(c.Comment, string.Empty, ";", 0, true))
                            {
                                buf.Append(s);
                            }
                        }
                    }
                    if (lastLength < buf.Length)
                    {
                        buf.AppendLine();
                    }
                }
                if (IsChecked(checkBoxSourceTrigger))
                {
                    lastLength = buf.Length;
                    foreach (Trigger t in Target.Triggers)
                    {
                        foreach (string s in ctx.GetSQL(t, string.Empty, ";", 0, true))
                        {
                            buf.Append(s);
                        }
                        buf.AppendLine();
                    }
                    if (lastLength < buf.Length)
                    {
                        buf.AppendLine();
                    }
                }
                if (IsChecked(checkBoxSourceIndex))
                {
                    lastLength = buf.Length;
                    foreach (Index i in Target.Indexes)
                    {
                        foreach (string s in ctx.GetSQL(i, string.Empty, ";", 0, true))
                        {
                            buf.Append(s);
                        }
                    }
                    if (lastLength < buf.Length)
                    {
                        buf.AppendLine();
                    }
                }
                if (IsChecked(checkBoxSourceReferredCons))
                {
                    lastLength = buf.Length;
                    foreach (ForeignKeyConstraint f in Target.ReferFrom)
                    {
                        foreach (string s in ctx.GetSQL(f, string.Empty, ";", 0, true, true))
                        {
                            buf.Append(s);
                        }
                    }
                    if (lastLength < buf.Length)
                    {
                        buf.AppendLine();
                    }
                }
                textBoxSource.Text = buf.ToString();
            }
            catch (Exception t)
            {
                textBoxSource.Text = t.ToString();
            }
        }