public string Compile(IColumnSelector value, SelectQuery query, IQueryParameterManager parameters) { var select = value as GroupByColumnSelector; if (query.GroupByColumns.Count == 1) { var column = new ColumnSelector(query.GroupByColumns[0].TableAlias, query.GroupByColumns[0].Field.Name, select.Alias, Aggregate.None); var result = new ColumnSelectorCompiler().Compile(column, query, parameters); return(result); } // cannot find the group key column return(string.Format("null AS {1}")); }
public string Compile(IColumnSelector value, SelectQuery query, IQueryParameterManager parameters) { var select = value as TotalColumnSelector; var count = "( COUNT(1) OVER () )"; if (select.OnlyOnRowIndex == null) { return(string.Format("{0} AS {1}", count, select.Alias)); } var rowNumber = new RowNumberColumnSelectorCompiler().Compile(new RowNumberColumnSelector(null), query, parameters); return(string.Format("( CASE WHEN {0} = {1} THEN {2} ELSE null END ) AS {3}", rowNumber, select.OnlyOnRowIndex, count, select.Alias)); }
private string SingleWord(ColumnLikeWhereFilter where, IQueryParameterManager parameters, bool exclude = false) { const string wc = "'%'"; var leftWildCard = (where.LikeMode == LikeMode.WildcardLeft || where.LikeMode == LikeMode.Wildcard); var rightWildCard = (where.LikeMode == LikeMode.WildcardRight || where.LikeMode == LikeMode.Wildcard); //var textValue = ToStringHelper.ValueString(, DbType.String); var parameterisedText = parameters.Parameterize(where.Text, DbType.String, where.LeftColumn.Field.Name); return(string.Format("{0} {1} {2}{3}{4}", where.LeftColumn.FullName, exclude ? "NOT LIKE" : "LIKE", leftWildCard ? wc + " + " : null, parameterisedText, rightWildCard ? " + " + wc : null )); }
public virtual string CompileFrom(SelectQuery selectQuery, IQueryParameterManager parameters) { var result = "FROM "; result += string.Format("\n\t{0} AS {1} ", selectQuery.FromTable.TableName, selectQuery.FromTable.Alias); var joinCompiler = new TableJoinCompiler(); foreach (var join in selectQuery.TableJoins) { result += string.Format("\n\t {0}", joinCompiler.Compile(join, selectQuery, parameters)); } return(result); }
public virtual string CompileGroupBy(SelectQuery selectQuery, IQueryParameterManager parameters) { if (!selectQuery.GroupByColumns.Any()) { return(null); } var result = "GROUP BY "; var groupCompiler = new GroupByColumCollectionCompiler(); foreach (var column in selectQuery.GroupByColumns) { result += string.Format("\n\t {0} ,", groupCompiler.Compile(column, selectQuery, parameters)); } result = result.TrimEnd(','); return(result); }
public string Compile(IWhereFilter filter, SelectQuery query, IQueryParameterManager parameters) { var where = filter as ColumnContainsWhereFilter; switch (where.ContainsMode) { case ContainsMode.AllWords: case ContainsMode.AllWordsWildcardRight: case ContainsMode.AnyWord: case ContainsMode.AnyWordWildcardRight: return(MultiWord(where, parameters)); case ContainsMode.Default: case ContainsMode.WildcardRight: return(SingleWord(where, parameters)); case ContainsMode.FreeText: return(FreeText(where, parameters)); } throw new NotImplementedException(); }
public string Compile(IWhereFilter filter, SelectQuery query, IQueryParameterManager parameters) { var where = filter as ColumnValueWhereFilter; var valueString = parameters.Parameterize(where.RightValue.Value, where.RightValue.Type, where.ParameterAlias ?? where.LeftColumn.Field.Name); if (where.IsNullValue != null) { string isnullQuotes = where.RightValue.Type.IsStringType() ? "'" : null; return(string.Format("ISNULL({0},{1}) {2} {3}", where.LeftColumn.FullName, isnullQuotes + where.IsNullValue + isnullQuotes, where.Operator.ToSqlString(), valueString )); } return(string.Format("{0} {1} {2}", where.LeftColumn.FullName, where.Operator.ToSqlString(), valueString )); }
public string Compile(IColumnSelector value, SelectQuery query, IQueryParameterManager parameters) { var select = value as SqlColumnSelector; return(select.Sql); }
public string Compile(IHavingFilter filter, SelectQuery query, IQueryParameterManager parameters) { var having = filter as SqlHavingFilter; return(having.Sql); }
public string Compile(IWhereFilter filter, SelectQuery query, IQueryParameterManager parameters) { var where = filter as SqlWhereFilter; return(where.Sql); }
public string Compile(IColumnSelector value, SelectQuery query, IQueryParameterManager parameters) { return("*"); }
public string Compile(IColumnSelector value, SelectQuery query, IQueryParameterManager parameters) { var select = value as CountColumnSelector; return(string.Format("COUNT({1}) AS {0}", select.Alias, select.FieldName)); }