Ejemplo n.º 1
0
 private void visitSelect(SelectBuilder item)
 {
     bool needsParentheses = level > 0;
     if (needsParentheses)
     {
         writer.Write("(");
     }
     writer.Write("SELECT ");
     if (item.Distinct != DistinctQualifier.Default)
     {
         DistinctQualifierConverter converter = new DistinctQualifierConverter();
         writer.Write(converter.ToString(item.Distinct));
         writer.Write(" ");
     }
     if (item.Top != null)
     {
         IVisitableBuilder top = item.Top;
         top.Accept(forSubCommand().forValueContext(ValueReferenceType.Reference));
         writer.Write(" ");
     }
     forValueContext(ValueReferenceType.Declaration).join(", ", item.Projection);
     if (item.From.Any())
     {
         writer.Write(" FROM ");
         forSourceContext(SourceReferenceType.Declaration).join(", ", item.From);
     }
     if (item.WhereFilterGroup.HasFilters)
     {
         writer.Write(" WHERE ");
         IFilter where = item.WhereFilterGroup;
         where.Accept(forSubCommand().forValueContext(ValueReferenceType.Reference));
     }
     if (item.GroupBy.Any())
     {
         writer.Write(" GROUP BY ");
         forValueContext(ValueReferenceType.Reference).join(", ", item.GroupBy);
     }
     if (item.HavingFilterGroup.HasFilters)
     {
         writer.Write(" HAVING ");
         IFilter having = item.HavingFilterGroup;
         having.Accept(forSubCommand().forValueContext(ValueReferenceType.Reference));
     }
     if (item.OrderBy.Any())
     {
         writer.Write(" ORDER BY ");
         forValueContext(ValueReferenceType.Alias).join(", ", item.OrderBy);
     }
     if (needsParentheses)
     {
         writer.Write(")");
     }
 }
Ejemplo n.º 2
0
 private void visitSelectCombiner(SelectCombiner combiner, string combinerToken)
 {
     bool needsParenthesis = level > 0;
     if (needsParenthesis)
     {
         writer.Write("(");
     }
     combiner.LeftHand.Accept(this);
     writer.Write(" ");
     writer.Write(combinerToken);
     writer.Write(" ");
     if (combiner.Distinct != DistinctQualifier.Default)
     {
         DistinctQualifierConverter converter = new DistinctQualifierConverter();
         writer.Write(converter.ToString(combiner.Distinct));
         writer.Write(" ");
     }
     combiner.RightHand.Accept(this);
     if (combiner.OrderBy.Any())
     {
         writer.Write(" ORDER BY ");
         join(", ", combiner.OrderBy);
     }
     if (needsParenthesis)
     {
         writer.Write(")");
     }
 }
Ejemplo n.º 3
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();
 }