public string ToSelectText(ConstraintType constraintType) { using (DbTextWriter writer = new DbTextWriter()) { return(ToSelectText(writer, constraintType)); } }
private void WriteColumnPredicates(DbTextWriter writer, IEnumerable <ColumnPredicate> predicates) { int i = 0; foreach (ColumnPredicate predicate in predicates) { if (predicate.OrToPreviousGroup) { OnWriteOr(writer); } else if (i++ >= 1) { OnWriteAnd(writer); } if (predicate.IsGroup) { WriteBeginGroup(writer); for (ColumnPredicate current = predicate; current != null; current = current.NextInGroup) { WriteColumnPredicate(writer, current); } } else { WriteColumnPredicate(writer, predicate); } } }
protected virtual void OnWriteGroupBys(DbTextWriter writer) { if (groupBys == null || groupBys.Count == 0) { return; } writer.WriteGroupBy(GroupBys); }
private void WriteEndGroup(DbTextWriter writer) { if (groupCount == 0) { return; } OnWriteEndGroup(writer); }
private void WriteCountSelect(DbTextWriter textWriter) { OnWriteCount(textWriter); OnWriteFrom(textWriter); OnWriteJoin(textWriter); OnWriteWhere(textWriter); OnWriteGroupBys(textWriter); OnWriteHaving(textWriter); OnWriteOrderBys(textWriter); }
protected virtual void OnWriteHaving(DbTextWriter writer) { if (havingPredicates == null || havingPredicates.Count == 0) { return; } if (!writer.IsSelectionSet) { throw new InvalidOperationException("Select columns have not been set."); } writer.WriteHaving(); WriteColumnPredicates(writer, havingPredicates); }
protected virtual void OnWriteJoin(DbTextWriter writer) { if (!writer.IsSelectionSet) { throw new InvalidOperationException("Select columns have not been set."); } if (!JoinInWhereClause && joinPredicates != null && joinPredicates.Count > 0) { WriteJoinPredicates(writer, joinPredicates); } if (!JoinInWhereClause && localizedJoinPredicates != null && localizedJoinPredicates.Count > 0) { WriteJoinPredicates(writer, localizedJoinPredicates); } }
private void WriteJoinPredicate(DbTextWriter writer, JoinPredicate current) { writer.WritePredicate(current, GetComparisonOperator(current.Comparison, current.ToColumn)); if (current.NextInGroup == null) { WriteEndGroup(writer); } if (current.NextInGroup != null && current.OrNextPredicate) { OnWriteOr(writer); } else if (current.NextInGroup != null) { OnWriteAnd(writer); } }
public string ToSelectText(DbTextWriter textWriter, ConstraintType constraintType) { Parameters.Clear(); if (Constraint.ConstraintType == ConstraintType.Page) { return(FormatPagingSql(textWriter, Constraint)); } if (constraintType == ConstraintType.Count) { WriteCountSelect(textWriter); } else { WriteBasicSelect(textWriter); } return(textWriter.ToString()); }
protected virtual void OnWriteWhere(DbTextWriter writer) { if (!writer.IsSelectionSet) { throw new InvalidOperationException("Select columns have not been set."); } if (JoinInWhereClause && joinPredicates != null && joinPredicates.Count > 0) { writer.WriteWhere(); WriteWhereJoinPredicates(writer, joinPredicates); } if (wherePredicates != null && wherePredicates.Count > 0) { writer.WriteWhere(); WriteColumnPredicates(writer, wherePredicates); } }
private void WriteJoinPredicates(DbTextWriter writer, IEnumerable <JoinPredicate> predicates) { foreach (JoinPredicate predicate in predicates) { writer.Write(" LEFT JOIN {0} ON ", "[" + predicate.ToColumn.Table.Owner + "].[" + predicate.ToColumn.Table.Name + "] " + writer.GetTableAlias(predicate.ToColumn.Table)); if (predicate.IsGroup) { WriteBeginGroup(writer); for (JoinPredicate current = predicate; current != null; current = current.NextInGroup) { WriteJoinPredicate(writer, current); } } else { WriteJoinPredicate(writer, predicate); } } }
private void WriteColumnPredicate(DbTextWriter writer, ColumnPredicate current) { if (current.IsJoinPredicate) { WriteJoinPredicate(writer, current); return; } writer.WritePredicate(current.Column, GetComparisonOperator(current.Comparison, current.Value), AddParameter(current)); if (current.NextInGroup == null) { WriteEndGroup(writer); } if (current.NextInGroup != null && current.OrNextPredicate) { OnWriteOr(writer); } else if (current.NextInGroup != null) { OnWriteAnd(writer); } }
protected virtual void OnWriteEndGroup(DbTextWriter writer) { writer.Write(")"); groupCount--; }
private void WriteBeginGroup(DbTextWriter writer) { OnWriteBeginGroup(writer); groupCount++; }
protected virtual void OnWriteSelect(DbTextWriter writer) { writer.WriteSelect(Columns, Constraint, Distinct); }
protected virtual string FormatPagingSql(DbTextWriter textWriter, Constraint constraint) { WriteBasicSelect(textWriter); return(textWriter.ToString()); }
protected virtual void OnWriteCount(DbTextWriter writer) { writer.WriteCount(); }
protected virtual void OnWriteFrom(DbTextWriter writer) { writer.WriteFrom(Tables.Values, NeedsAlias()); writer.WriteFrom(selfJoinTables, NeedsAlias()); }
protected virtual void OnWriteBeginGroup(DbTextWriter writer) { writer.Write("("); }
protected virtual void OnWriteOrderBys(DbTextWriter writer) { writer.WriteOrderBy(OrderBys, Constraint); }
public string ToSelectText(DbTextWriter textWriter) { return(ToSelectText(textWriter, ConstraintType.None)); }
protected virtual void OnWriteOr(DbTextWriter writer) { writer.Write(" OR "); }
protected virtual void OnWriteAnd(DbTextWriter writer) { writer.Write(" AND "); }
public string ToSelectText() { using (DbTextWriter writer = new DbTextWriter()) return(ToSelectText(writer, ConstraintType.None)); }