private PredicateSegment CreateInSegment(SqlServerCommandParser.PredicateContext context) { ColumnSegment column = (ColumnSegment)Visit(context.bitExpr(0)); PredicateBracketValue predicateBracketValue = CreateBracketValue(context); return(new PredicateSegment(context.Start.StartIndex, context.Stop.StopIndex, column, new PredicateInRightValue(predicateBracketValue, GetExpressionSegments(context)))); }
private PredicateSegment CreateBetweenSegment(SqlServerCommandParser.PredicateContext context) { ColumnSegment column = (ColumnSegment)Visit(context.bitExpr(0)); IExpressionSegment between = (IExpressionSegment)Visit(context.bitExpr(1)); IExpressionSegment and = (IExpressionSegment)Visit(context.predicate()); return(new PredicateSegment(context.Start.StartIndex, context.Stop.StopIndex, column, new PredicateBetweenRightValue(between, and))); }
private PredicateBracketValue CreateBracketValue(SqlServerCommandParser.PredicateContext context) { PredicateLeftBracketValue predicateLeftBracketValue = null != context.subquery() ? new PredicateLeftBracketValue(context.subquery().LP_().Symbol.StartIndex, context.subquery().LP_().Symbol.StopIndex) : new PredicateLeftBracketValue(context.LP_().Symbol.StartIndex, context.LP_().Symbol.StopIndex); PredicateRightBracketValue predicateRightBracketValue = null != context.subquery() ? new PredicateRightBracketValue(context.subquery().RP_().Symbol.StartIndex, context.subquery().RP_().Symbol.StopIndex) : new PredicateRightBracketValue(context.RP_().Symbol.StartIndex, context.RP_().Symbol.StopIndex); return(new PredicateBracketValue(predicateLeftBracketValue, predicateRightBracketValue)); }
private ICollection <IExpressionSegment> GetExpressionSegments(SqlServerCommandParser.PredicateContext context) { ICollection <IExpressionSegment> result = new LinkedList <IExpressionSegment>(); if (null != context.subquery()) { SqlServerCommandParser.SubqueryContext subquery = context.subquery(); result.Add(new SubQueryExpressionSegment(new SubQuerySegment(subquery.Start.StartIndex, subquery.Stop.StopIndex, (SelectCommand)Visit(context.subquery())))); return(result); } foreach (var expr in context.expr()) { result.Add((IExpressionSegment)Visit(expr)); } return(result); }
public override IASTNode VisitPredicate(SqlServerCommandParser.PredicateContext context) { if (null != context.IN() && null == context.NOT()) { return(CreateInSegment(context)); } if (null != context.BETWEEN() && null == context.NOT()) { return(CreateBetweenSegment(context)); } if (1 == context.children.Count) { return(Visit(context.bitExpr(0))); } return(VisitRemainPredicate(context)); }
private IASTNode VisitRemainPredicate(SqlServerCommandParser.PredicateContext context) { foreach (var bitExpr in context.bitExpr()) { Visit(bitExpr); } foreach (var expr in context.expr()) { Visit(expr); } foreach (var simpleExpr in context.simpleExpr()) { Visit(simpleExpr); } if (null != context.predicate()) { Visit(context.predicate()); } return(new CommonExpressionSegment(context.Start.StartIndex, context.Stop.StopIndex, context.GetText())); }