コード例 #1
0
 /// <summary>
 /// Returns an operation between two SELECT clauses (UNION, UNION ALL, etc.)
 /// </summary>
 /// <param name="selectOperator"></param>
 /// <param name="selectA"></param>
 /// <param name="selectB"></param>
 /// <returns></returns>
 public virtual SqlStatement GetLiteral(SelectOperatorType selectOperator, SqlStatement selectA, SqlStatement selectB)
 {
     switch (selectOperator)
     {
     case SelectOperatorType.Union:
         return GetLiteralUnion(selectA, selectB);
     case SelectOperatorType.UnionAll:
         return GetLiteralUnionAll(selectA, selectB);
     case SelectOperatorType.Intersection:
         return GetLiteralIntersect(selectA, selectB);
     case SelectOperatorType.Exception:
         return GetLiteralExcept(selectA, selectB);
     default:
         throw new ArgumentOutOfRangeException(selectOperator.ToString());
     }
 }
コード例 #2
0
        protected virtual Expression AnalyzeSelectOperation(SelectOperatorType operatorType, IList<Expression> parameters, TranslationContext context)
        {
            // a special case: if we have several SELECT expressions linked together,
            // we maximize the load to the database, since the result must use the same parameters
            // types and count.
            //context.QueryContext.MaximumDatabaseLoad = true; // all select expression goes to SQL tier
            var subQuery = parameters[1];
            if (subQuery != null) {
              // Handle second select first
              TranslationContext newContext = context.NewSisterSelect();
              Expression tableExpression = AnalyzeSubQuery(subQuery, newContext);
              BuildSelect(tableExpression, newContext);

              // add the second select select to the chain
              if (newContext.CurrentSelect.NextSelectExpression != null) {
                var typedTable = tableExpression as TableExpression;
                var dbTable = typedTable == null ? null : typedTable.TableInfo;
                var operand0 = new SubSelectExpression(newContext.CurrentSelect, tableExpression.Type, "source", dbTable);
                newContext.NewParentSelect();
                newContext.CurrentSelect.Tables.Add(operand0);
              }
              SelectExpression selectToModify = context.CurrentSelect;
              while (selectToModify.NextSelectExpression != null)
                selectToModify = selectToModify.NextSelectExpression;

              selectToModify.NextSelectExpression = newContext.CurrentSelect;
              selectToModify.NextSelectExpressionOperator = operatorType;

              Expression firstSelection = Analyze(parameters[0], context);
              BuildSelect(firstSelection, context);

              return firstSelection;
            }
            return Analyze(parameters[0], context);
        }