FunctionCall MakeDateExtractor(ExtractFunction extractFunction) { if (extractFunction == null) { throw new ArgumentNullException("extractFunction"); } FunctionCall functionCall = new FunctionCall("DATEPART"); functionCall.ExpressionArguments = new ExpressionItem(extractFunction.FieldSpec); functionCall.ExpressionArguments.Add(new ExpressionItem(extractFunction.Source)); return(functionCall); }
public override void PerformAfter(FunctionCall node) { if (node == null) { throw new ArgumentNullException("node"); } base.PerformAfter(node); if (TailorUtil.SUBSTRING.Equals(node.Name.ToLowerInvariant())) { ReplaceTerm(node, MakeSubstring(node)); } }
public override void PerformBefore(FunctionCall node) { if (node == null) { throw new ArgumentNullException("node"); } if (TailorUtil.NOW.Equals(node.Name.ToLowerInvariant())) { node.Name = TailorUtil.GETDATE.ToUpperInvariant(); } base.PerformBefore(node); }
public override void PerformBefore(FunctionCall node) { if (node == null) { throw new ArgumentNullException("node"); } string name = node.Name.ToLowerInvariant(); if (name.Equals(TailorUtil.GETDATE)) { ReplaceTerm(node, new DbObject(new Identifier( TailorUtil.CURRENT_TIMESTAMP.ToUpperInvariant()))); } base.PerformBefore(node); }
protected override FunctionCall GetDateaddCall(DateTimeUnit unit, INode number, INode date) { if (unit == null) { throw new ArgumentNullException("unit"); } if (number == null) { throw new ArgumentNullException("number"); } if (date == null) { throw new ArgumentNullException("date"); } if (unit == DateTimeUnit.Month) { throw new ArgumentNullException("Standard month arithmetic not supported."); } if (m_intervals == null) { m_intervals = new Dictionary <DateTimeUnit, string>(); m_intervals.Add(DateTimeUnit.Year, "yyyy"); m_intervals.Add(DateTimeUnit.Month, "m"); m_intervals.Add(DateTimeUnit.Day, "d"); m_intervals.Add(DateTimeUnit.Hour, "h"); m_intervals.Add(DateTimeUnit.Minute, "n"); m_intervals.Add(DateTimeUnit.Second, "s"); } FunctionCall dateadd = new FunctionCall(TailorUtil.DATEADD.ToUpperInvariant()); StringValue stringValue = new StringValue(m_intervals[unit]); stringValue.QuoteType = '\"'; dateadd.ExpressionArguments = new ExpressionItem(stringValue); dateadd.ExpressionArguments.Add(new ExpressionItem(number)); dateadd.ExpressionArguments.Add(new ExpressionItem(date)); return(dateadd); }
public INode Clone() { FunctionCall functionCall = new FunctionCall(m_name); if (m_expressionArguments != null) { functionCall.ExpressionArguments = (ExpressionItem)(m_expressionArguments.Clone()); } functionCall.Distinct = m_distinct; if (m_star) { functionCall.Star = Wildcard.Value; } return(functionCall); }
void CoalesceToIif(FunctionCall coalesce) { ExpressionItem args = coalesce.ExpressionArguments; if (args == null) { throw new InvalidOperationException("COALESCE has no arguments."); } if (args.Next == null) { throw new InvalidOperationException("COALESCE has just one argument."); } FunctionCall iif = (FunctionCall)MakeIif(args); coalesce.Name = iif.Name; coalesce.ExpressionArguments = iif.ExpressionArguments; }
/// <summary> /// Constructs the last argument for substring functions. /// </summary> /// <param name="startExpr"> /// First argument of the substring function /// (<c>ExpressionItem.Expression</c>, not the top-level <c>ExpressionItem</c>). /// </param> /// <param name="valExpr"> /// Second argument of the substring function /// (<c>ExpressionItem.Expression</c>, not the top-level <c>ExpressionItem</c>). /// </param> /// <param name="lenName"> /// Name of the length function (must not be null). /// </param> public static IExpression MakeLenArg(INode startExpr, INode valExpr, string lenName) { if (startExpr == null) { throw new ArgumentNullException("startExpr"); } if (valExpr == null) { throw new ArgumentNullException("valExpr"); } if (lenName == null) { throw new ArgumentNullException("lenName"); } FunctionCall lenCall = new FunctionCall(lenName); lenCall.ExpressionArguments = new ExpressionItem(valExpr.Clone()); IExpression argument; INode startTerm = GetTerm(startExpr); IntegerValue integerValue = startTerm as IntegerValue; if ((integerValue != null) && (integerValue.Value == 1)) { argument = lenCall; } else { Expression left = new Expression(lenCall, ExpressionOperator.Plus, new IntegerValue(1)); argument = new Expression(left, ExpressionOperator.Minus, startTerm.Clone()); } return(argument); }
public override void PerformBefore(FunctionCall node) { if (node == null) { throw new ArgumentNullException("node"); } string name = node.Name; Debug.Assert(name != null); m_sql.Append(name); m_sql.Append('('); if (node.Distinct) { m_sql.Append("DISTINCT "); } }
public override void PerformBefore(FunctionCall node) { if (node == null) { throw new ArgumentNullException("node"); } base.PerformBefore(node); string name = node.Name.ToLowerInvariant(); if (name.Equals(TailorUtil.GETDATE)) { node.Name = TailorUtil.GetCapitalized(TailorUtil.NOW); } else if (name.Equals(TailorUtil.COALESCE)) { CoalesceToIif(node); } }
public static bool HasNullArgument(FunctionCall functionCall) { if (functionCall == null) { throw new ArgumentNullException("functionCall"); } ExpressionItem argument = functionCall.ExpressionArguments; while (argument != null) { INode term = GetTerm(argument.Expression); if (term == NullValue.Value) { return(true); } argument = argument.Next; } return(false); }
public virtual void PerformAfter(FunctionCall node) { }
public virtual void PerformBefore(FunctionCall node) { }
INode MakeSubstring(FunctionCall substringCall) { if (substringCall == null) { throw new ArgumentNullException("substringCall"); } if (TailorUtil.HasNullArgument(substringCall)) { return(NullValue.Value); } ExpressionItem val = substringCall.ExpressionArguments; if (val == null) { throw new InvalidOperationException("No parameters for SUBSTRING."); } ExpressionItem start = val.Next; if (start == null) { throw new InvalidOperationException("Too few parameters for SUBSTRING."); } ExpressionItem len = start.Next; // before adding len to the list Expression when = MakeNotNullCheck(substringCall.ExpressionArguments); if (len == null) { IExpression argument = TailorUtil.MakeLenArg(start.Expression, val.Expression, "LEN"); start.Add(new ExpressionItem(argument)); } else { if (len.Next != null) { throw new InvalidOperationException("Too many parameters for SUBSTRING."); } } if (when != null) { CaseExpression caseExpression = new CaseExpression(); caseExpression.Alternatives = new CaseAlternative(when, substringCall); Expression elseExpr = new Expression(); elseExpr.Left = NullValue.Value; caseExpression.Else = elseExpr; return(caseExpression); } else { return(substringCall); } }
public override void PerformAfter(FunctionCall node) { PopKnownParent(node); }
public override void PerformBefore(FunctionCall node) { PushParent(node); }