protected override ColumnAssignment VisitColumnAssignment(ColumnAssignment ca)
        {
            ca = base.VisitColumnAssignment(ca);
            Expression           expression = ca.Expression;
            NamedValueExpression nv         = expression as NamedValueExpression;

            if (nv != null)
            {
                expression = new NamedValueExpression(nv.Name, ca.Column.QueryType, nv.Value);
            }
            return(this.UpdateColumnAssignment(ca, ca.Column, expression));
        }
        protected override Expression VisitMemberAccess(MemberExpression m)
        {
            m = (MemberExpression)base.VisitMemberAccess(m);
            NamedValueExpression nv = m.Expression as NamedValueExpression;

            if (nv != null)
            {
                Expression x = Expression.MakeMemberAccess(nv.Value, m.Member);
                return(GetNamedValue(x));
            }
            return(m);
        }
        private Expression GetNamedValue(Expression e)
        {
            NamedValueExpression nv;
            HashedExpression     he = new HashedExpression(e);

            if (!this.pmap.TryGetValue(he, out nv))
            {
                string name = "p" + (iParam++);
                nv = new NamedValueExpression(name, this.language.TypeSystem.GetColumnType(e.Type), e);
                this.pmap.Add(he, nv);
            }
            return(nv);
        }
Esempio n. 4
0
 protected override Expression VisitColumn(ColumnExpression column)
 {
     if (column.Alias == this.outerAlias)
     {
         NamedValueExpression nv;
         if (!this.map.TryGetValue(column, out nv))
         {
             nv = new NamedValueExpression("n" + (iParam++), column.QueryType, column);
             this.map.Add(column, nv);
         }
         return(nv);
     }
     return(column);
 }
 protected override Expression VisitConstant(ConstantExpression c)
 {
     if (c.Value != null && !IsNumeric(c.Value.GetType()))
     {
         NamedValueExpression nv;
         TypeAndValue         tv = new TypeAndValue(c.Type, c.Value);
         if (!this.map.TryGetValue(tv, out nv))   // re-use same name-value if same type & value
         {
             string name = "p" + (iParam++);
             nv = new NamedValueExpression(name, this.language.TypeSystem.GetColumnType(c.Type), c);
             this.map.Add(tv, nv);
         }
         return(nv);
     }
     return(c);
 }
        protected override Expression VisitBinary(BinaryExpression b)
        {
            Expression left  = this.Visit(b.Left);
            Expression right = this.Visit(b.Right);

            if (left.NodeType == (ExpressionType)DbExpressionType.NamedValue &&
                right.NodeType == (ExpressionType)DbExpressionType.Column)
            {
                NamedValueExpression nv = (NamedValueExpression)left;
                ColumnExpression     c  = (ColumnExpression)right;
                left = new NamedValueExpression(nv.Name, c.QueryType, nv.Value);
            }
            else if (right.NodeType == (ExpressionType)DbExpressionType.NamedValue &&
                     left.NodeType == (ExpressionType)DbExpressionType.Column)
            {
                NamedValueExpression nv = (NamedValueExpression)right;
                ColumnExpression     c  = (ColumnExpression)left;
                right = new NamedValueExpression(nv.Name, c.QueryType, nv.Value);
            }
            return(this.UpdateBinary(b, left, right, b.Conversion, b.IsLiftedToNull, b.Method));
        }
Esempio n. 7
0
        protected override Expression VisitDeclaration(DeclarationCommand decl)
        {
            if (decl.Source != null)
            {
                // make query that returns all these declared values as an object[]
                var projection = new ProjectionExpression(
                    decl.Source,
                    Expression.NewArrayInit(
                        typeof(object),
                        decl.Variables.Select(v => v.Expression.Type.IsValueType
                            ? Expression.Convert(v.Expression, typeof(object))
                            : v.Expression).ToArray()
                        ),
                    Aggregator.GetAggregator(typeof(object[]), typeof(IEnumerable <object[]>))
                    );

                // create execution variable to hold the array of declared variables
                var vars = Expression.Parameter(typeof(object[]), "vars");
                this.variables.Add(vars);
                this.initializers.Add(Expression.Constant(null, typeof(object[])));

                // create subsitution for each variable (so it will find the variable value in the new vars array)
                for (int i = 0, n = decl.Variables.Count; i < n; i++)
                {
                    var v = decl.Variables[i];
                    NamedValueExpression nv = new NamedValueExpression(
                        v.Name, v.QueryType,
                        Expression.Convert(Expression.ArrayIndex(vars, Expression.Constant(i)), v.Expression.Type)
                        );
                    this.variableMap.Add(v.Name, nv);
                }

                // make sure the execution of the select stuffs the results into the new vars array
                return(MakeAssign(vars, this.Visit(projection)));
            }

            // probably bad if we get here since we must not allow mulitple commands
            throw new InvalidOperationException("Declaration query not allowed for this langauge");
        }
Esempio n. 8
0
 protected override Expression VisitNamedValue(NamedValueExpression value)
 {
     this.namedValues.Add(value);
     return(value);
 }