public override void WriteSql(StringBuilder sql)
 {
     sql.Append(IsNegated ? "NOT " : "");
     sql.Append("EXISTS(");
     Argument.WriteSql(sql);
     sql.Append(")");
 }
        public override void WriteSql(StringBuilder sql)
        {
            string name = Quoted ? QuoteIdentifier(Name) : Name;

            sql.AppendFormat("{0}({1}", name, Distinct ? "DISTINCT " : "");
            Argument.WriteSql(sql);
            sql.Append(")");
        }
 public override void WriteSql(StringBuilder sql)
 {
     Argument.WriteSql(sql);
     if (IsNegated)
     {
         sql.Append(" NOT ");
     }
     sql.Append(" LIKE ");
     Pattern.WriteSql(sql);
 }
        public override void WriteSql(StringBuilder sql)
        {
            if (IsWrapped)
            {
                sql.Append("(");
            }
            sql.Append("SELECT");
            if (IsDistinct)
            {
                sql.Append(" DISTINCT ");
            }

            WriteList(Columns, sql);

            if (From != null)
            {
                sql.Append("\r\nFROM ");
                From.WriteSql(sql);
            }
            if (Where != null)
            {
                sql.Append("\r\n WHERE ");
                Where.WriteSql(sql);
            }
            if (GroupBy != null)
            {
                sql.Append("\r\n GROUP BY ");
                WriteList(GroupBy, sql);
            }
            WriteOrderBy(sql);
            if (Limit != null || Skip != null)
            {
                sql.Append(" LIMIT ");
                if (Skip != null)
                {
                    sql.AppendFormat("{0},", Skip);
                }
                if (Limit == null)
                {
                    sql.Append("18446744073709551615");
                }
                else
                {
                    sql.AppendFormat("{0}", Limit);
                }
            }
            if (IsWrapped)
            {
                sql.Append(")");
                if (Name != null)
                {
                    sql.AppendFormat(" AS {0}", QuoteIdentifier(Name));
                }
            }
        }
 public override void WriteInnerSql(StringBuilder sql)
 {
     Left.WriteSql(sql);
     sql.AppendFormat(" {0} ", JoinType);
     Right.WriteSql(sql);
     if (Condition != null)
     {
         sql.Append(" ON ");
         Condition.WriteSql(sql);
     }
 }
        public override void WriteSql(StringBuilder sql)
        {
            sql.Append("CASE");

            // If CASE clause contains an IS NULL value in WHEN statement and has an Else statement, negate WHEN and invert the CASE,
            // otherwise THEN statement will not be considered and the value will be set to NULL.
            if (When.Count == 1 && When[0] is IsNullFragment && !(((NegatableFragment)When[0]).IsNegated) && Else != null)
            {
                sql.Append(" WHEN (");
                ((NegatableFragment)When[0]).IsNegated = true;
                When[0].WriteSql(sql);
                sql.Append(") THEN (");
                Else.WriteSql(sql);
                sql.Append(") ");
                sql.Append(" ELSE (");
                Then[0].WriteSql(sql);
                sql.Append(") ");
            }
            else
            {
                for (int i = 0; i < When.Count; i++)
                {
                    sql.Append(" WHEN (");
                    When[i].WriteSql(sql);
                    sql.Append(") THEN (");
                    Then[i].WriteSql(sql);
                    sql.Append(") ");
                }
                if (Else != null)
                {
                    sql.Append(" ELSE (");
                    Else.WriteSql(sql);
                    sql.Append(") ");
                }
            }

            sql.Append("END");
        }
 public override void WriteSql(StringBuilder sql)
 {
     Argument.WriteSql(sql);
     if (IsNegated)
     {
         sql.Append(" NOT ");
     }
     sql.Append(" IN ( ");
     foreach (LiteralFragment lit in InList)
     {
         sql.Append(lit).Append(",");
     }
     sql.Length = sql.Length - 1;
     sql.Append(" )");
 }
        public override void WriteSql(StringBuilder sql)
        {
            if (IsNegated && Operator != "=")
            {
                sql.Append("NOT (");
            }

            // do left arg
            if (WrapLeft)
            {
                sql.Append("(");
            }
            Left.WriteSql(sql);
            if (WrapLeft)
            {
                sql.Append(")");
            }

            if (IsNegated && Operator == "=")
            {
                sql.Append(" != ");
            }
            else
            {
                sql.AppendFormat(" {0} ", Operator);
            }

            // now right arg
            if (WrapRight)
            {
                sql.Append("(");
            }
            Right.WriteSql(sql);
            if (WrapRight)
            {
                sql.Append(")");
            }
            if (IsNegated && Operator != "=")
            {
                sql.Append(")");
            }
        }
 public override void WriteSql(StringBuilder sql)
 {
     Argument.WriteSql(sql);
     sql.AppendFormat(" IS {0} NULL", IsNegated ? "NOT" : "");
 }