internal override SqlSelect VisitSelect(SqlSelect select)
        {
            SqlSource            from = this.VisitSource(@select.From);
            List <SqlExpression> gex  = null;

            if (@select.GroupBy.Count > 0)
            {
                gex = new List <SqlExpression>(@select.GroupBy.Count);
                foreach (SqlExpression sqlExpr in @select.GroupBy)
                {
                    gex.Add((SqlExpression)this.Visit(sqlExpr));
                }
            }
            SqlExpression             having = (SqlExpression)this.Visit(@select.Having);
            List <SqlOrderExpression> lex    = null;

            if (@select.OrderBy.Count > 0)
            {
                lex = new List <SqlOrderExpression>(@select.OrderBy.Count);
                foreach (SqlOrderExpression sox in @select.OrderBy)
                {
                    SqlOrderExpression nsox = new SqlOrderExpression(sox.OrderType, (SqlExpression)this.Visit(sox.Expression));
                    lex.Add(nsox);
                }
            }
            SqlExpression top = (SqlExpression)this.Visit(@select.Top);

            SqlExpression where = (SqlExpression)this.Visit(@select.Where);
            SqlRow        row       = (SqlRow)this.Visit(@select.Row);
            SqlExpression selection = this.VisitExpression(@select.Selection);

            SqlSelect n = new SqlSelect(selection, @from, @select.SourceExpression);

            if (gex != null)
            {
                n.GroupBy.AddRange(gex);
            }
            n.Having = having;
            if (lex != null)
            {
                n.OrderBy.AddRange(lex);
            }
            n.OrderingType = @select.OrderingType;
            n.Row          = row;
            n.Top          = top;
            n.IsDistinct   = @select.IsDistinct;
            n.IsPercent    = @select.IsPercent;
            n.Where        = @where;
            n.DoNotOutput  = @select.DoNotOutput;
            return(n);
        }
Exemple #2
0
 internal override SqlSelect VisitSelect(SqlSelect ss)
 {
     if (!ss.DoNotOutput)
     {
         string str = null;
         if (ss.From != null)
         {
             StringBuilder tmp = this.sb;
             this.sb = new StringBuilder();
             if (IsSimpleCrossJoinList(ss.From))
             {
                 VisitCrossJoinList(ss.From);
             }
             else
             {
                 Visit(ss.From);
             }
             str     = this.sb.ToString();
             this.sb = tmp;
         }
         else
         {
             str = "RDB$DATABASE";
         }
         this.sb.Append("SELECT ");
         if (ss.IsDistinct)
         {
             sb.Append("DISTINCT ");
         }
         if (ss.Top != null)
         {
             if (ss.Top is SqlFunctionCall == false)
             {
                 sb.Append("FIRST ");
             }
             Visit(ss.Top);
             sb.Append(" ");
         }
         if (ss.Row.Columns.Count > 0)
         {
             this.VisitRow(ss.Row);
         }
         else if (this.isDebugMode)
         {
             this.Visit(ss.Selection);
         }
         else
         {
             //this.sb.Append("NULL AS [EMPTY]");
             sb.Append("NULL AS ");
             sb.Append(SqlIdentifier.QuoteCompoundIdentifier("EMPTY"));
         }
         if (str != null)
         {
             this.NewLine();
             this.sb.Append("FROM ");
             this.sb.Append(str);
         }
         if (ss.Where != null)
         {
             this.NewLine();
             this.sb.Append("WHERE ");
             this.Visit(ss.Where);
         }
         if (ss.GroupBy.Count > 0)
         {
             this.NewLine();
             this.sb.Append("GROUP BY ");
             int num   = 0;
             int count = ss.GroupBy.Count;
             while (num < count)
             {
                 SqlExpression node = ss.GroupBy[num];
                 if (num > 0)
                 {
                     this.sb.Append(", ");
                 }
                 this.Visit(node);
                 num++;
             }
             if (ss.Having != null)
             {
                 this.NewLine();
                 this.sb.Append("HAVING ");
                 this.Visit(ss.Having);
             }
         }
         if ((ss.OrderBy.Count > 0) && (ss.OrderingType != SqlOrderingType.Never))
         {
             this.NewLine();
             this.sb.Append("ORDER BY ");
             int num3 = 0;
             int num4 = ss.OrderBy.Count;
             while (num3 < num4)
             {
                 SqlOrderExpression expression2 = ss.OrderBy[num3];
                 if (num3 > 0)
                 {
                     this.sb.Append(", ");
                 }
                 this.Visit(expression2.Expression);
                 if (expression2.OrderType == SqlOrderType.Descending)
                 {
                     this.sb.Append(" DESC");
                 }
                 num3++;
             }
         }
     }
     return(ss);
 }
            internal override SqlSelect VisitSelect(SqlSelect select) {
                SqlSource from = this.VisitSource(select.From);
                List<SqlExpression> gex = null;
                if (select.GroupBy.Count > 0) {
                    gex = new List<SqlExpression>(select.GroupBy.Count);
                    foreach (SqlExpression sqlExpr in select.GroupBy) {
                        gex.Add((SqlExpression)this.Visit(sqlExpr));
                    }
                }
                SqlExpression having = (SqlExpression)this.Visit(select.Having);
                List<SqlOrderExpression> lex = null;
                if (select.OrderBy.Count > 0) {
                    lex = new List<SqlOrderExpression>(select.OrderBy.Count);
                    foreach (SqlOrderExpression sox in select.OrderBy) {
                        SqlOrderExpression nsox = new SqlOrderExpression(sox.OrderType, (SqlExpression)this.Visit(sox.Expression));
                        lex.Add(nsox);
                    }
                }
                SqlExpression top = (SqlExpression)this.Visit(select.Top);
                SqlExpression where = (SqlExpression)this.Visit(select.Where);
                SqlRow row = (SqlRow)this.Visit(select.Row);
                SqlExpression selection = this.VisitExpression(select.Selection);

                SqlSelect n = new SqlSelect(selection, from, select.SourceExpression);
                if (gex != null)
                    n.GroupBy.AddRange(gex);
                n.Having = having;
                if (lex != null)
                    n.OrderBy.AddRange(lex);
                n.OrderingType = select.OrderingType;
                n.Row = row;
                n.Top = top;
                n.IsDistinct = select.IsDistinct;
                n.IsPercent = select.IsPercent;
                n.Where = where;
                n.DoNotOutput = select.DoNotOutput;
                return n;
            }
Exemple #4
0
            //将Select.Top等价于limit,将其后置。
            internal override SqlSelect VisitSelect(SqlSelect ss)
            {
                if (!ss.DoNotOutput)
                {
                    string str = null;
                    if (ss.From != null)
                    {
                        StringBuilder oldsb = this.sb;
                        this.sb = new StringBuilder();
                        if (this.IsSimpleCrossJoinList(ss.From))
                        {
                            this.VisitCrossJoinList(ss.From);
                        }
                        else
                        {
                            this.Visit(ss.From);
                        }
                        str     = this.sb.ToString();
                        this.sb = oldsb;
                    }
                    this.sb.Append("SELECT ");
                    if (ss.IsDistinct)
                    {
                        this.sb.Append("DISTINCT ");
                    }

                    if (ss.Row.Columns.Count > 0)
                    {
                        this.VisitRow(ss.Row);
                    }
                    else if (this.isDebugMode)
                    {
                        this.Visit(ss.Selection);
                    }
                    else
                    {
                        //MySQL不允许[EMPTY],改为EMPTY
                        this.sb.Append("NULL AS EMPTY");
                    }
                    if (str != null)
                    {
                        this.NewLine();
                        this.sb.Append("FROM ");
                        this.sb.Append(str);
                    }
                    if (ss.Where != null)
                    {
                        this.NewLine();
                        this.sb.Append("WHERE ");
                        this.Visit(ss.Where);
                    }
                    if (ss.GroupBy.Count > 0)
                    {
                        this.NewLine();
                        this.sb.Append("GROUP BY ");
                        int num   = 0;
                        int count = ss.GroupBy.Count;
                        while (num < count)
                        {
                            SqlExpression node = ss.GroupBy[num];
                            if (num > 0)
                            {
                                this.sb.Append(", ");
                            }
                            this.Visit(node);
                            num++;
                        }
                        if (ss.Having != null)
                        {
                            this.NewLine();
                            this.sb.Append("HAVING ");
                            this.Visit(ss.Having);
                        }
                    }
                    if ((ss.OrderBy.Count > 0) && (ss.OrderingType != SqlOrderingType.Never))
                    {
                        this.NewLine();
                        this.sb.Append("ORDER BY ");
                        int num3 = 0;
                        int num4 = ss.OrderBy.Count;
                        while (num3 < num4)
                        {
                            SqlOrderExpression expression2 = ss.OrderBy[num3];
                            if (num3 > 0)
                            {
                                this.sb.Append(", ");
                            }
                            this.Visit(expression2.Expression);
                            if (expression2.OrderType == SqlOrderType.Descending)
                            {
                                this.sb.Append(" DESC");
                            }
                            num3++;
                        }
                    }
                    //Select.Top后置!
                    if (ss.Top != null)
                    {
                        this.NewLine();
                        this.Visit(ss.Top);
                        this.sb.Append(" ");
                    }
                }
                return(ss);
            }