Example #1
0
 public string ToSelectText(ConstraintType constraintType)
 {
     using (DbTextWriter writer = new DbTextWriter())
     {
         return(ToSelectText(writer, constraintType));
     }
 }
Example #2
0
        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);
                }
            }
        }
Example #3
0
        protected virtual void OnWriteGroupBys(DbTextWriter writer)
        {
            if (groupBys == null || groupBys.Count == 0)
            {
                return;
            }

            writer.WriteGroupBy(GroupBys);
        }
Example #4
0
        private void WriteEndGroup(DbTextWriter writer)
        {
            if (groupCount == 0)
            {
                return;
            }

            OnWriteEndGroup(writer);
        }
Example #5
0
 private void WriteCountSelect(DbTextWriter textWriter)
 {
     OnWriteCount(textWriter);
     OnWriteFrom(textWriter);
     OnWriteJoin(textWriter);
     OnWriteWhere(textWriter);
     OnWriteGroupBys(textWriter);
     OnWriteHaving(textWriter);
     OnWriteOrderBys(textWriter);
 }
Example #6
0
        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);
        }
Example #7
0
        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);
            }
        }
Example #8
0
        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);
            }
        }
Example #9
0
        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());
        }
Example #10
0
        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);
            }
        }
Example #11
0
        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);
                }
            }
        }
Example #12
0
        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);
            }
        }
Example #13
0
 protected virtual void OnWriteEndGroup(DbTextWriter writer)
 {
     writer.Write(")");
     groupCount--;
 }
Example #14
0
 private void WriteBeginGroup(DbTextWriter writer)
 {
     OnWriteBeginGroup(writer);
     groupCount++;
 }
Example #15
0
 protected virtual void OnWriteSelect(DbTextWriter writer)
 {
     writer.WriteSelect(Columns, Constraint, Distinct);
 }
Example #16
0
 protected virtual string FormatPagingSql(DbTextWriter textWriter, Constraint constraint)
 {
     WriteBasicSelect(textWriter);
     return(textWriter.ToString());
 }
Example #17
0
 protected virtual void OnWriteCount(DbTextWriter writer)
 {
     writer.WriteCount();
 }
Example #18
0
 protected virtual void OnWriteFrom(DbTextWriter writer)
 {
     writer.WriteFrom(Tables.Values, NeedsAlias());
     writer.WriteFrom(selfJoinTables, NeedsAlias());
 }
Example #19
0
 protected virtual void OnWriteBeginGroup(DbTextWriter writer)
 {
     writer.Write("(");
 }
Example #20
0
 protected virtual void OnWriteOrderBys(DbTextWriter writer)
 {
     writer.WriteOrderBy(OrderBys, Constraint);
 }
Example #21
0
 public string ToSelectText(DbTextWriter textWriter)
 {
     return(ToSelectText(textWriter, ConstraintType.None));
 }
Example #22
0
 protected virtual void OnWriteOr(DbTextWriter writer)
 {
     writer.Write(" OR ");
 }
Example #23
0
 protected virtual void OnWriteAnd(DbTextWriter writer)
 {
     writer.Write(" AND ");
 }
Example #24
0
 public string ToSelectText()
 {
     using (DbTextWriter writer = new DbTextWriter())
         return(ToSelectText(writer, ConstraintType.None));
 }