コード例 #1
0
 /// <summary>
 /// Gets the match result for the item with the given name.
 /// </summary>
 /// <param name="itemName">The name of the item to get the results for.</param>
 /// <returns>The match result for the item with the given name -or- an empty MatchResult.</returns>
 public MatchResult this[string itemName]
 {
     get
     {
         MatchResult result;
         if (!resultLookup.TryGetValue(itemName, out result))
         {
             result = new MatchResult() { ItemName = itemName, IsMatch = false };
         }
         return result;
     }
 }
コード例 #2
0
ファイル: Expression.cs プロジェクト: kobynet/SQLGeneration
 /// <summary>
 /// Attempts to match the expression item with the values returned by the parser.
 /// </summary>
 /// <param name="attempt">The parser currently iterating over the token source.</param>
 /// <param name="itemName">The name of the item in the outer expression.</param>
 /// <returns>The results of the match.</returns>
 public MatchResult Match(IParseAttempt attempt, string itemName)
 {
     MatchResult result = new MatchResult() { ItemName = itemName, IsMatch = true };
     foreach (ExpressionItem detail in expression.Items)
     {
         IParseAttempt nextAttempt = attempt.Attempt();
         MatchResult innerResult = detail.Item.Match(nextAttempt, detail.ItemName);
         if (innerResult.IsMatch)
         {
             attempt.Accept(nextAttempt);
             result.Matches.Add(innerResult);
         }
         else
         {
             nextAttempt.Reject();
             if (detail.IsRequired)
             {
                 result.IsMatch = false;
                 return result;
             }
         }
     }
     return result;
 }
コード例 #3
0
 private void buildMatch(MatchResult result, MatchCase options)
 {
     MatchResult expressionResult = result.Matches[SqlGrammar.Match.Expression];
     IProjectionItem expression = (IProjectionItem)buildArithmeticItem(expressionResult);
     MatchResult valueResult = result.Matches[SqlGrammar.Match.Value];
     IProjectionItem value = (IProjectionItem)buildArithmeticItem(valueResult);
     options.AddBranch(expression, value);
 }
コード例 #4
0
 private void buildOrderByList(MatchResult result, List<OrderBy> orderByList)
 {
     MatchResult multiple = result.Matches[SqlGrammar.OrderByList.Multiple.Name];
     if (multiple.IsMatch)
     {
         MatchResult first = multiple.Matches[SqlGrammar.OrderByList.Multiple.First];
         buildOrderByItem(first, orderByList);
         MatchResult remaining = multiple.Matches[SqlGrammar.OrderByList.Multiple.Remaining];
         buildOrderByList(remaining, orderByList);
         return;
     }
     MatchResult single = result.Matches[SqlGrammar.OrderByList.Single];
     if (single.IsMatch)
     {
         buildOrderByItem(single, orderByList);
         return;
     }
     throw new InvalidOperationException();
 }
コード例 #5
0
 private ICommand buildDeleteStatement(MatchResult result)
 {
     MatchResult tableResult = result.Matches[SqlGrammar.DeleteStatement.Table];
     Table table = buildTable(tableResult);
     string alias = null;
     MatchResult aliasExpressionResult = result.Matches[SqlGrammar.DeleteStatement.AliasExpression.Name];
     if (aliasExpressionResult.IsMatch)
     {
         MatchResult aliasResult = aliasExpressionResult.Matches[SqlGrammar.DeleteStatement.AliasExpression.Alias];
         alias = getToken(aliasResult);
     }
     DeleteBuilder builder = new DeleteBuilder(table, alias);
     SourceCollection collection = new SourceCollection();
     collection.AddSource(builder.Table.GetSourceName(), builder.Table);
     scope.Push(collection);
     MatchResult whereResult = result.Matches[SqlGrammar.DeleteStatement.Where.Name];
     if (whereResult.IsMatch)
     {
         MatchResult filterListResult = whereResult.Matches[SqlGrammar.DeleteStatement.Where.FilterList];
         IFilter innerFilter = buildOrFilter(filterListResult);
         builder.WhereFilterGroup.AddFilter(innerFilter);
         builder.WhereFilterGroup.Optimize();
     }
     scope.Pop();
     return builder;
 }
コード例 #6
0
 private object buildNamedItem(MatchResult result)
 {
     List<string> parts = new List<string>();
     buildMultipartIdentifier(result, parts);
     if (parts.Count > 1)
     {
         // if is a period-separated, multiple-part identifier, it is a column
         Namespace qualifier = getNamespace(parts.Take(parts.Count - 2));
         string tableName = parts[parts.Count - 2];
         AliasedSource source = scope.GetSource(tableName);
         string columnName = parts[parts.Count - 1];
         return source.Column(columnName);
     }
     string name = parts[0];
     if (options.PlaceholderPrefix != null && name.StartsWith(options.PlaceholderPrefix))
     {
         // if the identifier begins with the placeholder prefix, treat is as a placeholder
         Placeholder placeholder = new Placeholder(name);
         return placeholder;
     }
     AliasedSource singleSource;
     if (scope.HasSingleSource(out singleSource))
     {
         // there is only one source in the query, so assume a column
         Column column = singleSource.Column(name);
         column.Qualify = false;
         return column;
     }
     // otherwise, we have no idea what the name represents
     // in order for the SQL to roundtrip without alteration, just use a placeholder
     Placeholder unknown = new Placeholder(name);
     return unknown;
 }
コード例 #7
0
 private NumericLiteral buildNumericLiteral(MatchResult result)
 {
     string numberString = getToken(result);
     double value = Double.Parse(numberString);
     return new NumericLiteral(value);
 }
コード例 #8
0
 private void buildMatchListPrime(MatchResult result, MatchCase options)
 {
     MatchResult matchResult = result.Matches[SqlGrammar.MatchListPrime.Match.Name];
     if (matchResult.IsMatch)
     {
         MatchResult firstResult = matchResult.Matches[SqlGrammar.MatchListPrime.Match.First];
         buildMatch(firstResult, options);
         MatchResult remainingResult = matchResult.Matches[SqlGrammar.MatchListPrime.Match.Remaining];
         buildMatchListPrime(remainingResult, options);
         return;
     }
     MatchResult elseResult = result.Matches[SqlGrammar.MatchListPrime.Else.Name];
     if (elseResult.IsMatch)
     {
         MatchResult valueResult = elseResult.Matches[SqlGrammar.MatchListPrime.Else.Value];
         options.Default = (IProjectionItem)buildArithmeticItem(valueResult);
         return;
     }
     MatchResult emptyResult = result.Matches[SqlGrammar.MatchListPrime.Empty];
     if (emptyResult.IsMatch)
     {
         return;
     }
     throw new InvalidOperationException();
 }
コード例 #9
0
 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();
 }
コード例 #10
0
 private void buildFromList(MatchResult result, SelectBuilder builder)
 {
     MatchResult multiple = result.Matches[SqlGrammar.FromList.Multiple.Name];
     if (multiple.IsMatch)
     {
         MatchResult first = multiple.Matches[SqlGrammar.FromList.Multiple.First];
         Join join = buildJoin(first, false);
         addJoinItem(builder, join);
         MatchResult remaining = multiple.Matches[SqlGrammar.FromList.Multiple.Remaining];
         buildFromList(remaining, builder);
         return;
     }
     MatchResult single = result.Matches[SqlGrammar.FromList.Single];
     if (single.IsMatch)
     {
         Join join = buildJoin(single, false);
         addJoinItem(builder, join);
         return;
     }
     throw new InvalidOperationException();
 }
コード例 #11
0
 private Function buildFunctionCall(MatchResult result)
 {
     MatchResult functionNameResult = result.Matches[SqlGrammar.FunctionCall.FunctionName];
     List<string> parts = new List<string>();
     buildMultipartIdentifier(functionNameResult, parts);
     Namespace qualifier = getNamespace(parts.Take(parts.Count - 1));
     string functionName = parts[parts.Count - 1];
     Function function = new Function(qualifier, functionName);
     MatchResult argumentsResult = result.Matches[SqlGrammar.FunctionCall.Arguments];
     if (argumentsResult.IsMatch)
     {
         ValueList arguments = new ValueList();
         buildValueList(argumentsResult, arguments);
         foreach (IProjectionItem value in arguments.Values)
         {
             function.AddArgument(value);
         }
     }
     MatchResult windowResult = result.Matches[SqlGrammar.FunctionCall.Window.Name];
     if (windowResult.IsMatch)
     {
         FunctionWindow window = new FunctionWindow();
         MatchResult partitioning = windowResult.Matches[SqlGrammar.FunctionCall.Window.Partitioning.Name];
         if (partitioning.IsMatch)
         {
             MatchResult valueListResult = partitioning.Matches[SqlGrammar.FunctionCall.Window.Partitioning.ValueList];
             ValueList valueList = new ValueList();
             buildValueList(valueListResult, valueList);
             foreach (IProjectionItem value in valueList.Values)
             {
                 window.AddPartition(value);
             }
         }
         MatchResult ordering = windowResult.Matches[SqlGrammar.FunctionCall.Window.Ordering.Name];
         if (ordering.IsMatch)
         {
             MatchResult orderByListResult = ordering.Matches[SqlGrammar.FunctionCall.Window.Ordering.OrderByList];
             buildOrderByList(orderByListResult, window.OrderByList);
         }
         MatchResult framing = windowResult.Matches[SqlGrammar.FunctionCall.Window.Framing.Name];
         if (framing.IsMatch)
         {
             MatchResult precedingOnlyFrameResult = framing.Matches[SqlGrammar.FunctionCall.Window.Framing.PrecedingFrame];
             if (precedingOnlyFrameResult.IsMatch)
             {
                 IPrecedingFrame precedingFrame = buildPrecedingFrame(precedingOnlyFrameResult);
                 window.Frame = new PrecedingOnlyWindowFrame(precedingFrame);
             }
             MatchResult betweenFrameResult = framing.Matches[SqlGrammar.FunctionCall.Window.Framing.BetweenFrame.Name];
             if (betweenFrameResult.IsMatch)
             {
                 MatchResult precedingFrameResult = betweenFrameResult.Matches[SqlGrammar.FunctionCall.Window.Framing.BetweenFrame.PrecedingFrame];
                 IPrecedingFrame precedingFrame = buildPrecedingFrame(precedingFrameResult);
                 MatchResult followingFrameResult = betweenFrameResult.Matches[SqlGrammar.FunctionCall.Window.Framing.BetweenFrame.FollowingFrame];
                 IFollowingFrame followingFrame = buildFollowingFrame(followingFrameResult);
                 window.Frame = new BetweenWindowFrame(precedingFrame, followingFrame);
             }
             MatchResult frameTypeResult = framing.Matches[SqlGrammar.FunctionCall.Window.Framing.FrameType];
             window.Frame.FrameType = buildFrameType(frameTypeResult);
         }
         function.FunctionWindow = window;
     }
     return function;
 }
コード例 #12
0
 private IFollowingFrame buildFollowingFrame(MatchResult result)
 {
     MatchResult unbound = result.Matches[SqlGrammar.FollowingFrame.UnboundedFollowing.Name];
     if (unbound.IsMatch)
     {
         return new FollowingUnboundFrame();
     }
     MatchResult bound = result.Matches[SqlGrammar.FollowingFrame.BoundedFollowing.Name];
     if (bound.IsMatch)
     {
         MatchResult rowCountResult = bound.Matches[SqlGrammar.FollowingFrame.BoundedFollowing.Number];
         NumericLiteral rowCount = buildNumericLiteral(rowCountResult);
         return new FollowingBoundFrame((int)rowCount.Value);
     }
     MatchResult currentRow = result.Matches[SqlGrammar.FollowingFrame.CurrentRow];
     if (currentRow.IsMatch)
     {
         return new CurrentRowFrame();
     }
     throw new InvalidOperationException();
 }
コード例 #13
0
 private FrameType buildFrameType(MatchResult result)
 {
     MatchResult rows = result.Matches[SqlGrammar.FrameType.Rows];
     if (rows.IsMatch)
     {
         return FrameType.Row;
     }
     MatchResult range = result.Matches[SqlGrammar.FrameType.Range];
     if (range.IsMatch)
     {
         return FrameType.Range;
     }
     throw new InvalidOperationException();
 }
コード例 #14
0
 private FilteredJoin buildFilteredJoin(MatchResult result, Join join, IRightJoinItem joinItem, string alias)
 {
     MatchResult innerResult = result.Matches[SqlGrammar.FilteredJoinType.InnerJoin];
     if (innerResult.IsMatch)
     {
         return join.InnerJoin(joinItem, alias);
     }
     MatchResult leftResult = result.Matches[SqlGrammar.FilteredJoinType.LeftOuterJoin];
     if (leftResult.IsMatch)
     {
         return join.LeftOuterJoin(joinItem, alias);
     }
     MatchResult rightResult = result.Matches[SqlGrammar.FilteredJoinType.RightOuterJoin];
     if (rightResult.IsMatch)
     {
         return join.RightOuterJoin(joinItem, alias);
     }
     MatchResult fullResult = result.Matches[SqlGrammar.FilteredJoinType.FullOuterJoin];
     if (fullResult.IsMatch)
     {
         return join.FullOuterJoin(joinItem, alias);
     }
     throw new InvalidOperationException();
 }
コード例 #15
0
 private IFilter buildFilter(MatchResult result)
 {
     MatchResult notResult = result.Matches[SqlGrammar.Filter.Not.Name];
     if (notResult.IsMatch)
     {
         MatchResult filterResult = notResult.Matches[SqlGrammar.Filter.Not.Filter];
         IFilter filter = buildFilter(filterResult);
         return new NotFilter(filter);
     }
     MatchResult wrappedResult = result.Matches[SqlGrammar.Filter.Wrapped.Name];
     if (wrappedResult.IsMatch)
     {
         MatchResult filterResult = wrappedResult.Matches[SqlGrammar.Filter.Wrapped.Filter];
         FilterGroup nested = new FilterGroup();
         IFilter innerFilter = buildOrFilter(filterResult);
         nested.AddFilter(innerFilter);
         nested.WrapInParentheses = true;
         return nested;
     }
     MatchResult quantifyResult = result.Matches[SqlGrammar.Filter.Quantify.Name];
     if (quantifyResult.IsMatch)
     {
         MatchResult expressionResult = quantifyResult.Matches[SqlGrammar.Filter.Quantify.Expression];
         IFilterItem filterItem = (IFilterItem)buildArithmeticItem(expressionResult);
         MatchResult quantifierResult = quantifyResult.Matches[SqlGrammar.Filter.Quantify.Quantifier];
         Quantifier quantifier = buildQuantifier(quantifierResult);
         IValueProvider valueProvider = null;
         MatchResult selectResult = quantifyResult.Matches[SqlGrammar.Filter.Quantify.SelectStatement];
         if (selectResult.IsMatch)
         {
             valueProvider = buildSelectStatement(selectResult);
         }
         MatchResult valueListResult = quantifyResult.Matches[SqlGrammar.Filter.Quantify.ValueList];
         if (valueListResult.IsMatch)
         {
             ValueList values = new ValueList();
             buildValueList(valueListResult, values);
             valueProvider = values;
         }
         MatchResult operatorResult = quantifyResult.Matches[SqlGrammar.Filter.Quantify.ComparisonOperator];
         return buildQuantifierFilter(operatorResult, filterItem, quantifier, valueProvider);
     }
     MatchResult functionResult = result.Matches[SqlGrammar.Filter.Function.Name];
     if (functionResult.IsMatch)
     {
         MatchResult expressionResult = functionResult.Matches[SqlGrammar.Filter.Function.Expression];
         return buildFunctionCall(expressionResult);
     }
     MatchResult orderResult = result.Matches[SqlGrammar.Filter.Order.Name];
     if (orderResult.IsMatch)
     {
         MatchResult leftResult = orderResult.Matches[SqlGrammar.Filter.Order.Left];
         IFilterItem left = (IFilterItem)buildArithmeticItem(leftResult);
         MatchResult rightResult = orderResult.Matches[SqlGrammar.Filter.Order.Right];
         IFilterItem right = (IFilterItem)buildArithmeticItem(rightResult);
         MatchResult operatorResult = orderResult.Matches[SqlGrammar.Filter.Order.ComparisonOperator];
         return buildOrderFilter(operatorResult, left, right);
     }
     MatchResult betweenResult = result.Matches[SqlGrammar.Filter.Between.Name];
     if (betweenResult.IsMatch)
     {
         MatchResult expressionResult = betweenResult.Matches[SqlGrammar.Filter.Between.Expression];
         IFilterItem expression = (IFilterItem)buildArithmeticItem(expressionResult);
         MatchResult lowerBoundResult = betweenResult.Matches[SqlGrammar.Filter.Between.LowerBound];
         IFilterItem lowerBound = (IFilterItem)buildArithmeticItem(lowerBoundResult);
         MatchResult upperBoundResult = betweenResult.Matches[SqlGrammar.Filter.Between.UpperBound];
         IFilterItem upperBound = (IFilterItem)buildArithmeticItem(upperBoundResult);
         BetweenFilter filter = new BetweenFilter(expression, lowerBound, upperBound);
         MatchResult betweenNotResult = betweenResult.Matches[SqlGrammar.Filter.Between.NotKeyword];
         filter.Not = betweenNotResult.IsMatch;
         return filter;
     }
     MatchResult likeResult = result.Matches[SqlGrammar.Filter.Like.Name];
     if (likeResult.IsMatch)
     {
         MatchResult leftResult = likeResult.Matches[SqlGrammar.Filter.Like.Left];
         IFilterItem left = (IFilterItem)buildArithmeticItem(leftResult);
         MatchResult rightResult = likeResult.Matches[SqlGrammar.Filter.Like.Right];
         IFilterItem right = (IFilterItem)buildArithmeticItem(rightResult);
         LikeFilter filter = new LikeFilter(left, right);
         MatchResult likeNotResult = likeResult.Matches[SqlGrammar.Filter.Like.NotKeyword];
         filter.Not = likeNotResult.IsMatch;
         return filter;
     }
     MatchResult isResult = result.Matches[SqlGrammar.Filter.Is.Name];
     if (isResult.IsMatch)
     {
         MatchResult expressionResult = isResult.Matches[SqlGrammar.Filter.Is.Expression];
         IFilterItem expression = (IFilterItem)buildArithmeticItem(expressionResult);
         NullFilter filter = new NullFilter(expression);
         MatchResult isNotResult = isResult.Matches[SqlGrammar.Filter.Is.NotKeyword];
         filter.Not = isNotResult.IsMatch;
         return filter;
     }
     MatchResult inResult = result.Matches[SqlGrammar.Filter.In.Name];
     if (inResult.IsMatch)
     {
         MatchResult expressionResult = inResult.Matches[SqlGrammar.Filter.In.Expression];
         IFilterItem expression = (IFilterItem)buildArithmeticItem(expressionResult);
         IValueProvider valueProvider = null;
         MatchResult valuesResult = inResult.Matches[SqlGrammar.Filter.In.Values.Name];
         if (valuesResult.IsMatch)
         {
             MatchResult valueListResult = valuesResult.Matches[SqlGrammar.Filter.In.Values.ValueList];
             ValueList values = new ValueList();
             buildValueList(valueListResult, values);
             valueProvider = values;
         }
         MatchResult selectResult = inResult.Matches[SqlGrammar.Filter.In.Select.Name];
         if (selectResult.IsMatch)
         {
             MatchResult selectStatementResult = selectResult.Matches[SqlGrammar.Filter.In.Select.SelectStatement];
             valueProvider = buildSelectStatement(selectStatementResult);
         }
         MatchResult functionCall = inResult.Matches[SqlGrammar.Filter.In.FunctionCall];
         if (functionCall.IsMatch)
         {
             valueProvider = buildFunctionCall(functionCall);
         }
         InFilter filter = new InFilter(expression, valueProvider);
         MatchResult inNotResult = inResult.Matches[SqlGrammar.Filter.In.NotKeyword];
         filter.Not = inNotResult.IsMatch;
         return filter;
     }
     MatchResult existsResult = result.Matches[SqlGrammar.Filter.Exists.Name];
     if (existsResult.IsMatch)
     {
         MatchResult selectExpressionResult = existsResult.Matches[SqlGrammar.Filter.Exists.SelectStatement];
         ISelectBuilder builder = buildSelectStatement(selectExpressionResult);
         ExistsFilter filter = new ExistsFilter(builder);
         return filter;
     }
     throw new InvalidOperationException();
 }
コード例 #16
0
 private DistinctQualifier buildDistinctQualifier(MatchResult result)
 {
     DistinctQualifierConverter converter = new DistinctQualifierConverter();
     MatchResult distinct = result.Matches[SqlGrammar.DistinctQualifier.Distinct];
     if (distinct.IsMatch)
     {
         return DistinctQualifier.Distinct;
     }
     MatchResult all = result.Matches[SqlGrammar.DistinctQualifier.All];
     if (all.IsMatch)
     {
         return DistinctQualifier.All;
     }
     throw new InvalidOperationException();
 }
コード例 #17
0
 private MatchCase buildMatchCase(MatchResult result)
 {
     MatchResult expressionResult = result.Matches[SqlGrammar.MatchCase.Expression];
     IProjectionItem expression = (IProjectionItem)buildArithmeticItem(expressionResult);
     MatchCase options = new MatchCase(expression);
     MatchResult matchListResult = result.Matches[SqlGrammar.MatchCase.MatchList];
     buildMatchList(matchListResult, options);
     return options;
 }
コード例 #18
0
 private void buildGroupByList(MatchResult result, SelectBuilder builder)
 {
     MatchResult multiple = result.Matches[SqlGrammar.GroupByList.Multiple.Name];
     if (multiple.IsMatch)
     {
         MatchResult firstResult = multiple.Matches[SqlGrammar.GroupByList.Multiple.First];
         IGroupByItem first = (IGroupByItem)buildArithmeticItem(firstResult);
         builder.AddGroupBy(first);
         MatchResult remainingResult = multiple.Matches[SqlGrammar.GroupByList.Multiple.Remaining];
         buildGroupByList(remainingResult, builder);
         return;
     }
     MatchResult single = result.Matches[SqlGrammar.GroupByList.Single];
     if (single.IsMatch)
     {
         IGroupByItem item = (IGroupByItem)buildArithmeticItem(single);
         builder.AddGroupBy(item);
         return;
     }
     throw new InvalidOperationException();
 }
コード例 #19
0
 private void buildMatchList(MatchResult result, MatchCase options)
 {
     MatchResult match = result.Matches[SqlGrammar.MatchList.Match];
     buildMatch(match, options);
     MatchResult matchListPrime = result.Matches[SqlGrammar.MatchList.MatchListPrime];
     buildMatchListPrime(matchListPrime, options);
 }
コード例 #20
0
 private ICommand buildInsertStatement(MatchResult result)
 {
     MatchResult tableResult = result.Matches[SqlGrammar.InsertStatement.Table];
     Table table = buildTable(tableResult);
     IValueProvider valueProvider = null;
     MatchResult valuesResult = result.Matches[SqlGrammar.InsertStatement.Values.Name];
     if (valuesResult.IsMatch)
     {
         ValueList values = new ValueList();
         MatchResult valueListResult = valuesResult.Matches[SqlGrammar.InsertStatement.Values.ValueList];
         if (valueListResult.IsMatch)
         {
             buildValueList(valueListResult, values);
         }
         valueProvider = values;
     }
     MatchResult selectResult = result.Matches[SqlGrammar.InsertStatement.Select.Name];
     if (selectResult.IsMatch)
     {
         MatchResult selectStatementResult = selectResult.Matches[SqlGrammar.InsertStatement.Select.SelectStatement];
         ISelectBuilder selectBuilder = buildSelectStatement(selectStatementResult);
         valueProvider = selectBuilder;
     }
     string alias = null;
     MatchResult aliasExpressionResult = result.Matches[SqlGrammar.InsertStatement.AliasExpression.Name];
     if (aliasExpressionResult.IsMatch)
     {
         MatchResult aliasResult = aliasExpressionResult.Matches[SqlGrammar.InsertStatement.AliasExpression.Alias];
         alias = getToken(aliasResult);
     }
     InsertBuilder builder = new InsertBuilder(table, valueProvider, alias);
     SourceCollection collection = new SourceCollection();
     collection.AddSource(builder.Table.GetSourceName(), builder.Table);
     scope.Push(collection);
     MatchResult columnsResult = result.Matches[SqlGrammar.InsertStatement.Columns.Name];
     if (columnsResult.IsMatch)
     {
         MatchResult columnListResult = columnsResult.Matches[SqlGrammar.InsertStatement.Columns.ColumnList];
         buildColumnsList(columnListResult, builder);
     }
     scope.Pop();
     return builder;
 }
コード例 #21
0
 private void buildMultipartIdentifier(MatchResult result, List<string> parts)
 {
     MatchResult multiple = result.Matches[SqlGrammar.MultipartIdentifier.Multiple.Name];
     if (multiple.IsMatch)
     {
         MatchResult first = multiple.Matches[SqlGrammar.MultipartIdentifier.Multiple.First];
         parts.Add(getToken(first));
         MatchResult remaining = multiple.Matches[SqlGrammar.MultipartIdentifier.Multiple.Remaining];
         buildMultipartIdentifier(remaining, parts);
         return;
     }
     MatchResult single = result.Matches[SqlGrammar.MultipartIdentifier.Single];
     if (single.IsMatch)
     {
         parts.Add(getToken(single));
         return;
     }
     throw new InvalidOperationException();
 }
コード例 #22
0
 private object buildItem(MatchResult result)
 {
     MatchResult numberResult = result.Matches[SqlGrammar.Item.Number];
     if (numberResult.IsMatch)
     {
         return buildNumericLiteral(numberResult);
     }
     MatchResult stringResult = result.Matches[SqlGrammar.Item.String];
     if (stringResult.IsMatch)
     {
         return buildStringLiteral(stringResult);
     }
     MatchResult nullResult = result.Matches[SqlGrammar.Item.Null];
     if (nullResult.IsMatch)
     {
         return new NullLiteral();
     }
     MatchResult functionCallResult = result.Matches[SqlGrammar.Item.FunctionCall];
     if (functionCallResult.IsMatch)
     {
         return buildFunctionCall(functionCallResult);
     }
     MatchResult columnResult = result.Matches[SqlGrammar.Item.Column];
     if (columnResult.IsMatch)
     {
         return buildNamedItem(columnResult);
     }
     MatchResult matchCaseResult = result.Matches[SqlGrammar.Item.MatchCase];
     if (matchCaseResult.IsMatch)
     {
         return buildMatchCase(matchCaseResult);
     }
     MatchResult conditionCaseResult = result.Matches[SqlGrammar.Item.ConditionCase];
     if (conditionCaseResult.IsMatch)
     {
         return buildConditionalCase(conditionCaseResult);
     }
     MatchResult selectResult = result.Matches[SqlGrammar.Item.Select.Name];
     if (selectResult.IsMatch)
     {
         MatchResult selectExpressionResult = selectResult.Matches[SqlGrammar.Item.Select.SelectStatement];
         return buildSelectStatement(selectExpressionResult);
     }
     throw new NotImplementedException();
 }
コード例 #23
0
 private object buildAdditiveExpression(MatchResult result, bool wrap)
 {
     MatchResult multiple = result.Matches[SqlGrammar.AdditiveExpression.Multiple.Name];
     if (multiple.IsMatch)
     {
         MatchResult firstResult = multiple.Matches[SqlGrammar.AdditiveExpression.Multiple.First];
         IProjectionItem first = (IProjectionItem)buildMultiplicitiveExpression(firstResult, false);
         MatchResult remainingResult = multiple.Matches[SqlGrammar.AdditiveExpression.Multiple.Remaining];
         IProjectionItem remaining = (IProjectionItem)buildAdditiveExpression(remainingResult, false);
         MatchResult operatorResult = multiple.Matches[SqlGrammar.AdditiveExpression.Multiple.Operator];
         return buildAdditiveOperator(operatorResult, first, remaining, wrap);
     }
     MatchResult single = result.Matches[SqlGrammar.AdditiveExpression.Single];
     if (single.IsMatch)
     {
         return buildMultiplicitiveExpression(single, wrap);
     }
     throw new InvalidOperationException();
 }
コード例 #24
0
 private Join buildJoin(MatchResult result, bool wrap)
 {
     MatchResult wrapped = result.Matches[SqlGrammar.Join.Wrapped.Name];
     if (wrapped.IsMatch)
     {
         MatchResult joinResult = wrapped.Matches[SqlGrammar.Join.Wrapped.Join];
         Join first = buildJoin(joinResult, true);
         first.WrapInParentheses = true;
         scope.Push(first.Sources);
         MatchResult joinPrime = wrapped.Matches[SqlGrammar.Join.Wrapped.JoinPrime];
         Join join = buildJoinPrime(joinPrime, first);
         scope.Pop();
         return join;
     }
     MatchResult joined = result.Matches[SqlGrammar.Join.Joined.Name];
     if (joined.IsMatch)
     {
         string alias;
         MatchResult joinItemResult = joined.Matches[SqlGrammar.Join.Joined.JoinItem];
         IRightJoinItem first = buildJoinItem(joinItemResult, out alias);
         Join start = Join.From(first, alias);
         scope.Push(start.Sources);
         MatchResult joinPrime = joined.Matches[SqlGrammar.Join.Joined.JoinPrime];
         Join join = buildJoinPrime(joinPrime, start);
         scope.Pop();
         return join;
     }
     throw new InvalidOperationException();
 }
コード例 #25
0
 private NullPlacement buildNullPlacement(MatchResult result)
 {
     MatchResult nullsFirst = result.Matches[SqlGrammar.NullPlacement.NullsFirst];
     if (nullsFirst.IsMatch)
     {
         return NullPlacement.First;
     }
     MatchResult nullsLast = result.Matches[SqlGrammar.NullPlacement.NullsLast];
     if (nullsLast.IsMatch)
     {
         return NullPlacement.Last;
     }
     throw new InvalidOperationException();
 }
コード例 #26
0
 private ConditionalCase buildConditionalCase(MatchResult result)
 {
     ConditionalCase options = new ConditionalCase();
     MatchResult conditionListResult = result.Matches[SqlGrammar.ConditionalCase.ConditionList];
     buildConditionList(conditionListResult, options);
     return options;
 }
コード例 #27
0
 private void buildOrderByItem(MatchResult result, List<OrderBy> orderByList)
 {
     MatchResult expressionResult = result.Matches[SqlGrammar.OrderByItem.Expression];
     IProjectionItem expression = (IProjectionItem)buildArithmeticItem(expressionResult);
     Order order = Order.Default;
     MatchResult directionResult = result.Matches[SqlGrammar.OrderByItem.OrderDirection];
     if (directionResult.IsMatch)
     {
         order = buildOrderDirection(directionResult);
     }
     NullPlacement placement = NullPlacement.Default;
     MatchResult placementResult = result.Matches[SqlGrammar.OrderByItem.NullPlacement];
     if (placementResult.IsMatch)
     {
         placement = buildNullPlacement(placementResult);
     }
     OrderBy orderBy = new OrderBy(expression, order, placement);
     orderByList.Add(orderBy);
 }
コード例 #28
0
 private Join buildJoinPrime(MatchResult result, Join join)
 {
     MatchResult filtered = result.Matches[SqlGrammar.JoinPrime.Filtered.Name];
     if (filtered.IsMatch)
     {
         MatchResult joinItemResult = filtered.Matches[SqlGrammar.JoinPrime.Filtered.JoinItem];
         string alias;
         IRightJoinItem joinItem = buildJoinItem(joinItemResult, out alias);
         MatchResult joinTypeResult = filtered.Matches[SqlGrammar.JoinPrime.Filtered.JoinType];
         FilteredJoin filteredJoin = buildFilteredJoin(joinTypeResult, join, joinItem, alias);
         scope.Push(filteredJoin.Sources);
         MatchResult onResult = filtered.Matches[SqlGrammar.JoinPrime.Filtered.On.Name];
         MatchResult filterListResult = onResult.Matches[SqlGrammar.JoinPrime.Filtered.On.FilterList];
         IFilter innerFilter = buildOrFilter(filterListResult);
         filteredJoin.OnFilterGroup.AddFilter(innerFilter);
         filteredJoin.OnFilterGroup.Optimize();
         MatchResult joinPrimeResult = filtered.Matches[SqlGrammar.JoinPrime.Filtered.JoinPrime];
         Join prime = buildJoinPrime(joinPrimeResult, filteredJoin);
         scope.Pop();
         return prime;
     }
     MatchResult cross = result.Matches[SqlGrammar.JoinPrime.Cross.Name];
     if (cross.IsMatch)
     {
         MatchResult joinItemResult = cross.Matches[SqlGrammar.JoinPrime.Cross.JoinItem];
         string alias;
         IRightJoinItem joinItem = buildJoinItem(joinItemResult, out alias);
         Join crossJoin = join.CrossJoin(joinItem, alias);
         scope.Push(crossJoin.Sources);
         MatchResult joinPrimeResult = cross.Matches[SqlGrammar.JoinPrime.Cross.JoinPrime];
         Join prime = buildJoinPrime(joinPrimeResult, crossJoin);
         scope.Pop();
         return prime;
     }
     MatchResult empty = result.Matches[SqlGrammar.JoinPrime.Empty];
     if (empty.IsMatch)
     {
         return join;
     }
     throw new InvalidOperationException();
 }
コード例 #29
0
 private IRightJoinItem buildJoinItem(MatchResult result, out string alias)
 {
     alias = null;
     MatchResult aliasExpression = result.Matches[SqlGrammar.JoinItem.AliasExpression.Name];
     if (aliasExpression.IsMatch)
     {
         MatchResult aliasResult = aliasExpression.Matches[SqlGrammar.JoinItem.AliasExpression.Alias];
         alias = getToken(aliasResult);
     }
     MatchResult tableResult = result.Matches[SqlGrammar.JoinItem.Table];
     if (tableResult.IsMatch)
     {
         Table table = buildTable(tableResult);
         return table;
     }
     MatchResult select = result.Matches[SqlGrammar.JoinItem.Select.Name];
     if (select.IsMatch)
     {
         MatchResult selectStatement = select.Matches[SqlGrammar.JoinItem.Select.SelectStatement];
         return buildSelectStatement(selectStatement);
     }
     MatchResult functionCall = result.Matches[SqlGrammar.JoinItem.FunctionCall];
     if (functionCall.IsMatch)
     {
         return buildFunctionCall(functionCall);
     }
     throw new InvalidOperationException();
 }
コード例 #30
0
 private void buildConditionList(MatchResult result, ConditionalCase options)
 {
     MatchResult condition = result.Matches[SqlGrammar.ConditionList.Condition];
     buildCondition(condition, options);
     MatchResult conditionListPrime = result.Matches[SqlGrammar.ConditionList.ConditionListPrime];
     buildConditionListPrime(conditionListPrime, options);
 }