示例#1
0
 public void AppendConstraint(AST.Table.AstTableKeyBaseNode keyBase)
 {
     if (keyBase is AST.Table.AstTablePrimaryKeyNode || keyBase is AST.Table.AstTableIdentityNode)
     {
         AppendConstraintBase(keyBase, "PRIMARY KEY", String.Empty);
     }
     else
     {
         AppendConstraintBase(keyBase, String.Empty, keyBase.Unique ? "UNIQUE " : " ");
     }
 }
示例#2
0
        private static string BuildKeys(AST.Table.AstTableKeyBaseNode keyBase)
        {
            var keyBuilder = new StringBuilder();

            foreach (AST.Table.AstTableKeyColumnNode columnNode in keyBase.Columns)
            {
                ColumnsTSqlEmitter.CheckAndAppendSeparator(",", keyBuilder);
                keyBuilder.AppendFormat(CultureInfo.InvariantCulture, "[{0}] {1}", columnNode.Column.Name, columnNode.SortOrder);
            }
            return(keyBuilder.ToString());
        }
示例#3
0
        private void AppendConstraintBase(AST.Table.AstTableKeyBaseNode constraint, string primaryKeyString, string unique)
        {
            string clustered    = constraint.Clustered ? "CLUSTERED" : "NONCLUSTERED";
            string ignoreDupKey = constraint.IgnoreDupKey ? "IGNORE_DUP_KEY = ON" : "IGNORE_DUP_KEY = OFF";
            string padIndex     = constraint.PadIndex ? "PAD_INDEX = ON" : "PAD_INDEX = OFF";
            string keys         = BuildKeys(constraint);

            var te = new TemplatePlatformEmitter("ConstraintTemplate", String.Format(CultureInfo.InvariantCulture, "[{0}]", constraint.Name), unique + clustered, keys, "WITH(" + padIndex + "," + ignoreDupKey + ")", primaryKeyString);

            _constraintKeyBuilder.Append("," + te.Emit());
            _constraintKeyBuilder.AppendFormat(CultureInfo.InvariantCulture, "\n");
        }