/// <summary> /// 重新组合SQL语句(带上有效时间和删除标识) /// </summary> ///<param name="select"></param> private void RepackSelectSQL(SelectBuilder select) { var projections = select.Projection; var tables = select.Sources; var where = select.Where; int fieldCount = projections.Count(); if (fieldCount > 0) { var arryProjections = projections.ToArray(); for (int i = 0; i < fieldCount; i++) { IProjectionItem item = arryProjections[i].ProjectionItem; if (item is AllColumns)//* { AllColumns currItem = item as AllColumns; //移除掉重新构建 select.RemoveProjection(arryProjections[i]); HandleSelectStarStatement(select, currItem); } else if (item is Column) { Column currItem = item as Column; HandleSelectStatement(select, arryProjections[i], currItem); } } } HandlerInFilterWhere(where); ParserWhere(select); }
/// <summary> /// Constructor. /// </summary> /// <param name="proj">Source projection.</param> /// <param name="item">New item.</param> private ClientClusterGroupProjection(ClientClusterGroupProjection proj, IProjectionItem item) { _filter = new List <IProjectionItem>(proj._filter) { item }; }
/// <summary> /// Adds the given projection item to the values list. /// </summary> /// <param name="item">The value to add.</param> public void AddValue(IProjectionItem item) { if (item == null) { throw new ArgumentNullException("item"); } _values.Add(item); }
/// <summary> /// Adds the given projection item from the values list. /// </summary> /// <param name="item">The item to remove.</param> /// <returns>True if the item was removed; otherwise, false.</returns> public bool RemoveValue(IProjectionItem item) { if (item == null) { throw new ArgumentNullException("item"); } return(_values.Remove(item)); }
/// <summary> /// Initializes a new instance of a Negation. /// </summary> /// <param name="item">The item to negate.</param> public Negation(IProjectionItem item) { if (item == null) { throw new ArgumentNullException("item"); } Item = item; }
/// <summary> /// Initializes a new instance of a Top. /// </summary> /// <param name="expression">The number or percent of items to return.</param> public Top(IProjectionItem expression) { if (expression == null) { throw new ArgumentNullException("expression"); } _expression = expression; }
/// <summary> /// Initializes a new instance of a MatchCase. /// </summary> /// <param name="item">The item that will be matched to the different values.</param> public MatchCase(IProjectionItem item) { if (item == null) { throw new ArgumentNullException("item"); } Item = item; branches = new List<MatchCaseBranch>(); }
/// <summary> /// Initializes a new instance of a MatchCase. /// </summary> /// <param name="item">The item that will be matched to the different values.</param> public MatchCase(IProjectionItem item) { if (item == null) { throw new ArgumentNullException("item"); } Item = item; branches = new List <MatchCaseBranch>(); }
/// <summary> /// Adds a projection item to the output projection. /// </summary> /// <param name="item">The projection item to add.</param> /// <param name="alias">The alias to refer to the item with.</param> /// <returns>The item that was added.</returns> public AliasedProjection AddOutputProjection(IProjectionItem item, string alias = null) { if (item == null) { throw new ArgumentNullException("item"); } AliasedProjection projection = new AliasedProjection(item, alias); _outputProjection.Add(projection); return(projection); }
/// <summary> /// Adds the item as a partitioner. /// </summary> /// <param name="item">The item to partition the records on.</param> /// <returns>An aliased projection wrapping the given item.</returns> public AliasedProjection AddPartition(IProjectionItem item) { if (item == null) { throw new ArgumentNullException("item"); } AliasedProjection projection = new AliasedProjection(item, null); partitionItems.Add(projection); return(projection); }
/// <summary> /// Initializes a new instance of a ArithmeticExpression. /// </summary> /// <param name="leftHand">The left hand side of the expression.</param> /// <param name="rightHand">The right hand side of the expression.</param> protected ArithmeticExpression(IProjectionItem leftHand, IProjectionItem rightHand) { if (leftHand == null) { throw new ArgumentNullException("leftHand"); } if (rightHand == null) { throw new ArgumentNullException("rightHand"); } _leftHand = leftHand; _rightHand = rightHand; }
/// <summary> /// Initializes a new instance of a OrderBy. /// </summary> /// <param name="projection">The item to sort by.</param> /// <param name="order">The order in which to sort the items.</param> /// <param name="nullPlacement">The placement of nulls in the results.</param> public OrderBy( IProjectionItem projection, Order order = Order.Default, NullPlacement nullPlacement = NullPlacement.Default) { if (projection == null) { throw new ArgumentNullException("projection"); } Projection = new AliasedProjection(projection, null); Order = order; NullPlacement = nullPlacement; }
/// <summary> /// Initializes a new instance of a Setter. /// </summary> /// <param name="column">The name of the column to set.</param> /// <param name="value">The value to set the column to.</param> public Setter(Column column, IProjectionItem value) { if (column == null) { throw new ArgumentNullException("column"); } if (value == null) { throw new ArgumentNullException("value"); } _column = column; _value = value; }
private static void LogProjectionItem(IProjectionItem projectionItem, StringBuilder logBuilder, int indentLevel) { var indent = GetIndent(indentLevel); var column = projectionItem as Column; if (column != null) { logBuilder.AppendLine(string.Format("{0} Column Name: {1}, Qualify? {2}", indent, column.Name, column.Qualify.GetValueOrDefault())); if (column.Source != null) { logBuilder.AppendLine(string.Format("{0} Column Source: ", indent)); LogAliasedSource(column.Source, logBuilder, indentLevel + 1); } } }
/// <summary> /// Adds the case option to the case expression. /// </summary> /// <param name="filter">The value that the case item must equal for given the result to be returned.</param> /// <param name="result">The value to return when the item equals the option.</param> public ConditionalCaseBranch AddBranch(IFilter filter, IProjectionItem result) { if (filter == null) { throw new ArgumentNullException("filter"); } if (result == null) { throw new ArgumentNullException("result"); } ConditionalCaseBranch branch = new ConditionalCaseBranch(); branch.Condition = filter; branch.Value = result; branches.Add(branch); return branch; }
/// <summary> /// Adds a branch with the given option and value to the case expression. /// </summary> /// <param name="option">The value that the case item must equal for given the result to be returned.</param> /// <param name="value">The value to return when the item equals the option.</param> public MatchCaseBranch AddBranch(IProjectionItem option, IProjectionItem value) { if (option == null) { throw new ArgumentNullException("option"); } if (value == null) { throw new ArgumentNullException("value"); } MatchCaseBranch branch = new MatchCaseBranch(); branch.Option = option; branch.Value = value; branches.Add(branch); return branch; }
/// <summary> /// Adds the case option to the case expression. /// </summary> /// <param name="filter">The value that the case item must equal for given the result to be returned.</param> /// <param name="result">The value to return when the item equals the option.</param> public ConditionalCaseBranch AddBranch(IFilter filter, IProjectionItem result) { if (filter == null) { throw new ArgumentNullException("filter"); } if (result == null) { throw new ArgumentNullException("result"); } ConditionalCaseBranch branch = new ConditionalCaseBranch(); branch.Condition = filter; branch.Value = result; branches.Add(branch); return(branch); }
/// <summary> /// Adds a branch with the given option and value to the case expression. /// </summary> /// <param name="option">The value that the case item must equal for given the result to be returned.</param> /// <param name="value">The value to return when the item equals the option.</param> public MatchCaseBranch AddBranch(IProjectionItem option, IProjectionItem value) { if (option == null) { throw new ArgumentNullException("option"); } if (value == null) { throw new ArgumentNullException("value"); } MatchCaseBranch branch = new MatchCaseBranch(); branch.Option = option; branch.Value = value; branches.Add(branch); return(branch); }
/// <summary> /// 获得解析select语句不在主where部分加有效期限制 /// </summary> /// <returns></returns> public string ParserSelectSqlNoWhere() { //解析SQL语句 CommandBuilder commandBuilder = new CommandBuilder(); ICommand command = commandBuilder.GetCommand(_sql); if (command is SelectBuilder) { SelectBuilder select = command as SelectBuilder; var projections = select.Projection; int fieldCount = projections.Count(); if (fieldCount > 0) { var arryProjections = projections.ToArray(); for (int i = 0; i < fieldCount; i++) { IProjectionItem item = arryProjections[i].ProjectionItem; if (item is AllColumns)//* { AllColumns currItem = item as AllColumns; //移除掉重新构建 select.RemoveProjection(arryProjections[i]); HandleSelectStarStatement(select, currItem); } else if (item is Column) { Column currItem = item as Column; HandleSelectStatement(select, arryProjections[i], currItem); i++; } } } Formatter formatter = new Formatter(); string newSql = formatter.GetCommandText(command); return(newSql); } return(string.Empty); }
/// <summary> /// Adds the given projection item from the values list. /// </summary> /// <param name="item">The item to remove.</param> /// <returns>True if the item was removed; otherwise, false.</returns> public bool RemoveValue(IProjectionItem item) { if (item == null) { throw new ArgumentNullException("item"); } return _values.Remove(item); }
/// <summary> /// Initializes a new instance of a Addition. /// </summary> /// <param name="leftHand">The left hand side of the expression.</param> /// <param name="rightHand">The right hand side of the expression.</param> public Addition(IProjectionItem leftHand, IProjectionItem rightHand) : base(leftHand, rightHand) { }
/// <summary> /// Initializes a new instance of a Multiplication. /// </summary> /// <param name="leftHand">The left hand side of the expression.</param> /// <param name="rightHand">The right hand side of the expression.</param> public Multiplication(IProjectionItem leftHand, IProjectionItem rightHand) : base(leftHand, rightHand) { }
/// <summary> /// Adds a projection item to the projection. /// </summary> /// <param name="item">The projection item to add.</param> /// <param name="alias">The alias to refer to the item with.</param> /// <returns>The item that was added.</returns> public AliasedProjection AddProjection(IProjectionItem item, string alias = null) { if (item == null) { throw new ArgumentNullException("item"); } AliasedProjection projection = new AliasedProjection(item, alias); _projection.Add(projection); return projection; }
private object buildAdditiveOperator(MatchResult result, IProjectionItem leftHand, IProjectionItem rightHand, bool wrap) { MatchResult plusResult = result.Matches[SqlGrammar.AdditiveOperator.PlusOperator]; if (plusResult.IsMatch) { Addition addition = new Addition(leftHand, rightHand); addition.WrapInParentheses = wrap; return addition; } MatchResult minusResult = result.Matches[SqlGrammar.AdditiveOperator.MinusOperator]; if (minusResult.IsMatch) { Subtraction subtraction = new Subtraction(leftHand, rightHand); subtraction.WrapInParentheses = wrap; return subtraction; } throw new InvalidOperationException(); }
/// <summary> /// Initializes a new instance of a Division. /// </summary> /// <param name="leftHand">The left hand side of the expression.</param> /// <param name="rightHand">The right hand side of the expression.</param> public Division(IProjectionItem leftHand, IProjectionItem rightHand) : base(leftHand, rightHand) { }
/// <summary> /// Removes the given projection item from the arguments list. /// </summary> /// <param name="item">The item to remove.</param> /// <returns>True if the item was removed; otherwise, false.</returns> public bool RemoveArgument(IProjectionItem item) { return(arguments.Remove(item)); }
/// <summary> /// Initializes a new instance of an AliasedProjection. /// </summary> /// <param name="item">The projection item.</param> /// <param name="alias">The alias to refer to the item with.</param> internal AliasedProjection(IProjectionItem item, string alias = null) { ProjectionItem = item; Alias = alias; }
/// <summary> /// Initializes a new instance of a Modulus. /// </summary> /// <param name="leftHand">The left hand side of the expression.</param> /// <param name="rightHand">The right hand side of the expression.</param> public Modulus(IProjectionItem leftHand, IProjectionItem rightHand) : base(leftHand, rightHand) { }
/// <summary> /// Removes the given projection item from the arguments list. /// </summary> /// <param name="item">The item to remove.</param> /// <returns>True if the item was removed; otherwise, false.</returns> public bool RemoveArgument(IProjectionItem item) { return arguments.Remove(item); }
/// <summary> /// Adds the given projection item to the arguments list. /// </summary> /// <param name="item">The value to add.</param> public void AddArgument(IProjectionItem item) { arguments.Add(item); }
/// <summary> /// Initializes a new instance of a Subtraction. /// </summary> /// <param name="leftHand">The left hand side of the expression.</param> /// <param name="rightHand">The right hand side of the expression.</param> public Subtraction(IProjectionItem leftHand, IProjectionItem rightHand) : base(leftHand, rightHand) { }
/// <summary> /// Adds the item as a partitioner. /// </summary> /// <param name="item">The item to partition the records on.</param> /// <returns>An aliased projection wrapping the given item.</returns> public AliasedProjection AddPartition(IProjectionItem item) { if (item == null) { throw new ArgumentNullException("item"); } AliasedProjection projection = new AliasedProjection(item, null); partitionItems.Add(projection); return projection; }
private object buildMultiplicitiveOperator(MatchResult result, IProjectionItem leftHand, IProjectionItem rightHand, bool wrap) { MatchResult multiply = result.Matches[SqlGrammar.MultiplicitiveOperator.Multiply]; if (multiply.IsMatch) { Multiplication multiplication = new Multiplication(leftHand, rightHand); multiplication.WrapInParentheses = wrap; return multiplication; } MatchResult divide = result.Matches[SqlGrammar.MultiplicitiveOperator.Divide]; if (divide.IsMatch) { Division division = new Division(leftHand, rightHand); division.WrapInParentheses = wrap; return division; } MatchResult modulo = result.Matches[SqlGrammar.MultiplicitiveOperator.Modulus]; if (modulo.IsMatch) { Modulus modulus = new Modulus(leftHand, rightHand); modulus.WrapInParentheses = wrap; return modulus; } throw new InvalidOperationException(); }