public ParameterInfoAttribute(ParameterAccessor a)
        {
            Access = a;
            switch (a)
            {
            case ParameterAccessor.Int:
                Type = typeof(int);
                break;

            case ParameterAccessor.Float:
                Type = typeof(float);
                break;

            case ParameterAccessor.IntArray:
                Type = typeof(int[]);
                break;

            case ParameterAccessor.FloatArray:
                Type = typeof(float[]);
                break;

            default:
                break;
            }
        }
Esempio n. 2
0
        static void BuildTake(ExpressionBuilder builder, IBuildContext sequence, ISqlExpression expr, TakeHints?hints)
        {
            var sql = sequence.SelectQuery;

            if (hints != null && !builder.DataContext.SqlProviderFlags.GetIsTakeHintsSupported(hints.Value))
            {
                throw new LinqException("TakeHints are {0} not supported by current database".Args(hints));
            }

            if (hints != null && sql.Select.SkipValue != null)
            {
                throw new LinqException("Take with hints could not be applied with Skip");
            }

            sql.Select.Take(expr, hints);

            if (sql.Select.SkipValue != null &&
                builder.DataContext.SqlProviderFlags.IsTakeSupported &&
                !builder.DataContext.SqlProviderFlags.GetIsSkipSupportedFlag(sql))
            {
                if (sql.Select.SkipValue is SqlParameter && sql.Select.TakeValue is SqlValue)
                {
                    var skip = (SqlParameter)sql.Select.SkipValue;
                    var parm = (SqlParameter)sql.Select.SkipValue.Clone(new Dictionary <ICloneableElement, ICloneableElement>(), _ => true);

                    parm.SetTakeConverter((int)((SqlValue)sql.Select.TakeValue).Value);

                    sql.Select.Take(parm, hints);

                    var ep = (from pm in builder.CurrentSqlParameters where pm.SqlParameter == skip select pm).First();

                    ep = new ParameterAccessor(ep.Expression, ep.Accessor, ep.DataTypeAccessor, parm);

                    builder.CurrentSqlParameters.Add(ep);
                }
                else
                {
                    sql.Select.Take(builder.Convert(
                                        sequence,
                                        new SqlBinaryExpression(typeof(int), sql.Select.SkipValue, "+", sql.Select.TakeValue, Precedence.Additive)), hints);
                }
            }

            if (!builder.DataContext.SqlProviderFlags.GetAcceptsTakeAsParameterFlag(sql))
            {
                var p = sql.Select.TakeValue as SqlParameter;

                if (p != null)
                {
                    p.IsQueryParameter = false;
                }
            }
        }
Esempio n. 3
0
        private static void BuildTake(ExpressionBuilder builder, IBuildContext sequence, IQueryExpression expr)
        {
            var sql = sequence.Select;

            sql.Select.TakeValue = expr;

            if (sql.Select.SkipValue != null &&
                builder.DataContextInfo.SqlProviderFlags.IsTakeSupported &&
                !builder.DataContextInfo.SqlProviderFlags.GetIsSkipSupportedFlag(sql))
            {
                var sqlParameter = sql.Select.SkipValue as ISqlParameter;
                var sqlValue     = sql.Select.TakeValue as ISqlValue;
                if (sqlParameter != null && sqlValue != null)
                {
                    var skip = sqlParameter;
                    var parm =
                        (ISqlParameter)
                        sqlParameter.Clone(new Dictionary <ICloneableElement, ICloneableElement>(), _ => true);

                    parm.SetTakeConverter((int)sqlValue.Value);

                    sql.Select.TakeValue = parm;

                    var ep = (from pm in builder.CurrentSqlParameters where pm.SqlParameter == skip select pm).First();

                    ep = new ParameterAccessor
                    {
                        Expression   = ep.Expression,
                        Accessor     = ep.Accessor,
                        SqlParameter = parm
                    };

                    builder.CurrentSqlParameters.Add(ep);
                }
                else
                {
                    sql.Select.TakeValue = builder.Convert(
                        sequence,
                        new SqlBinaryExpression(typeof(int), sql.Select.SkipValue, "+", sql.Select.TakeValue,
                                                Precedence.Additive));
                }
            }

            if (!builder.DataContextInfo.SqlProviderFlags.GetAcceptsTakeAsParameterFlag(sql))
            {
                var p = sql.Select.TakeValue as ISqlParameter;

                if (p != null)
                {
                    p.IsQueryParameter = false;
                }
            }
        }
Esempio n. 4
0
        static void BuildTake(ExpressionBuilder builder, IBuildContext sequence, ISqlExpression expr)
        {
            var sql = sequence.SqlQuery;

            builder.SqlProvider.SqlQuery = sql;

            sql.Select.Take(expr);

            if (sql.Select.SkipValue != null && builder.SqlProvider.IsTakeSupported && !builder.SqlProvider.IsSkipSupported)
            {
                if (sql.Select.SkipValue is SqlParameter && sql.Select.TakeValue is SqlValue)
                {
                    var skip = (SqlParameter)sql.Select.SkipValue;
                    var parm = (SqlParameter)sql.Select.SkipValue.Clone(new Dictionary <ICloneableElement, ICloneableElement>(), _ => true);

                    parm.SetTakeConverter((int)((SqlValue)sql.Select.TakeValue).Value);

                    sql.Select.Take(parm);

                    var ep = (from pm in builder.CurrentSqlParameters where pm.SqlParameter == skip select pm).First();

                    ep = new ParameterAccessor
                    {
                        Expression   = ep.Expression,
                        Accessor     = ep.Accessor,
                        SqlParameter = parm
                    };

                    builder.CurrentSqlParameters.Add(ep);
                }
                else
                {
                    sql.Select.Take(builder.Convert(
                                        sequence,
                                        new SqlBinaryExpression(typeof(int), sql.Select.SkipValue, "+", sql.Select.TakeValue, Precedence.Additive)));
                }
            }

            if (!builder.SqlProvider.TakeAcceptsParameter)
            {
                var p = sql.Select.TakeValue as SqlParameter;

                if (p != null)
                {
                    p.IsQueryParameter = false;
                }
            }
        }
 public ParameterInfoAttribute(ParameterAccessor a, Type t)
 {
     Access = a;
     if (a == ParameterAccessor.FloatArray)
     {
         Type = typeof(float[]);
     }
     else if (a == ParameterAccessor.IntArray)
     {
         Type = typeof(int[]);
     }
     else
     {
         Type = t;
     }
 }
Esempio n. 6
0
		static void ParseTake(ExpressionParser parser, IParseContext sequence, ISqlExpression expr)
		{
			var sql = sequence.SqlQuery;

			parser.SqlProvider.SqlQuery = sql;

			sql.Select.Take(expr);

			if (sql.Select.SkipValue != null && parser.SqlProvider.IsTakeSupported && !parser.SqlProvider.IsSkipSupported)
			{
				if (sql.Select.SkipValue is SqlParameter && sql.Select.TakeValue is SqlValue)
				{
					var skip = (SqlParameter)sql.Select.SkipValue;
					var parm = (SqlParameter)sql.Select.SkipValue.Clone(new Dictionary<ICloneableElement,ICloneableElement>(), _ => true);

					parm.SetTakeConverter((int)((SqlValue)sql.Select.TakeValue).Value);

					sql.Select.Take(parm);

					var ep = (from pm in parser.CurrentSqlParameters where pm.SqlParameter == skip select pm).First();

					ep = new ParameterAccessor
					{
						Expression   = ep.Expression,
						Accessor     = ep.Accessor,
						SqlParameter = parm
					};

					parser.CurrentSqlParameters.Add(ep);
				}
				else
					sql.Select.Take(parser.Convert(
						sequence,
						new SqlBinaryExpression(typeof(int), sql.Select.SkipValue, "+", sql.Select.TakeValue, Precedence.Additive)));
			}

			if (!parser.SqlProvider.TakeAcceptsParameter)
			{
				var p = sql.Select.TakeValue as SqlParameter;

				if (p != null)
					p.IsQueryParameter = false;
			}
		}
        public ParameterInfoAttribute(Type t)
        {
            Type = t;

            bool wasarray = t.IsArray;

            if (wasarray)
            {
                t = t.GetElementType();
            }

            if (t.IsEnum)
            {
                Access = ParameterAccessor.Int;
            }
            else if (t == typeof(byte) || t == typeof(sbyte) || t == typeof(short) || t == typeof(ushort) || t == typeof(int) || t == typeof(uint) || t == typeof(bool))
            {
                Access = ParameterAccessor.Int;
            }
            else if (t == typeof(float) || t == typeof(double))
            {
                Access = ParameterAccessor.Float;
            }
            else
            {
                Access = ParameterAccessor.Int;
            }

            if (wasarray && Access == ParameterAccessor.Float)
            {
                Access = ParameterAccessor.FloatArray;
            }
            if (wasarray && Access == ParameterAccessor.Int)
            {
                Access = ParameterAccessor.IntArray;
            }
        }
		ParameterAccessor BuildParameter(Expression expr)
		{
			ParameterAccessor p;

			if (_parameters.TryGetValue(expr, out p))
				return p;

			string name = null;

			var newExpr = ReplaceParameter(_expressionAccessors, expr, nm => name = nm);
			var mapper  = Expression.Lambda<Func<Expression,object[],object>>(
				Expression.Convert(newExpr, typeof(object)),
				new [] { ExpressionParam, ParametersParam });

			p = new ParameterAccessor
			{
				Expression   = expr,
				Accessor     = mapper.Compile(),
				SqlParameter = new SqlParameter(expr.Type, name, null)
			};

			_parameters.Add(expr, p);
			CurrentSqlParameters.Add(p);

			return p;
		}
		ISqlExpression GetParameter(Expression ex, MemberInfo member)
		{
			if (member is MethodInfo)
				member = TypeHelper.GetPropertyByMethod((MethodInfo)member);

			var par    = ReplaceParameter(_expressionAccessors, ex, _ => {});
			var expr   = Expression.MakeMemberAccess(par.Type == typeof(object) ? Expression.Convert(par, member.DeclaringType) : par, member);
			var mapper = Expression.Lambda<Func<Expression,object[],object>>(
				Expression.Convert(expr, typeof(object)),
				new [] { ExpressionParam, ParametersParam });

			var p = new ParameterAccessor
			{
				Expression   = expr,
				Accessor     = mapper.Compile(),
				SqlParameter = new SqlParameter(expr.Type, member.Name, null)
			};

			_parameters.Add(expr, p);
			CurrentSqlParameters.Add(p);

			return p.SqlParameter;
		}
Esempio n. 10
0
 public override Mutator Extract(ParameterAccessor accessor)
 {
     throw new SyntaxErrorException("Can not access instance inside variable declaration");
 }
Esempio n. 11
0
 public override Mutator WithAssignment(ParameterAccessor accessor, Mutator value)
 {
     throw new SyntaxErrorException("Assignments inside variable declarations are unsupported");
 }
Esempio n. 12
0
 public int RegisterAccessor(ParameterAccessor accessor)
 {
     _accessors ??= new List <ParameterAccessor>();
     _accessors.Add(accessor);
     return(_accessors.Count - 1);
 }
Esempio n. 13
0
 public Mutator Extract(ParameterAccessor accessor)
 {
     Debug.Assert(false, "A parameter access reached a Mutator?!");
     throw new NotImplementedException();
 }
Esempio n. 14
0
 public Mutator WithAssignment(ParameterAccessor accessor, Mutator value)
 {
     Debug.Assert(false, "A parameter access reached a Mutator?!");
     throw new NotImplementedException();
 }