Example #1
0
        public override void EnterPredicate([NotNull] TSqlParser.PredicateContext context)
        {
            base.EnterPredicate(context);

            string debug          = context.GetText();
            var    sourceInterval = context.SourceInterval;

            Console.WriteLine("EnterPredicate:");
            Console.WriteLine(debug);
            Console.WriteLine("---");


            var select = GetStatementAsSelect();
            var part   = new StatementPart();

            part.StatementTableName = select.Tables.FirstOrDefault();
            part.Text            = context.GetText();
            part.StatementOrigin = "EnterPredicate";

            int      a        = context.Start.StartIndex;
            int      b        = context.Stop.StopIndex;
            Interval interval = new Interval(a, b);

            _charStream = context.Start.InputStream;

            part.TextWithWhiteSpace = _charStream.GetText(interval);

            var parent = context.Parent.Parent;

            if (parent != null)
            {
                part.StatementParent = parent.GetText();
                var tokenInterval = parent.SourceInterval;
                part.StatementParentWithWhiteSpace = GetWhitespaceStringFromTokenInterval(tokenInterval);
            }

            var grandparent = context.Parent.Parent.Parent;

            if (grandparent != null)
            {
                part.StatementGrandParent = grandparent.GetText();
                var tokenInterval = grandparent.SourceInterval;
                part.StatementGrandParentWithWhiteSpace = GetWhitespaceStringFromTokenInterval(tokenInterval);
            }

            part.ParseStatementPart();
            select.Statements.Add(part);
        }
Example #2
0
    public override void EnterPredicate([NotNull] TSqlParser.PredicateContext context)
    {
        base.EnterPredicate(context);
        Console.WriteLine(context.GetText());

        var part = new StatementPart();

        part.StatementTableName = _dmlStatement.Tables.FirstOrDefault();
        part.Text            = context.GetText();
        part.StatementOrigin = "EnterPredicate";

        part.TextWithWhiteSpace = GetWhiteSpaceFormat(context);

        var parent = context.Parent.Parent;

        if (parent != null)
        {
            part.StatementParent = parent.GetText();
            var tokenInterval = parent.SourceInterval;
            part.StatementParentWithWhiteSpace = GetWhitespaceStringFromTokenInterval(tokenInterval);
        }

        var grandparent = context.Parent.Parent.Parent;

        if (grandparent != null)
        {
            part.StatementGrandParent = grandparent.GetText();
            var tokenInterval = grandparent.SourceInterval;
            part.StatementGrandParentWithWhiteSpace = GetWhitespaceStringFromTokenInterval(tokenInterval);
        }

        if (!part.ParseStatementPart())
        {
            _dmlStatement.IsValid = false;
        }

        _dmlStatement.WhereClause.Conditions.Add(part);
    }