Пример #1
0
 private void addJoinItem(SelectBuilder builder, Join join)
 {
     JoinStart start = join as JoinStart;
     if (start == null)
     {
         builder.AddJoin(join);
         return;
     }
     AliasedSource source = start.Source;
     Table table = source.Source as Table;
     if (table != null)
     {
         builder.AddTable(table, source.Alias);
         return;
     }
     ISelectBuilder select = source.Source as SelectBuilder;
     if (select != null)
     {
         builder.AddSelect(select, source.Alias);
         return;
     }
     Function functionCall = source.Source as Function;
     if (functionCall != null)
     {
         builder.AddFunction(functionCall, source.Alias);
         return;
     }
     throw new InvalidOperationException();
 }
Пример #2
0
 /// <summary>
 /// Initializes a new instance of a BinaryJoin.
 /// </summary>
 /// <param name="leftHand">The left hand item or join.</param>
 /// <param name="rightHand">The right hand item in the join.</param>
 protected BinaryJoin(Join leftHand, AliasedSource rightHand)
     : base(leftHand, rightHand)
 {
     if (leftHand == null)
     {
         throw new ArgumentNullException("leftHand");
     }
     if (rightHand == null)
     {
         throw new ArgumentNullException("rightHand");
     }
     LeftHand = leftHand;
     RightHand = rightHand;
 }
Пример #3
0
 /// <summary>
 /// Initializes a new instance of a CrossJoin.
 /// </summary>
 /// <param name="leftHand">The left hand item in the join.</param>
 /// <param name="rightHand">The right hand table in the join.</param>
 internal CrossJoin(Join leftHand, AliasedSource rightHand)
     : base(leftHand, rightHand)
 {
 }
Пример #4
0
 /// <summary>
 /// Initializes a new instance of a FilteredJoin.
 /// </summary>
 /// <param name="left">The left hand item in the join.</param>
 /// <param name="right">The right hand item in the join.</param>
 protected FilteredJoin(Join left, AliasedSource right)
     : base(left, right)
 {
     on = new FilterGroup(Conjunction.And);
 }
Пример #5
0
 /// <summary>
 /// Initializes a new instance of a RightOuterJoin.
 /// </summary>
 /// <param name="leftHand">The left hand item in the join.</param>
 /// <param name="rightHand">The right hand table in the join.</param>
 internal RightOuterJoin(Join leftHand, AliasedSource rightHand)
     : base(leftHand, rightHand)
 {
 }
Пример #6
0
 /// <summary>
 /// Initializes a new instance of a Join.
 /// </summary>
 /// <param name="other">The previous join in the sequence.</param>
 /// <param name="source">The source for the current </param>
 protected Join(Join other, AliasedSource source)
     : this(new SourceCollection(other.sources), source)
 {
 }
Пример #7
0
 private void visitJoin(Join join, Action visitor)
 {
     if (join.WrapInParentheses ?? options.WrapJoinsInParentheses)
     {
         writer.Write("(");
     }
     visitor();
     if (join.WrapInParentheses ?? options.WrapJoinsInParentheses)
     {
         writer.Write(")");
     }
 }
Пример #8
0
 /// <summary>
 /// Removes the given join from the FROM clause.
 /// </summary>
 /// <param name="join">The join to remove.</param>
 /// <returns>True if the item was found and removed; otherwise, false.</returns>
 public bool RemoveJoin(Join join)
 {
     if (join == null)
     {
         throw new ArgumentNullException("joinItem");
     }
     return _from.Remove(join);
 }
Пример #9
0
 /// <summary>
 /// Adds the given join to the FROM clause.
 /// </summary>
 /// <param name="join">The join to add.</param>
 public void AddJoin(Join join)
 {
     if (join == null)
     {
         throw new ArgumentNullException("join");
     }
     sources.AddSources(join.Sources);
     _from.Add(join);
 }
Пример #10
0
        public static void LogJoin(Join join, StringBuilder stringBuilder, int level = 0)
        {
            var indent = GetIndent(level);
            if (join != null)
            {
                stringBuilder.AppendLine(string.Format("{0} {1}", indent, join.GetType().Name));
                var binaryJoin = join as BinaryJoin;
                if (binaryJoin != null)
                {

                    if (binaryJoin.LeftHand != null)
                    {
                        stringBuilder.AppendLine(string.Format("{0} Left:", indent));
                        LogJoin(binaryJoin.LeftHand, stringBuilder, level + 1);
                    }
                    if (binaryJoin.RightHand != null)
                    {
                        stringBuilder.AppendLine(string.Format("{0} Right:", indent));
                        AliasedSource asource = binaryJoin.RightHand;
                        LogAliasedSource(asource, stringBuilder, level + 1);
                    }

                }
                var filteredJoin = join as FilteredJoin;
                if (filteredJoin != null)
                {
                    stringBuilder.AppendLine(string.Format("{0} On filters:", indent));
                    foreach (var on in filteredJoin.OnFilters)
                    {
                        // Support Equals
                        var equalTo = on as EqualToFilter;
                        if (equalTo != null)
                        {

                            var leftColumn = equalTo.LeftHand as Column;
                            var rightColumn = equalTo.RightHand as Column;
                            if (leftColumn == null || rightColumn == null)
                            {
                                throw new NotSupportedException("The ON operator used in the Join statement must have a column name on it's left and right side.");
                            }

                            stringBuilder.AppendLine(string.Format("{0}  Filter Type: {1}", indent, on.GetType().FullName));
                            stringBuilder.AppendLine(string.Format("{0}    Left Column Name: {1}", indent, leftColumn.Name));
                            if (leftColumn.Source != null)
                            {
                                stringBuilder.AppendLine(string.Format("{0}    Left Column Source", indent));
                                LogAliasedSource(leftColumn.Source, stringBuilder, level + 1);
                                //
                            }

                            stringBuilder.AppendLine(string.Format("{0}    Right Column Name: {1}", indent, rightColumn.Name));
                            if (rightColumn.Source != null)
                            {
                                stringBuilder.AppendLine(string.Format("{0}    Right Column Source", indent));
                                LogAliasedSource(rightColumn.Source, stringBuilder, level + 1);
                                //
                            }

                            return;
                        }

                    }
                }

            }
        }
Пример #11
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();
 }
Пример #12
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();
 }
Пример #13
0
 /// <summary>
 /// Initializes a new instance of a Join.
 /// </summary>
 /// <param name="other">The previous join in the sequence.</param>
 /// <param name="source">The source for the current </param>
 protected Join(Join other, AliasedSource source)
     : this(new SourceCollection(other.sources), source)
 {
 }
Пример #14
0
 /// <summary>
 /// Initializes a new instance of a FilteredJoin.
 /// </summary>
 /// <param name="left">The left hand item in the join.</param>
 /// <param name="right">The right hand item in the join.</param>
 protected FilteredJoin(Join left, AliasedSource right)
     : base(left, right)
 {
     on = new FilterGroup(Conjunction.And);
 }