Exemple #1
0
        /// Adds a LEFT/RIGHT JOIN part of the SQL query as FROM parts, while replacing corresponding FROM parts.
        ///
        /// If a subquery parts aggregator is open, redirects the call to it instead.
        public void AddOuterJoinPart(string outerMember, string innerMember)
        {
            if (_visitingSubQueryExpression)
            {
                _subQueryExpressionPartsAggregator.AddOuterJoinPart(outerMember, innerMember);
            }
            else
            {
                var outerSource   = outerMember.Split('.')[0];
                var innerSource   = innerMember.Split('.')[0];
                var groupJoinPart =
                    $"{outerSource} LEFT OUTER JOIN {innerSource} ON ({outerMember} = {innerMember})";

                // We're using the fact that the left source table was already added in AddFromPart
                var index = FromParts.IndexOf(outerSource);
                FromParts[index] = groupJoinPart;

                var groupingPart =
                    $"(SELECT COUNT(*) FROM {innerSource} AS \"temp_{innerSource.Substring(1)} " +
                    $"WHERE \"temp_{innerMember.Substring(1)} = {outerMember}) AS";
                if (SelectPart.Contains(groupingPart))
                {
                    OrderByParts.Add(outerMember);
                    OrderByParts.Add(innerMember);
                }
            }
        }
Exemple #2
0
        /// Adds an INNER JOIN part of the SQL query as FROM parts, while replacing corresponding FROM parts.
        ///
        /// If a subquery parts aggregator is open, redirects the call to it instead.
        public void AddInnerJoinPart(string leftMember, string rightMember)
        {
            if (_visitingSubQueryExpression)
            {
                _subQueryExpressionPartsAggregator.AddInnerJoinPart(leftMember, rightMember);
            }
            else
            {
                var leftSource  = leftMember.Split('.')[0];
                var rightSource = rightMember.Split('.')[0];
                var joinPart    =
                    $"{leftSource} INNER JOIN {rightSource} ON ({leftMember} = {rightMember})";

                // We're using the fact that the left source table was already added in AddFromPart
                var index = FromParts.IndexOf(leftSource);
                FromParts[index] = joinPart;
            }
        }