Beispiel #1
0
                public void Build(Sql.ISqExtensionBuilder builder)
                {
                    var method = (MethodInfo)builder.Member;
                    var arg    = method.GetGenericArguments().Single();

                    builder.AddParameter("table_field", new SqlTable(builder.Mapping, arg));
                }
Beispiel #2
0
        public void Build(Sql.ISqExtensionBuilder builder)
        {
            builder.Expression = "JSON_MODIFY({source}, {path}, {value})";

            builder.AddParameter("source", builder.GetExpression(0));

            var member = (MemberExpression)((LambdaExpression)((UnaryExpression)builder.Arguments[1]).Operand).Body;

            builder.AddParameter("path", $"$.{member.Member.Name}");

            var propertyExpression = (MemberExpression)builder.Arguments[2];
            var memberExpression   = (MemberExpression)propertyExpression.Expression !;
            var fieldInfo          = (FieldInfo)memberExpression.Member;
            var valueExpression    = (ConstantExpression)memberExpression.Expression !;
            var value = ((PropertyInfo)propertyExpression.Member).GetValue(fieldInfo.GetValue(valueExpression.Value)) !;

            builder.AddParameter("value", value.ToString() !);
        }
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                var pathExpr = builder.Arguments[0];

                if (pathExpr.NodeType != ExpressionType.MemberAccess)
                {
                    throw new NotSupportedException();
                }

                var pathList = new List <Expression>();
                var current  = pathExpr;

                while (true)
                {
                    pathList.Add(current);
                    if (current.NodeType == ExpressionType.MemberAccess)
                    {
                        current = ((MemberExpression)current).Expression;
                    }
                    else
                    {
                        break;
                    }
                }

                pathList.Reverse();

                var entity = pathList[0];
                var field  = pathList[1];

                var fieldSql = builder.ConvertExpressionToSql(field);

                builder.AddParameter("field", fieldSql);

                var propPathStr = "$";

                for (int i = 2; i < pathList.Count; i++)
                {
                    propPathStr += "." + ((MemberExpression)pathList[i]).Member.Name;
                }

                builder.AddParameter("propPath", new SqlValue(propPathStr));
            }
Beispiel #4
0
        public void Build(Sql.ISqExtensionBuilder builder)
        {
            var values = builder.GetValue <System.Collections.IEnumerable>("values");

            builder.Query.IsParameterDependent = true;

            foreach (var value in values)
            {
                var param = new SqlParameter(value?.GetType() ?? typeof(int?), "p", value);
                builder.AddParameter("values", param);
            }
        }
Beispiel #5
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                if (!(builder.GetExpression("src") is SqlField field))
                {
                    throw new InvalidOperationException("Can not get table");
                }

                var sqlTable = (SqlTable)field.Table !;

                var newField = new SqlField(sqlTable, sqlTable.PhysicalName !);

                builder.AddParameter("table_field", newField);
            }
Beispiel #6
0
            public void Build(Sql.ISqExtensionBuilder builder)
            {
                var field = builder.GetExpression("src") as SqlField;

                if (field == null)
                {
                    throw new InvalidOperationException("Can not get table");
                }

                var sqlTable = (SqlTable)field.Table;
                var newField = new SqlField
                {
                    Name  = sqlTable.PhysicalName,
                    Table = sqlTable
                };

                builder.AddParameter("table_field", newField);
            }
Beispiel #7
0
        /// <summary>
        /// Builds the parametrized sql IN expression
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <exception cref="ArgumentNullException">Values for \"In\" operation should not be empty - values</exception>
        /// <see cref="SqlExtensions.In{T}(Sql.ISqlExtension,T,IEnumerable{T})"/>
        /// <seealso cref="SqlExtensions.In{T}(Sql.ISqlExtension,T,IEnumerable{T})"/>
        public void Build(Sql.ISqExtensionBuilder builder)
        {
            var parameterName = (builder.Arguments[2] as MemberExpression)?.Member.Name ?? "p";

            var values = builder.GetValue <System.Collections.IEnumerable>("values")
                         ?.OfType <object>()
                         .ToArray();

            if (values == null || values.Length == 0)
            {
                throw new ArgumentNullException("values", "Values for \"In\" operation should not be empty");
            }

            foreach (var value in values)
            {
                var param = new SqlParameter(value?.GetType() ?? typeof(object), parameterName, value);
                builder.AddParameter("values", param);
            }
        }
 public static Sql.SqlExtensionParam AddExpression(this Sql.ISqExtensionBuilder builder, string name, string expr)
 {
     return(builder.AddParameter(name, new SqlExpression(expr, Precedence.Primary)));
 }
 public static Sql.SqlExtensionParam AddParameter(this Sql.ISqExtensionBuilder builder, string name, string value)
 {
     return(builder.AddParameter(name, new SqlValue(value)));
 }