private string RenderSelect(SelectQuery query, int limitRows) { query.Validate(); StringBuilder builder = new StringBuilder(); this.Select(builder, query.Distinct); this.SelectColumns(builder, query.Columns); this.FromClause(builder, query.FromClause, query.TableSpace); WhereClause group = new WhereClause(WhereClauseRelationship.And); group.SubClauses.Add(query.WherePhrase); if (limitRows > -1) { group.Terms.Add(WhereTerm.CreateCompare(SqlExpression.PseudoField("rownum"), SqlExpression.Number(limitRows), CompareOperator.LessOrEqual)); } this.Where(builder, group); this.WhereClause(builder, group); this.GroupBy(builder, query.GroupByTerms); if (query.GroupByWithCube) { builder.Append(" cube ("); } else if (query.GroupByWithRollup) { builder.Append(" rollup ("); } this.GroupByTerms(builder, query.GroupByTerms); if (query.GroupByWithCube || query.GroupByWithRollup) { builder.Append(" )"); } this.Having(builder, query.HavingPhrase); this.WhereClause(builder, query.HavingPhrase); this.OrderBy(builder, query.OrderByTerms); this.OrderByTerms(builder, query.OrderByTerms); return builder.ToString(); }
private string RenderSelect(SelectQuery query, bool forRowCount, int offset, int limitRows) { query.Validate(); StringBuilder builder = new StringBuilder(); this.Select(builder, query.Distinct); if (forRowCount) { this.SelectColumn(builder, new SelectColumn("*", null, "cnt", SqlAggregationFunction.Count)); } else { this.SelectColumns(builder, query.Columns); } this.FromClause(builder, query.FromClause, query.TableSpace); this.Where(builder, query.WherePhrase); this.WhereClause(builder, query.WherePhrase); this.GroupBy(builder, query.GroupByTerms); this.GroupByTerms(builder, query.GroupByTerms); if (query.GroupByWithCube) { throw new InvalidQueryException("MySql does not support WITH CUBE modifier."); } if (query.GroupByWithRollup) { builder.Append(" with rollup"); } this.Having(builder, query.HavingPhrase); this.WhereClause(builder, query.HavingPhrase); this.OrderBy(builder, query.OrderByTerms); this.OrderByTerms(builder, query.OrderByTerms); if (limitRows > -1) { builder.AppendFormat(" limit {0}, {1}", offset, limitRows); } return builder.ToString(); }