public string Build(SQLPartHelper helper) { helper.Indent(); var selectString = ""; foreach (var item in _what) { if (selectString.Length != 0) { selectString += _separator; if (NewLine) { selectString += helper.NewLine; } } string x; if (item is object[]) { x = helper.Translate(new CommaSeparated((object[])item, _separator, _addParenthesis) { NewLine = NewLine }); } else if (item is EasySql.SelectItems) { x = helper.Translate(new CommaSeparated((object[])((EasySql.SelectItems)item)._items.ToArray(), _separator, _addParenthesis) { NewLine = NewLine }); } else if (item is EasySql.SelectItem && ((EasySql.SelectItem)item)._item is EasySql.SelectItem[]) { x = helper.Translate(new CommaSeparated((object[])((EasySql.SelectItem[])((EasySql.SelectItem)item)._item), _separator, _addParenthesis) { NewLine = NewLine }); } else { x = helper.Translate(item); } if (_addParenthesis) { x = "(" + x + ")"; } selectString += x; } helper.UnIndent(); return(selectString); }
internal static string BuildOrderBy(SQLPartHelper helper, IEnumerable <OrderByItem> _orderBy) { var ob = ""; foreach (var item in _orderBy) { if (item._item is SortDirection) { if (((SortDirection)item._item) == SortDirection.Descending) { ob += " desc"; } continue; } if (ob.Length > 0) { ob += ", " + helper.NewLine; } ob += helper.Translate(item); } return(helper.NewLine + "Order by " + ob); }
private string InternalBuild(SQLPartHelper helper) { if (_from.Count == 0) { var entitiesDone = new HashSet <Entity>(); foreach (var item in _select) { var c = item._item as ColumnBase; if (c != null) { if (!entitiesDone.Contains(c.Entity)) { _from.Add(c.Entity); entitiesDone.Add(c.Entity); } } } if (_from.Count == 0) { throw new InvalidOperationException("Couldn't figure out the from"); } } foreach (var item in _from) { item.RegisterEntity(helper); } if (_joins != null) { foreach (var item in _joins) { helper.RegisterEntities(item.To); } } var tempFrom = new List <object>(); foreach (var item in _from) { var z = item._what as SqlStatementKeywordBase; if (z != null) { tempFrom.Add(new SqlPart(z, " ", helper.generateAlias())); } else { tempFrom.Add(item._what); } } var theFrom = helper.Translate(new CommaSeparated(tempFrom) { NewLine = true }); helper.Indent(); if (_joins != null) { foreach (var j in _joins) { theFrom += helper.NewLine + (j.joinType) + " join " + helper.Translate(j.To) + " on " + helper.Translate(j.On); } } helper.UnIndent(); string theWhere = helper.Translate(And(_where.ToArray())); if (theWhere != "") { theWhere = helper.NewLine + " Where " + theWhere; } var result = "Select " + helper.Translate(new CommaSeparated(_select) { NewLine = true }) + helper.NewLine + " From " + theFrom + theWhere; if (_groupBy != null && _groupBy.Count > 0) { result += helper.NewLine + "Group by " + helper.Translate(new CommaSeparated(_groupBy) { NewLine = true }); } if (_having.Count > 0) { result += helper.NewLine + "Having " + helper.Translate(And(_having.ToArray())); } if (_orderBy != null && _orderBy.Count > 0) { result += BuildOrderBy(helper, _orderBy);; } return(result); }
public string Build(SQLPartHelper helper) { return(helper.Translate(_item)); }