Esempio n. 1
0
        public virtual SqlFragment BuildSqlForSqlFunctionExpression(SqlFunctionExpression expr)
        {
            SqlTemplate template = SqlDialect.GetSqlFunctionTemplate(expr);

            if (template != null)
            {
                var args    = expr.GetOperands();
                var sqlArgs = args.Select(a => BuildLinqExpressionSql(a)).ToArray();
                return(template.Format(sqlArgs));
            }
            return(BuildSqlForSqlFunctionExpressionNoTemplate(expr));
        }//class
Esempio n. 2
0
        public virtual SqlFragment BuildAggregateSql(AggregateExpression expr)
        {
            if (expr.AggregateType == AggregateType.Count && expr.Operands.Count == 0)
            {
                return(this.SqlDialect.SqlCountStar);
            }
            SqlTemplate template = SqlDialect.GetAggregateTemplate(expr);

            if (template != null)
            {
                var args    = expr.GetOperands();
                var sqlArgs = args.Select(a => BuildLinqExpressionSql(a)).ToArray();
                return(template.Format(sqlArgs));
            }
            Util.Throw("Unsupported Aggregate type: {0}, expr: {1} ", expr.AggregateType, expr);
            return(null);
        }
Esempio n. 3
0
        }//method

        public virtual SqlFragment BuildSqlForSqlExpression(SqlExpression expr)
        {
            switch (expr.SqlNodeType)
            {
            case SqlExpressionType.Alias:
                var aliasExpr = (AliasedExpression)expr;
                return(BuildLinqExpressionSql(aliasExpr.Expression)); //Alias will be added later

            case SqlExpressionType.SqlFunction:
                return(BuildSqlForSqlFunctionExpression((SqlFunctionExpression)expr));

            case SqlExpressionType.Column:
                var colExpr = (ColumnExpression)expr;
                return(GetColumnRefSql(colExpr, forOutput: false));

            case SqlExpressionType.SubSelect:
                var subs      = (SubSelectExpression)expr;
                var subSelect = BuildSqlForSqlExpression(subs.Select);
                return(CompositeSqlFragment.Parenthesize(subSelect));

            case SqlExpressionType.Table:
                var te = (TableExpression)expr;
                return(te.TableInfo.SqlFullName);

            case SqlExpressionType.TableFilter:
                var tfe      = (TableFilterExpression)expr;
                var argParts = BuildSqls(tfe.Columns);
                var sqlTempl = new SqlTemplate(tfe.Filter.EntityFilter.Template.StandardForm);
                var part     = sqlTempl.Format(argParts);
                return(part);

            case SqlExpressionType.ExternalValue:
                var extValue = (ExternalValueExpression)expr;
                var ph       = CreateSqlPlaceHolder(extValue);
                // it is already added to placeholders list
                return(ph);

            case SqlExpressionType.Group:
                var ge = (GroupExpression)expr;
                return(BuildLinqExpressionSql(ge.GroupedExpression));

            case SqlExpressionType.OrderBy:
                return(BuildOrderByMember((OrderByExpression)expr));

            case SqlExpressionType.Aggregate:
                return(BuildAggregateSql((AggregateExpression)expr));

            case SqlExpressionType.Select:
                var selectSql = BuildSelectSql((SelectExpression)expr);
                return(CompositeSqlFragment.Parenthesize(selectSql));


            case SqlExpressionType.DerivedTable:
                // Looks like we never come here
                //!!! investigate this
                //TODO: investigate DerivedTable SQL
                return(SqlTerms.Star);

            default:
                Util.Throw("SqlExpression->SQL not implemented, SqlNodeType: {0}", expr.SqlNodeType);
                return(null); //never happens
            }//switch
        }//method