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 ParameterExpression vars = Expression.Parameter(typeof(object[]), "vars"); variables.Add(vars); 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++) { VariableDeclaration v = decl.Variables[i]; var nv = new NamedValueExpression(v.Name, v.QueryType, Expression.Convert(Expression.ArrayIndex(vars, Expression.Constant(i)), v.Expression.Type)); variableMap.Add(v.Name, nv); } // make sure the execution of the select stuffs the results into the new vars array return(MakeAssign(vars, 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"); }
protected override ColumnAssignment VisitColumnAssignment(ColumnAssignment ca) { ca = base.VisitColumnAssignment(ca); Expression expression = ca.Expression; var nv = expression as NamedValueExpression; if (nv != null) { expression = new NamedValueExpression(nv.Name, ca.Column.QueryType, nv.Value); } return(UpdateColumnAssignment(ca, ca.Column, expression)); }
private Expression GetNamedValue(Expression e) { NamedValueExpression nv; var he = new HashedExpression(e); if (!pmap.TryGetValue(he, out nv)) { string name = "p" + (iParam++); nv = new NamedValueExpression(name, language.TypeSystem.GetColumnType(e.Type), e); pmap.Add(he, nv); } return(nv); }
protected override Expression VisitColumn(ColumnExpression column) { if (column.Alias == outerAlias) { NamedValueExpression nv; if (!map.TryGetValue(column, out nv)) { nv = new NamedValueExpression("n" + (iParam++), column.QueryType, column); map.Add(column, nv); } return(nv); } return(column); }
protected override Expression VisitConstant(ConstantExpression c) { if (c.Value != null && !IsNumeric(c.Value.GetType())) { NamedValueExpression nv; var tv = new TypeAndValue(c.Type, c.Value); if (!map.TryGetValue(tv, out nv)) { // re-use same name-value if same type & value string name = "p" + (iParam++); nv = new NamedValueExpression(name, language.TypeSystem.GetColumnType(c.Type), c); map.Add(tv, nv); } return(nv); } return(c); }
protected override Expression VisitBinary(BinaryExpression b) { Expression left = Visit(b.Left); Expression right = Visit(b.Right); if (left.NodeType == (ExpressionType)DbExpressionType.NamedValue && right.NodeType == (ExpressionType)DbExpressionType.Column) { var nv = (NamedValueExpression)left; var c = (ColumnExpression)right; left = new NamedValueExpression(nv.Name, c.QueryType, nv.Value); } else if (b.Right.NodeType == (ExpressionType)DbExpressionType.NamedValue && b.Left.NodeType == (ExpressionType)DbExpressionType.Column) { var nv = (NamedValueExpression)right; var c = (ColumnExpression)left; right = new NamedValueExpression(nv.Name, c.QueryType, nv.Value); } return(UpdateBinary(b, left, right, b.Conversion, b.IsLiftedToNull, b.Method)); }
protected virtual bool CompareNamedValue(NamedValueExpression a, NamedValueExpression b) { return(a.Name == b.Name && Compare(a.Value, b.Value)); }
protected virtual Expression VisitNamedValue(NamedValueExpression value) { return(value); }
protected override Expression VisitNamedValue(NamedValueExpression value) { namedValues.Add(value); return(value); }
protected override Expression VisitNamedValue(NamedValueExpression value) { WriteParameterName(value.Name); return(value); }