Exemple #1
0
 public void ProcessColumnDefTableConstraints(TSqlParser.Column_def_table_constraintsContext context)
 {
     foreach (var constraintContext in context.column_def_table_constraint())
     {
         ProcessColumnDefTableConstraint(constraintContext);
     }
 }
Exemple #2
0
        public override string VisitColumn_def_table_constraints([NotNull] TSqlParser.Column_def_table_constraintsContext context)
        {
            var    hasPrimaryKeyOrIndex = false;
            string firstColumn          = null;

            foreach (var child in context.children)
            {
                if (child is TSqlParser.Column_def_table_constraintContext)
                {
                    if (firstColumn == null && (child.GetChild(0) is TSqlParser.Column_definitionContext columnDefinitionChild))
                    {
                        IParseTree descendant = child;
                        do
                        {
                            descendant = descendant.GetChild(0);
                        } while (!(descendant is ITerminalNode));
                        firstColumn = descendant.GetText();
                    }
                    if (child.GetChild(0) is TSqlParser.Table_constraintContext constraintChild)
                    {
                        if (
                            string.Compare(constraintChild.GetChild(2).GetText(), "PRIMARY", ignoreCase: true) == 0 ||
                            string.Compare(constraintChild.GetChild(0).GetText(), "PRIMARY", ignoreCase: true) == 0
                            )
                        {
                            hasPrimaryKeyOrIndex = true;
                        }
                    }
                }
            }
            if (!hasPrimaryKeyOrIndex)
            {
                Replacements.Add(new Replacement {
                    SourceIndex = context.Stop.StopIndex + 1, SourceLength = 0, Target = $", INDEX IX_INDEX NONCLUSTERED ({firstColumn}) "
                });
            }
            return(base.VisitColumn_def_table_constraints(context));
        }