Пример #1
0
        public void MakeSQOAlter()
        {
            SQLScript.Clear();
            cbCollate.Enabled = false;
            var sb = new StringBuilder();

            if (DomainObject.Name != txtName.Text)
            {
                sb.Append($@"ALTER DOMAIN {DomainObject.Name} TO {txtName.Text};");
                sb.Append($@"{SQLPatterns.Commit}{Environment.NewLine}");
            }

            sb.Append($@"ALTER DOMAIN {txtName.Text} TYPE {StaticVariablesClass.CompleteRawType(cbTypes.Text.Trim(), StaticFunctionsClass.ToIntDef(txtLength.Text.Trim(),0))}");
            if (cbCharSet.Enabled)
            {
                if (cbCharSet.Text != "NONE")
                {
                    sb.Append($@" CHARACTER SET {cbCharSet.Text}");
                }
            }
            sb.AppendLine($@";");
            sb.AppendLine($@"{SQLPatterns.Commit}{Environment.NewLine}");

            if (txtDefault.Text != DomainObject._defaultValue)
            {
                string defstr = (cbTypes.Text.IndexOf("CHAR") >= 0)   ? $@"'{txtDefault.Text}'" : txtDefault.Text;
                string cmd    = string.IsNullOrEmpty(txtDefault.Text) ? $@"ALTER DOMAIN {txtName.Text} SET DEFAULT NULL;" : $@"ALTER DOMAIN {txtName.Text} SET DEFAULT {defstr};";
                sb.AppendLine(cmd);
                sb.AppendLine($@"{SQLPatterns.Commit}{Environment.NewLine}");
            }

            if (txtCheck.Text.Length > 0)
            {
                sb.AppendLine($@"ALTER DOMAIN {txtName.Text} DROP CONSTRAINT; /* drop check constraint */");
                if (ckCheck.Checked)
                {
                    sb.AppendLine($@"ALTER DOMAIN {txtName.Text} ADD CONSTRAINT CHECK ({txtCheck.Text}); /* adds not null flag to domain */");
                }
                sb.AppendLine($@"{SQLPatterns.Commit}{Environment.NewLine}");
            }
            else if (ckCheck.Checked != DomainObject.NotNull)
            {
                sb.AppendLine($@"ALTER DOMAIN {txtName.Text} DROP CONSTRAINT; /* drop check constraint */");
                if (ckCheck.Checked)
                {
                    sb.AppendLine($@"ALTER DOMAIN {txtName.Text} ADD CONSTRAINT CHECK (VALUE IS NOT NULL); /* adds not null flag to domain */");
                }
                sb.AppendLine($@"{SQLPatterns.Commit}{Environment.NewLine}");
            }

            if (fctDescription.Text != DomainObject.Description)
            {
                sb.AppendLine($@"COMMENT ON DOMAIN {txtName.Text} IS '{fctDescription.Text}';");
                sb.AppendLine($@"{SQLPatterns.Commit}{Environment.NewLine}");
            }

            SQLScript.Add(sb.ToString());
            SQLToUI();
        }
Пример #2
0
        public void MakeSQLNew()
        {
            SQLScript.Clear();
            cbCollate.Enabled = true;
            var sb = new StringBuilder();

            sb.Append($@"CREATE DOMAIN {txtName.Text} AS ");
            sb.Append($@"{StaticVariablesClass.CompleteRawType(cbTypes.Text.Trim(), StaticFunctionsClass.ToIntDef(txtLength.Text.Trim(), 0))}");
            if (cbCharSet.Enabled)
            {
                if (cbCharSet.Text != "NONE")
                {
                    sb.Append($@" CHARACTER SET {cbCharSet.Text}");
                }
            }
            if (cbCollate.Enabled)
            {
                if (cbCollate.Text != "NONE")
                {
                    sb.Append($@" COLLATE {cbCollate.Text}");
                }
            }
            if (!string.IsNullOrEmpty(txtDefault.Text))
            {
                sb.Append($@" DEFAULT  '{txtDefault.Text}'");
            }

            sb.AppendLine($@";");
            sb.Append($@"{SQLPatterns.Commit}{Environment.NewLine}");

            if (cbNotNull.Checked)
            {
                sb.AppendLine($@"ALTER DOMAIN {txtName.Text} ADD CONSTRAINT CHECK (VALUE IS NOT NULL); /* adds not null flag to domain */");
                sb.AppendLine($@"{SQLPatterns.Commit}{Environment.NewLine}");
            }


            if (!string.IsNullOrEmpty(fctDescription.Text))
            {
                sb.AppendLine($@"COMMENT ON DOMAIN {txtName.Text} IS '{fctDescription.Text}';");
                sb.Append($@"{SQLPatterns.Commit}{Environment.NewLine}");
            }

            SQLScript.Add(sb.ToString());
            SQLToUI();
        }