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"); }
protected virtual NamedValueExpression CreateNamedValueForConstant(ConstantExpression expression) { var name = "p" + (iParam++); var nv = new NamedValueExpression(name, expression); map.Add(GetKeyNameForConstantExpression(expression), new List<NamedValueExpression> { nv }); return nv; }
protected virtual NamedValueExpression CreateNamedValueForConstant(ConstantExpression expression) { var name = "p" + (iParam++); var nv = new NamedValueExpression(name, expression); map.Add(GetKeyNameForConstantExpression(expression), new List <NamedValueExpression> { nv }); return(nv); }
private Expression GetNamedValue(Expression e) { NamedValueExpression nv; if (!this.pmap.TryGetValue(e, out nv)) { string name = "p" + (iParam++); nv = new NamedValueExpression(name, e); this.pmap.Add(e, nv); } return nv; }
private Expression GetNamedValue(Expression e) { NamedValueExpression nv; if (!this.pmap.TryGetValue(e, out nv)) { string name = "p" + (iParam++); nv = new NamedValueExpression(name, e); this.pmap.Add(e, nv); } return(nv); }
protected override Expression VisitMember(MemberExpression memberExp) { memberExp = (MemberExpression)base.VisitMember(memberExp); NamedValueExpression nv = memberExp.Expression as NamedValueExpression; if (nv != null) { Expression x = Expression.MakeMemberAccess(nv.Value, memberExp.Member); return(GetNamedValue(x)); } return(memberExp); }
/// <summary> /// Visits the column assignment. /// </summary> /// <param name="ca">The ca.</param> /// <returns></returns> 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, 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(this.GetNamedValue(x)); } return(m); }
protected override Expression VisitConstant(ConstantExpression c) { if (c.Value != null && !IsNumeric(c.Value.GetType())) { NamedValueExpression nv; if (!this.map.TryGetValue(c.Value, out nv)) { // re-use same name-value if same value string name = "p" + (iParam++); nv = new NamedValueExpression(name, c); this.map.Add(c.Value, nv); } return nv; } return c; }
protected NamedValueExpression GetExistingNamedValue(ConstantExpression expression) { List <NamedValueExpression> nvItems; if (map.TryGetValue(GetKeyNameForConstantExpression(expression), out nvItems)) { NamedValueExpression nv = nvItems[0]; if (nv.Value.Type == expression.Type) { return(nv); } } return(null); }
private Expression GetNamedValue(Expression e) { NamedValueExpression nv; HashedExpression he = new HashedExpression(e); if (!this.pmap.TryGetValue(he, out nv)) { string name = "@__Param__" + (this.parameterCounter++) + "__"; nv = new NamedValueExpression(name, this.language.TypeSystem.GetColumnType(e.Type), e); this.pmap.Add(he, nv); } return(nv); }
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.SqlType, column); this.map.Add(column, nv); } return(nv); } return(column); }
protected override Expression VisitConstant(ConstantExpression c) { //parametrize constants string par = String.Format("{0}", _parameters.Count + 1); if (_parameters == null) { _parameters = new Dictionary <string, object>(); } _parameters.Add(par, c.Value); var result = new NamedValueExpression(par, c); return(base.VisitNamedValue(result)); }
protected override Expression VisitConstant(ConstantExpression c) { if (c.Value != null && !IsNumeric(c.Value.GetType())) { TypeAndValue tv = new TypeAndValue(c.Type, c.Value); if (!this.map.TryGetValue(tv, out NamedValueExpression nv)) { // re-use same name-value if same type & value string name = "p" + (iParam++); nv = new NamedValueExpression(name, c); this.map.Add(tv, nv); } return(nv); } return(c); }
protected override Expression VisitConstant(ConstantExpression c) { if (c.Value != null && !IsNumeric(c.Value.GetType())) { NamedValueExpression nv; if (!this.map.TryGetValue(c.Value, out nv)) // re-use same name-value if same value { string name = "p" + (iParam++); nv = new NamedValueExpression(name, c); this.map.Add(c.Value, nv); } return(nv); } return(c); }
protected override Expression VisitColumn(ColumnExpression column) { if (column.Alias == this.outerAlias) { NamedValueExpression nv; if (!this.map.TryGetValue(column, out nv)) { string name = "@__Param__" + (this.parameterCounter++) + "__"; nv = new NamedValueExpression(name, column.QueryType, column); this.map.Add(column, nv); } return nv; } return column; }
// ...same for all others, just... // ... // implement your own for one 'route' protected 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 VisitColumn(ColumnExpression column) { if (column.Alias == this.outerAlias) { NamedValueExpression nv; if (!this.map.TryGetValue(column, out nv)) { string name = "@__Param__" + (this.parameterCounter++) + "__"; nv = new NamedValueExpression(name, column.QueryType, column); this.map.Add(column, nv); } return(nv); } return(column); }
/// <summary> /// Visits the binary. /// </summary> /// <param name="b">The b.</param> /// <returns></returns> 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, nv.Value); } else if (b.Right.NodeType == (ExpressionType)DbExpressionType.NamedValue && b.Left.NodeType == (ExpressionType)DbExpressionType.Column) { NamedValueExpression nv = (NamedValueExpression)right; ColumnExpression c = (ColumnExpression)left; right = new NamedValueExpression(nv.Name, nv.Value); } return(this.UpdateBinary(b, left, right, b.Conversion, b.IsLiftedToNull, b.Method)); }
protected override NamedValueExpression CreateNamedValueForConstant(ConstantExpression expression) { var name = "p" + (iParam++); var nv = new NamedValueExpression(name, expression); var keyNameForConstantExpression = GetKeyNameForConstantExpression(expression); List <NamedValueExpression> nvList; if (map.TryGetValue(keyNameForConstantExpression, out nvList)) { nvList.Add(nv); } else { map.Add(keyNameForConstantExpression, new List <NamedValueExpression> { nv }); } return(nv); }
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 = QueryUtility.GetNamedValueExpression(nv.Name, nv.Value, (DbType)c.MapInfo.DataType); } else if (b.Right.NodeType == (ExpressionType)DbExpressionType.NamedValue && b.Left.NodeType == (ExpressionType)DbExpressionType.Column) { NamedValueExpression nv = (NamedValueExpression)right; ColumnExpression c = (ColumnExpression)left; right = QueryUtility.GetNamedValueExpression(nv.Name, nv.Value, (DbType)c.MapInfo.DataType); } return(b.Update(left, b.Conversion, right)); }
protected override Expression VisitConstant(ConstantExpression c) { if (c.Value != null && !this.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 { var queryType = this.language.TypeSystem.GetColumnType(c.Type); if (queryType == null) { return(c); } string name = "@__Param__" + (this.parameterCounter++) + "__"; nv = new NamedValueExpression(name, queryType, c); this.map.Add(tv, nv); } return(nv); } return(c); }
protected override Expression VisitNamedValue(NamedValueExpression value) { this.WriteParameterName(value.Name); return value; }
protected virtual Expression VisitNamedValue(NamedValueExpression value) { return value; }
protected virtual bool CompareNamedValue(NamedValueExpression a, NamedValueExpression b) { return a.Name == b.Name && this.Compare(a.Value, b.Value); }
protected override Expression VisitNamedValue(NamedValueExpression value) { this.namedValues.Add(value); return(value); }
/// <summary> /// Visits the named value. /// </summary> /// <param name="value">The value.</param> /// <returns></returns> protected override Expression VisitNamedValue(NamedValueExpression value) { this.WriteParameterName(value.Name); return(value); }
protected override Expression VisitNamedValue(NamedValueExpression value) { sb.Append(":" + value.Name); return value; }
private bool CompareNamedValue(NamedValueExpression a, NamedValueExpression b) { return a.Name == b.Name && this.Compare(a.Value, b.Value); }
protected override Expression VisitNamedValue(NamedValueExpression value) { sb.Append(":" + value.Name); return(value); }
protected override Expression VisitNamedValue(NamedValueExpression value) { if (value.Type == typeof(string)) sb.Append("enlist "); switch (value.Name) { case "p0": sb.Append("x"); break; case "p1": sb.Append("y"); break; case "p2": sb.Append("z"); break; default: break; // throw new NotSupportedException(); } return value; }
protected override Expression VisitNamedValue(NamedValueExpression value) { this.namedValues.Add(value); return value; }
protected override Expression VisitColumn(ColumnExpression column) { if (column.Alias == outerAlias) { NamedValueExpression nv; if (!map.TryGetValue(column, out nv)) { nv = new NamedValueExpression("n" + (iParam++), column); map.Add(column, nv); } return nv; } return column; }
protected override Expression VisitNamedValue(NamedValueExpression value) { return(base.VisitNamedValue(value)); }
protected override NamedValueExpression CreateNamedValueForConstant(ConstantExpression expression) { var name = "p" + (iParam++); var nv = new NamedValueExpression(name, expression); var keyNameForConstantExpression = GetKeyNameForConstantExpression(expression); List<NamedValueExpression> nvList; if (map.TryGetValue(keyNameForConstantExpression, out nvList)) nvList.Add(nv); else map.Add(keyNameForConstantExpression, new List<NamedValueExpression> { nv }); return nv; }