internal override SqlExpression VisitBinaryOperator(SqlBinary bo) { if(IsCompareToValue(bo)) { SqlMethodCall call = (SqlMethodCall)bo.Left; if(IsCompareToMethod(call)) { int iValue = System.Convert.ToInt32(this.Eval(bo.Right), Globalization.CultureInfo.InvariantCulture); bo = this.MakeCompareTo(call.Object, call.Arguments[0], bo.NodeType, iValue) ?? bo; } else if(IsCompareMethod(call)) { int iValue = System.Convert.ToInt32(this.Eval(bo.Right), Globalization.CultureInfo.InvariantCulture); bo = this.MakeCompareTo(call.Arguments[0], call.Arguments[1], bo.NodeType, iValue) ?? bo; } } else if(IsVbCompareStringEqualsValue(bo)) { SqlMethodCall call = (SqlMethodCall)bo.Left; int iValue = System.Convert.ToInt32(this.Eval(bo.Right), Globalization.CultureInfo.InvariantCulture); //in VB, comparing a string with Nothing means comparing with "" SqlValue strValue = call.Arguments[1] as SqlValue; if(strValue != null && strValue.Value == null) { SqlValue emptyStr = new SqlValue(strValue.ClrType, strValue.SqlType, String.Empty, strValue.IsClientSpecified, strValue.SourceExpression); bo = this.MakeCompareTo(call.Arguments[0], emptyStr, bo.NodeType, iValue) ?? bo; } else { bo = this.MakeCompareTo(call.Arguments[0], call.Arguments[1], bo.NodeType, iValue) ?? bo; } } return base.VisitBinaryOperator(bo); }
internal override SqlExpression VisitValue(SqlValue value) { if(!value.IsClientSpecified && value.ClrType.IsClass && value.ClrType != typeof(string) && value.ClrType != typeof(Type) && value.Value != null) { throw Error.ClassLiteralsNotAllowed(value.ClrType); } return value; }
private SqlParameter InsertLookup(SqlValue cp) { SqlParameterInfo pi = null; if(!this.map.TryGetValue(cp, out pi)) { SqlParameter p; if(this.timeProviderType == null) { p = new SqlParameter(cp.ClrType, cp.SqlType, this.parameterizer.CreateParameterName(), cp.SourceExpression); pi = new SqlParameterInfo(p, cp.Value); } else { p = new SqlParameter(cp.ClrType, this.timeProviderType, this.parameterizer.CreateParameterName(), cp.SourceExpression); pi = new SqlParameterInfo(p, ((DateTime)cp.Value).TimeOfDay); } this.map.Add(cp, pi); this.currentParams.Add(pi); } return pi.Parameter; }
internal virtual SqlExpression VisitValue(SqlValue value) { return value; }
private Type GenerateValue(SqlValue value) { return this.GenerateConstant(value.ClrType, value.Value); }
internal override SqlExpression VisitValue(SqlValue value) { if(value.IsClientSpecified && !_isDebugMode) { throw Error.InvalidFormatNode("Value"); } this.FormatValue(value.Value); return value; }
internal override SqlExpression VisitValue(SqlValue value) { return value; }
private SqlExpression CoerceValueForExpression(SqlValue value, SqlExpression expression) { object clrValue = value.Value; if(!value.ClrType.IsAssignableFrom(expression.ClrType)) { clrValue = DBConvert.ChangeType(clrValue, expression.ClrType); } ProviderType newSqlType = typeProvider.ChangeTypeFamilyTo(value.SqlType, expression.SqlType); return sql.Value(expression.ClrType, newSqlType, clrValue, value.IsClientSpecified, value.SourceExpression); }
internal override SqlExpression VisitValue(SqlValue value) { if(this.topLevel || !value.IsClientSpecified || !value.SqlType.CanBeParameter) { return value; } return this.InsertLookup(value); }
/// <summary> /// Return a node representing typeof(typeOf) /// </summary> internal SqlExpression StaticType(MetaType typeOf, Expression sourceExpression) { if(typeOf == null) throw Error.ArgumentNull("typeOf"); if(typeOf.InheritanceCode == null) { // If no inheritance is involved, then there's no discriminator to // make a discriminated type. In this case, just make a literal type. return new SqlValue(typeof(Type), this.typeProvider.From(typeof(Type)), typeOf.Type, false, sourceExpression); } Type type = typeOf.InheritanceCode.GetType(); SqlValue match = new SqlValue(type, this.typeProvider.From(type), typeOf.InheritanceCode, true, sourceExpression); return this.DiscriminatedType(match, typeOf); }