Esempio n. 1
0
 public string GetSQL(Formatter formatter)
 {
     return "\n" + (_joinType == JoinType.Inner ? "INNER" : "LEFT OUTER" ) + " JOIN " + formatter.GetTableText(_table) + "\nON " + _criteria.GetSQL(formatter);
 }
Esempio n. 2
0
        internal string GetSQL(Formatter formatter, bool resetTableAliases)
        {
            ValidateQuery();

            if (resetTableAliases)
            {
                ResetTableAliases(0);
            }

            // TODO: Switch to using a StringBuilder.

            string sql = "SELECT ";

            if (_distinct)
            {
                sql += "DISTINCT ";
            }

            sql += GetColumnNames(formatter) + "\nFROM ";

            sql += formatter.GetTableText(_fromTable);

            if (_joins.Count > 0)
            {
                foreach (JoinInfo joinInfo in _joins)
                {
                    sql += joinInfo.GetSQL(formatter);
                }
            }

            if (_where != null)
            {
                sql += "\nWHERE ";

                sql += _where.GetSQL(formatter);
            }

            if (_groupBy.Count > 0)
            {
                sql += "\nGROUP BY ";

                bool first = true;

                foreach (Column column in _groupBy)
                {
                    if (!first)
                    {
                        sql += ", ";
                    }

                    sql += column.GetColumnText(formatter);

                    first = false;
                }

                if (_having != null)
                {
                    sql += "\nHAVING ";

                    sql += _having.GetSQL(formatter);
                }
            }

            if (_orderBy.Count > 0)
            {
                sql += "\nORDER BY ";

                bool first = true;

                foreach (OrderByInfo orderBy in _orderBy)
                {
                    if (!first)
                    {
                        sql += ", ";
                    }

                    if (orderBy is OrderByColumnInfo)
                    {
                        sql += ((OrderByColumnInfo)orderBy).Column.GetColumnText(formatter);
                    }
                    else
                    {
                        sql += formatter.GetResultText(((OrderByResultInfo)orderBy).Result);
                    }

                    if (orderBy.Descending)
                    {
                        sql += " DESC";
                    }

                    first = false;
                }
            }

            return sql;
        }