public void Visit(LikeOperator op) { _conditionWriter.WriteStartElement("like"); op.Left.Visit(this); op.Right.Visit(this); _conditionWriter.WriteEndElement(); }
public virtual IExpression Clone(LikeOperator op) { return(new LikeOperator() { Left = CloneAndReturn(op.Left), Right = CloneValue(op.Left, op.Right) }.Normalize()); }
protected virtual void Visit(LikeOperator op, bool not) { AddParenthesesIfNeeded(op, () => { op.Left.Visit(this); Writer.Write((not ? " not" : "") + " like "); op.Right.Visit(this); }); }
public void Visit(LikeOperator op) { var norm = op.Normalize(); if (!object.ReferenceEquals(norm, op)) { norm.Visit(this); return; } if (!(op.Right is PatternList pattern && pattern.Patterns.Count == 1)) { throw new NotSupportedException(); } var matches = pattern.Patterns[0].Matches; if (matches.Count == 1 && matches[0] is StringMatch s1) { if (_version.OnlySupportsV2OrV3()) { WriteEncoded("substringof('"); WriteEncoded(s1.Match.ToString().Replace("'", "''")); WriteEncoded("',"); op.Left.Visit(this); WriteEncoded(")"); } else { WriteEncoded("contains("); op.Left.Visit(this); WriteEncoded(",'"); WriteEncoded(s1.Match.ToString().Replace("'", "''")); WriteEncoded("')"); } } else if (matches.Count == 2 && matches[0] is Anchor a2 && a2.Type == AnchorType.Start_Absolute && matches[1] is StringMatch s2) { WriteEncoded("startswith("); op.Left.Visit(this); WriteEncoded(",'"); WriteEncoded(s2.Match.ToString().Replace("'", "''")); WriteEncoded("')"); }
protected override void Visit(LikeOperator op, bool not) { if (op.Right is PatternList pat) { var pattern = default(StringLiteral); var isRegex = false; try { pattern = new StringLiteral(Oracle.Render(pat)); } catch (NotSupportedException) { var writer = new RegexWriter(); pat.Visit(writer); pattern = new StringLiteral(writer.ToString()); isRegex = true; } AddParenthesesIfNeeded(op, () => { if (isRegex) { if (not) { Writer.Write(" not "); } Writer.Write("regexp_like("); op.Left.Visit(this); Writer.Write(","); pattern.Visit(this); Writer.Write(", 'i')"); } else { op.Left.Visit(this); Writer.Write((not ? " not" : "") + " like "); pattern.Visit(this); } }); } else { base.Visit(op, not); } }
public IExpression Normalize() { switch (Name.ToLowerInvariant()) { case "concat": if (_ptr < 1) { throw new NotSupportedException(); } if (_ptr == 1) { return(_args[0]); } var concat = (IExpression) new ConcatenationOperator() { Left = _args[0], Right = _args[1] }.Normalize(); for (var i = 2; i < _ptr; i++) { concat = new ConcatenationOperator() { Left = concat, Right = _args[i] }.Normalize(); } return(concat); case "contains": case "endswith": case "startswith": if (_ptr == 2) { return(LikeOperator.FromMethod(Name, _args[0], _args[1])); } break; case "substringof": if (_ptr == 2) { return(LikeOperator.FromMethod("contains", _args[1], _args[0])); } break; case "indexof": if (_ptr == 2) { return(new Functions.IndexOf_Zero() { String = _args[0], Target = _args[1] }); } break; case "length": if (_ptr == 1) { return new Functions.Length() { String = _args[0] } } ; break; case "substring": if (_ptr == 2) { return(new Functions.Substring_Zero() { String = _args[0], Start = _args[1], Length = new SubtractionOperator() { Left = new Functions.Length() { String = _args[2] }, Right = _args[1] }.Normalize() }); } else if (_ptr == 3) { return(new Functions.Substring_Zero() { String = _args[0], Start = _args[1], Length = _args[2] }); } break; case "tolower": if (_ptr == 1) { return new Functions.ToLower() { String = _args[0] } } ; break; case "toupper": if (_ptr == 1) { return new Functions.ToUpper() { String = _args[0] } } ; break; case "trim": if (_ptr == 1) { return new Functions.Trim() { String = _args[0] } } ; break; case "date": if (_ptr == 1) { return new Functions.TruncateTime() { Expression = _args[0] } } ; break; case "day": if (_ptr == 1) { return new Functions.Day() { Expression = _args[0] } } ; break; case "fractionalseconds": if (_ptr == 1) { return(new DivisionOperator() { Left = new Functions.Millisecond() { Expression = _args[0] }, Right = new FloatLiteral(1000) }.Normalize()); } break; case "hour": if (_ptr == 1) { return new Functions.Hour() { Expression = _args[0] } } ; break; case "minute": if (_ptr == 1) { return new Functions.Minute() { Expression = _args[0] } } ; break; case "month": if (_ptr == 1) { return new Functions.Month() { Expression = _args[0] } } ; break; case "now": if (_ptr == 0) { return(new Functions.CurrentDateTime()); } break; case "second": if (_ptr == 1) { return new Functions.Second() { Expression = _args[0] } } ; break; case "year": if (_ptr == 1) { return new Functions.Year() { Expression = _args[0] } } ; break; case "ceiling": if (_ptr == 1) { return new Functions.Ceiling() { Value = _args[0] } } ; break; case "floor": if (_ptr == 1) { return new Functions.Floor() { Value = _args[0] } } ; break; case "round": if (_ptr == 1) { return new Functions.Round() { Value = _args[0], Digits = new IntegerLiteral(0) } } ; break; } throw new NotSupportedException(); } }
public void Visit(LikeOperator op) { Visit(op, false); }
public virtual void Visit(LikeOperator op) { op.Left.Visit(this); op.Right.Visit(this); }
void IExpressionVisitor.Visit(LikeOperator op) { _clone = Clone(op); }