Esempio n. 1
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                throw new ArgumentException(string.Format(Res.ArgumentCountError, "CASE", "", " 2 or 3 "));
            }

            var whens = (args[0] as ICollection <Expression>).ToArray();
            var thens = (args[1] as ICollection <Expression>).ToArray();
            var @else = args[2] as Expression;

            builder.Append("CASE");

            var lenght = whens.Length;

            for (int i = 0; i < lenght; i++)
            {
                builder.Append(" WHEN ");
                builder.Visit(whens[i]);
                builder.Append(" THEN ");
                builder.Visit(thens[i]);
            }

            if (@else != null)
            {
                builder.Append(" ELSE ");
                builder.Visit(@else);
            }

            builder.Append(" END");
        }
        /// <summary>
        /// 将表达式所表示的SQL片断写入SQL构造器
        /// </summary>
        public void Write(ISqlBuilder builder, bool newLine)
        {
            if (_qOrder.Count > 0)
            {
                base._builder = builder;
                if (base._methodVisitor == null)
                {
                    base._methodVisitor = _provider.CreateMethodCallVisitor(this);
                }

                if (newLine)
                {
                    _builder.AppendNewLine();
                }
                _builder.Append("ORDER BY ");


                //foreach (DbExpression qj in _qOrder)
                for (int i = 0; i < _qOrder.Count; i++)
                {
                    this.Visit(_qOrder[i].Expressions[0]);
                    if (_qOrder[i].DbExpressionType == DbExpressionType.OrderByDescending || _qOrder[i].DbExpressionType == DbExpressionType.ThenByDescending)
                    {
                        builder.Append(" DESC");
                    }
                    if (i < _qOrder.Count - 1)
                    {
                        builder.Append(',');
                    }
                }
            }
        }
        /// <summary>
        /// 访问表达式节点
        /// </summary>
        /// <param name="havings">分组筛选表达式</param>
        public override Expression Visit(List <DbExpression> havings)
        {
            if (havings != null && havings.Count > 0)
            {
                _builder.AppendNewLine();
                _builder.Append("Having ");

                for (int index = 0; index < havings.Count; index++)
                {
                    DbExpression d    = havings[index];
                    var          node = d.Expressions[0];
                    if (node.NodeType == ExpressionType.Lambda)
                    {
                        node = ((LambdaExpression)node).Body;
                    }
                    node = BooleanUnaryToBinary(node);

                    base.Visit(node);
                    if (index < havings.Count - 1)
                    {
                        _builder.Append(" AND ");
                    }
                }
            }

            return(null);
        }
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     if (args == null)
     {
         throw new NotSupportedException("args");
     }
     if (args.Length != 2 && args.Length != 3)
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "PadRight", "", "2 or 3"));
     }
     builder.Append("RPAD(");
     builder.Visit(args[0]);
     builder.Append(",");
     builder.Visit(args[1]);
     builder.Append(",");
     if (args.Length == 2)
     {
         builder.Append("' ')");
     }
     else
     {
         builder.Visit(args[2]);
         builder.Append(")");
     }
 }
Esempio n. 5
0
        public void Render(ISqlBuilder visitor, params Expression[] args)
        {
            var whens = (args[0] as ICollection<Expression>).ToArray();
            var thens = (args[1] as ICollection<Expression>).ToArray();
            var @else = args[2] as Expression;

            var lenght = whens.Length;
            for (int i = 0; i < lenght; i++)
            {
                if (i != 0)
                    visitor.Append(",");

                visitor.Append("IIF(");
                visitor.Visit(whens[i]);
                visitor.Append(",");
                visitor.Visit(thens[i]);

                if (i == lenght - 1)
                {
                    if (@else != null)
                    {
                        visitor.Append(",");
                        visitor.Visit(@else);
                    }
                    for (var j = i; j >= 0; j--)
                        visitor.Append(")");

                }

            }
        }
Esempio n. 6
0
        /// <summary>
        /// 访问表达式节点
        /// </summary>
        /// <param name="wheres">筛选表达式</param>
        public override Expression Visit(List <DbExpression> wheres)
        {
            if (wheres != null && wheres.Count > 0)
            {
                if (_builder.Length > 0)
                {
                    _builder.Append(" AND ");
                }

                for (int index = 0; index < wheres.Count; index++)
                {
                    DbExpression d    = wheres[index];
                    var          node = d.Expressions[0];
                    if (node.NodeType == ExpressionType.Lambda)
                    {
                        node = ((LambdaExpression)node).Body;
                    }
                    node = BooleanUnaryToBinary(node);

                    base.Visit(node);
                    if (index < wheres.Count - 1)
                    {
                        _builder.Append(" AND ");
                    }
                }
            }

            return(null);
        }
Esempio n. 7
0
        // Cross Join
        private void AppendCrossJoin(ISqlBuilder jf, DbExpression dbExpression, TableAliasCache aliases)
        {
            if (!usedKeyword)
            {
                jf.AppendNewLine();
                jf.Append(_keywordName);
                usedKeyword = true;
            }
            else
            {
                jf.Append(',');
                jf.AppendNewLine();
                jf.Append(_pad);
            }

            LambdaExpression lambda = dbExpression.Expressions[1] as LambdaExpression;
            Type             type   = lambda.Parameters[1].Type;
            var typeRuntime         = TypeRuntimeInfoCache.GetRuntimeInfo(type);

            jf.AppendMember(typeRuntime.TableName, !typeRuntime.IsTemporary);

            string alias = aliases.GetTableAlias(lambda.Parameters[1]);

            jf.Append(' ');
            jf.Append(alias);
        }
Esempio n. 8
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            var value = args[1];
            var constExp = args[2] as ConstantExpression;
            if (constExp != null)
            {
                value = FormatValue(value,
                    (bool)constExp.Value
                    , (bool)(args[3] as ConstantExpression).Value
                    , (bool)(args[4] as ConstantExpression).Value);
            }
            else
            {
                var nv = args[2] as NamedValueExpression;
                if (nv != null)
                {
                    constExp = nv.Value as ConstantExpression;
                    value = FormatValue(value,
                   (bool)constExp.Value
                   , (bool)((args[3] as NamedValueExpression).Value as  ConstantExpression).Value
                   , (bool)((args[4] as NamedValueExpression).Value as ConstantExpression).Value);
                }
            }

            builder.Append("(");
            builder.Visit(args[0]);
            builder.Append(" LIKE ");
            builder.Visit(value);
            builder.Append(")");
        }
Esempio n. 9
0
 public virtual void Render(ISqlBuilder visitor, params Expression[] args)
 {
     var targetArg = args[0];
     visitor.Append("RTRIM(LTRIM(");
     visitor.Visit(targetArg);
     visitor.Append("))");
 }
Esempio n. 10
0
 public virtual void Render(ISqlBuilder builder, params Expression[] args)
 {
     builder.Append(name);
     builder.Append("(");
     builder.VisitEnumerable(args);
     builder.Append(")");
 }
Esempio n. 11
0
        public void Render(ISqlBuilder visitor, params Expression[] args)
        {
            var whens = (args[0] as ICollection <Expression>).ToArray();
            var thens = (args[1] as ICollection <Expression>).ToArray();
            var @else = args[2] as Expression;

            var lenght = whens.Length;

            for (int i = 0; i < lenght; i++)
            {
                if (i != 0)
                {
                    visitor.Append(",");
                }

                visitor.Append("IIF(");
                visitor.Visit(whens[i]);
                visitor.Append(",");
                visitor.Visit(thens[i]);

                if (i == lenght - 1)
                {
                    if (@else != null)
                    {
                        visitor.Append(",");
                        visitor.Visit(@else);
                    }
                    for (var j = i; j >= 0; j--)
                    {
                        visitor.Append(")");
                    }
                }
            }
        }
Esempio n. 12
0
 public virtual void Render(ISqlBuilder builder, params Expression[] args)
 {
     builder.Append(name);
     builder.Append("(");
     builder.VisitEnumerable(args);
     builder.Append(")");
 }
Esempio n. 13
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            if (args.Length != 2 && args.Length != 3)
            {
                throw new ArgumentException(string.Format(Res.ArgumentCountError, "CASE", "", " 2 or 3 "));
            }

            var whens = (args[0] as ICollection<Expression>).ToArray();
            var thens = (args[1] as ICollection<Expression>).ToArray();
            var @else = args[2] as Expression;

            builder.Append("CASE");

            var lenght = whens.Length;
            for (int i = 0; i < lenght; i++)
            {
                builder.Append(" WHEN ");
                builder.Visit(whens[i]);
                builder.Append(" THEN ");
                builder.Visit(thens[i]);
            }

            if (@else != null)
            {
                builder.Append(" ELSE ");
                builder.Visit(@else);
            }

            builder.Append(" END");
        }
Esempio n. 14
0
        /// <summary>
        /// 将表达式所表示的SQL片断写入SQL构造器
        /// </summary>
        public override void Write(ISqlBuilder builder)
        {
            base._builder = builder;
            if (base._methodVisitor == null)
            {
                base._methodVisitor = _provider.CreateMethodCallVisitor(this);
            }

            if (_statis != null)
            {
                Expression exp = _statis.DbExpressionType == DbExpressionType.Count ? Expression.Constant(1) : base.Expression;
                if (exp.NodeType == ExpressionType.Lambda)
                {
                    exp = (exp as LambdaExpression).Body;
                }

                // q.Average(a => a);
                // 这种情况下g.Key 一定是单个字段,否则解析出来的SQL执行不了
                if (exp.NodeType == ExpressionType.Parameter)
                {
                    exp = _groupBy.Expressions[0];
                }

                builder.Append(_statisMethods[_statis.DbExpressionType]);
                builder.Append("(");
                base.Visit(exp);
                builder.Append(")");
            }

            //base.Visit();
        }
Esempio n. 15
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            var value    = args[1];
            var constExp = args[2] as ConstantExpression;

            if (constExp != null)
            {
                value = FormatValue(value,
                                    (bool)constExp.Value
                                    , (bool)(args[3] as ConstantExpression).Value
                                    , (bool)(args[4] as ConstantExpression).Value);
            }
            else
            {
                var nv = args[2] as NamedValueExpression;
                if (nv != null)
                {
                    constExp = nv.Value as ConstantExpression;
                    value    = FormatValue(value,
                                           (bool)constExp.Value
                                           , (bool)((args[3] as NamedValueExpression).Value as  ConstantExpression).Value
                                           , (bool)((args[4] as NamedValueExpression).Value as ConstantExpression).Value);
                }
            }

            builder.Append("(");
            builder.Visit(args[0]);
            builder.Append(" LIKE ");
            builder.Visit(value);
            builder.Append(")");
        }
Esempio n. 16
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            if (args != null && args.Length > 0)
                throw new ArgumentException(string.Format(Res.ArgumentCountError, Name, "no", ""));

            builder.Append(Name);
            builder.Append("()");
        }
Esempio n. 17
0
        public virtual void Render(ISqlBuilder visitor, params Expression[] args)
        {
            var targetArg = args[0];

            visitor.Append("LTRIM(");
            visitor.Visit(targetArg);
            visitor.Append(")");
        }
Esempio n. 18
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     if (args.Length == 1)
     {
         builder.Append("DATE_FORMAT(");
         builder.Visit(args[0]);
         builder.Append(",'%H:%i:%s')");
     }
 }
Esempio n. 19
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     if (args.Length == 1)
     {
         builder.Append("DATE_FORMAT(");
         builder.Visit(args[0]);
         builder.Append(",'%H:%i:%s')");
     }
 }
Esempio n. 20
0
 /// <summary>
 /// 访问表达式节点
 /// </summary>
 /// <param name="groupBy">分组表达式</param>
 public override Expression Visit(DbExpression groupBy)
 {
     if (groupBy != null && groupBy.HasExpression)
     {
         _builder.AppendNewLine();
         _builder.Append("GROUP BY ");
         base.Visit(groupBy);
     }
     return(null);
 }
Esempio n. 21
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     builder.Append("CDate(");
     builder.Visit(args[0]);
     builder.Append(" & '/' & ");
     builder.Visit(args[1]);
     builder.Append(" & '/' & ");
     builder.Visit(args[2]);
     builder.Append(")");
 }
Esempio n. 22
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     builder.Append("CDate(");
     builder.Visit(args[0]);
     builder.Append(" & '/' & ");
     builder.Visit(args[1]);
     builder.Append(" & '/' & ");
     builder.Visit(args[2]);
     builder.Append(")");
 }
Esempio n. 23
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            if (args != null && args.Length > 0)
            {
                throw new ArgumentException(string.Format(Res.ArgumentCountError, Name, "no", ""));
            }

            builder.Append(Name);
            builder.Append("()");
        }
Esempio n. 24
0
 public void Render(ISqlBuilder visitor, params Expression[] args)
 {
     if (args == null || (args.Length != 2 && args.Length != 3))
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "remove()", "", " 2 or 3 "));
     }
     visitor.Append("IIF((LEN(");
     visitor.Visit(args[0]);
     visitor.Append(") < ");
     visitor.Visit(args[1]);
     visitor.Append("),NULL,REPLACE(");
     visitor.Visit(args[0]);
     visitor.Append(",MID(");
     visitor.Visit(args[0]);
     visitor.Append(",");
     visitor.Visit(args[1]);
     if (args.Length == 2)
     {
         visitor.Append(",8000)");
     }
     else
     {
         visitor.Append(",");
         visitor.Visit(args[2]);
         visitor.Append(")");
     }
     visitor.Append(",''))");
 }
Esempio n. 25
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     //SUBSTRING(userName,1,2)+'ddd'+SUBSTRING(userName,3,LEN(userName))
     if (args.Length != 3)
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "Insert", "", "3"));
     }
     //var secondStartIndex = Expression.Constant((int)(args[1] as ConstantExpression).Value + 1);
     builder.Append("(CASE WHEN ");
     builder.Visit(args[1]);
     builder.Append(" > LEN(");
     builder.Visit(args[0]);
     builder.Append(") THEN null ELSE (SUBSTRING(");
     builder.Visit(args[0]);
     builder.Append(",1,");
     builder.Visit(Expression.Subtract(Expression.Property(args[1], "Value"), Expression.Constant(1, Types.Int32)));
     builder.Append(") + ");
     builder.Visit(args[2]);
     builder.Append(" + SUBSTRING(");
     builder.Visit(args[0]);
     builder.Append(",");
     builder.Visit(args[1]);
     builder.Append(",LEN(");
     builder.Visit(args[0]);
     builder.Append("))) END)");
 }
Esempio n. 26
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     //SUBSTRING(userName,1,2)+'ddd'+SUBSTRING(userName,3,LEN(userName))
     if (args.Length != 3)
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "Insert", "", "3"));
     }
     //var secondStartIndex = Expression.Constant((int)(args[1] as ConstantExpression).Value + 1);
     builder.Append("(CASE WHEN ");
     builder.Visit(args[1]);
     builder.Append(" > LEN(");
     builder.Visit(args[0]);
     builder.Append(") THEN null ELSE (SUBSTRING(");
     builder.Visit(args[0]);
     builder.Append(",1,");
     builder.Visit(Expression.Subtract(Expression.Property(args[1], "Value"), Expression.Constant(1, Types.Int32)));
     builder.Append(") + ");
     builder.Visit(args[2]);
     builder.Append(" + SUBSTRING(");
     builder.Visit(args[0]);
     builder.Append(",");
     builder.Visit(args[1]);
     builder.Append(",LEN(");
     builder.Visit(args[0]);
     builder.Append("))) END)");
 }
Esempio n. 27
0
 public void Render(ISqlBuilder visitor, params Expression[] args)
 {
     if (args == null || (args.Length != 2 && args.Length != 3))
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "remove()", "", " 2 or 3 "));
     }
     visitor.Append("IIF((LEN(");
     visitor.Visit(args[0]);
     visitor.Append(") < ");
     visitor.Visit(args[1]);
     visitor.Append("),NULL,REPLACE(");
     visitor.Visit(args[0]);
     visitor.Append(",MID(");
     visitor.Visit(args[0]);
     visitor.Append(",");
     visitor.Visit(args[1]);
     if (args.Length == 2)
     {
         visitor.Append(",8000)");
     }
     else
     {
         visitor.Append(",");
         visitor.Visit(args[2]);
         visitor.Append(")");
     }
     visitor.Append(",''))");
 }
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            var year  = args[0];
            var month = args[1];

            builder.Append("(CASE");
            builder.Append(" WHEN ");
            builder.Visit(year);
            builder.Append("% 4 = 0 AND(");
            builder.Visit(year);
        }
Esempio n. 29
0
        public void Render(ISqlBuilder visitor, params Expression[] args)
        {
            if (args.Length != 2)
                throw new ArgumentException(string.Format(Res.ArgumentCountError, "dateadd", "", " 2 "));

            var addPart = (args[1] as ConstantExpression).Value;

            visitor.Append("(");
            visitor.Visit(args[0]);
            visitor.Append(" + interval '" + addPart.ToString() + "' " + Type.ToString() + ")");
        }
Esempio n. 30
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            var year = args[0];
            var month = args[1];

            builder.Append("(CASE");
            builder.Append(" WHEN ");
            builder.Visit(year);
            builder.Append("% 4 = 0 AND(");
            builder.Visit(year);
        }
Esempio n. 31
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     builder.Append("IIF(");
     builder.Visit(args[0]);
     builder.Append(" = ");
     builder.Visit(args[1]);
     builder.Append(", 0, IIF(");
     builder.Visit(args[0]);
     builder.Append(" < ");
     builder.Visit(args[1]);
     builder.Append(", -1, 1))");
 }
Esempio n. 32
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     builder.Append("IIF(");
     builder.Visit(args[0]);
     builder.Append(" = ");
     builder.Visit(args[1]);
     builder.Append(", 0, IIF(");
     builder.Visit(args[0]);
     builder.Append(" < ");
     builder.Visit(args[1]);
     builder.Append(", -1, 1))");
 }
Esempio n. 33
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     builder.Append("(CASE WHEN ");
     builder.Visit(args[0]);
     builder.Append(" = ");
     builder.Visit(args[1]);
     builder.Append(" THEN 0 WHEN ");
     builder.Visit(args[0]);
     builder.Append(" < ");
     builder.Visit(args[1]);
     builder.Append(" THEN -1 ELSE 1 END)");
 }
Esempio n. 34
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            var value = args[1];

            value = FormatValue(value);

            builder.Append("(");
            builder.Visit(args[0]);
            builder.Append(" LIKE ");
            builder.Visit(value);
            builder.Append(")");
        }
Esempio n. 35
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     builder.Append("(CASE WHEN ");
     builder.Visit(args[0]);
     builder.Append(" = ");
     builder.Visit(args[1]);
     builder.Append(" THEN 0 WHEN ");
     builder.Visit(args[0]);
     builder.Append(" < ");
     builder.Visit(args[1]);
     builder.Append(" THEN -1 ELSE 1 END)");
 }
Esempio n. 36
0
 public void Render(ISqlBuilder ctx, params Expression[] args)
 {
     ctx.Append("DATETIME(");
     ctx.Visit(args[0]);
     ctx.Append(",'");
     //ctx.Append((args[0] as ConstantExpression).Value);
     ExecuteContext.Items.Add(SQLiteDateTimeFunctions.IgonreIntDoubleConvert, null);
     ctx.Visit(args[1]);
     ExecuteContext.Items.Remove(SQLiteDateTimeFunctions.IgonreIntDoubleConvert);
     ctx.Append(" ");
     ctx.Append(type);
     ctx.Append("')");
 }
        public void Render(ISqlBuilder visitor, params Expression[] args)
        {
            if (args.Length != 2)
            {
                throw new ArgumentException(string.Format(Res.ArgumentCountError, "dateadd", "", "2"));
            }

            var addPart = (args[1] as ConstantExpression).Value;

            visitor.Append("(");
            visitor.Visit(args[0]);
            visitor.Append(" + interval '" + addPart.ToString() + "' " + Type.ToString() + ")");
        }
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            if (args == null)
            {
                throw new NotSupportedException("args");
            }
            //if (args.Length != 1)
            //    throw new NotSupportedException("'IsNullOrWhiteSpace' function takes  1 arguments");
            var isNot = args.Length == 2;

            if (isNot)
            {
                builder.Append("(");
                builder.Visit(args[0]);
                builder.Append(" IS NOT NULL OR ");
                builder.Visit(args[0]);
                builder.Append(" <> '' OR LTRIM(");
                builder.Visit(args[0]);
                builder.Append(") = '')");
            }
            else
            {
                builder.Append("(");
                builder.Visit(args[0]);
                builder.Append(" IS NULL OR ");
                builder.Visit(args[0]);
                builder.Append(" = '' OR LTRIM(");
                builder.Visit(args[0]);
                builder.Append(") = '')");
            }
        }
Esempio n. 39
0
        public void Render(ISqlBuilder visitor, params Expression[] args)
        {
            if (args.Length != 2)
                throw new ArgumentException("function ' dateadd takes 2 arguments.");

            visitor.Append("(");
            visitor.Visit(args[0]);
            visitor.Append(" + interval '");
            ExecuteContext.Items.Add(OracleDateTimeFunctions.IgonreIntDoubleConvert, null);
            visitor.Visit(args[1]);
            ExecuteContext.Items.Remove(OracleDateTimeFunctions.IgonreIntDoubleConvert);

            visitor.Append("' " + Type.ToString() + ")");
        }
Esempio n. 40
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            var value = args[1];
            value = FormatValue(value,
                (bool)(args[2] as ConstantExpression).Value
                , (bool)(args[3] as ConstantExpression).Value
                , (bool)(args[4] as ConstantExpression).Value);

            builder.Append("(");
            builder.Visit(args[0]);
            builder.Append(" LIKE ");
            builder.Visit(value);
            builder.Append(")");
        }
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     if (args == null)
         throw new NotSupportedException("args");
     if (args.Length != 1)
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "IsNullOrWhiteSpace", "", "1"));
     builder.Append("(");
     builder.Visit(args[0]);
     builder.Append(" IS NULL OR ");
     builder.Visit(args[0]);
     builder.Append(" = '' OR LTRIM(");
     builder.Visit(args[0]);
     builder.Append(") IS NULL)");
 }
Esempio n. 42
0
 public void Render(ISqlBuilder ctx, params Expression[] args)
 {
     if (args.Length != 3)
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "Insert", "", "3"));
     }
     var secondStartIndex = args[1];// Expression.Constant((int)(args[1] as ConstantExpression).Value + 1);
     ctx.Append("(CASE WHEN ");
     ctx.Visit(secondStartIndex);
     ctx.Append(" > LENGTH(");
     ctx.Visit(args[0]);
     ctx.Append(") THEN null ELSE (SUBSTR(");
     ctx.Visit(args[0]);
     ctx.Append(",1,");
     ctx.Visit(Expression.Subtract(Expression.Property(args[1], "Value"), Expression.Constant(1, Types.Int32)));
     ctx.Append(") || ");
     ctx.Visit(args[2]);
     ctx.Append(" || SUBSTR(");
     ctx.Visit(args[0]);
     ctx.AppendFormat(",");
     ctx.Visit(secondStartIndex);
     ctx.Append(",LENGTH(");
     ctx.Visit(args[0]);
     ctx.Append(")))END)");
 }
Esempio n. 43
0
 public void Render(ISqlBuilder ctx, params Expression[] args)
 {
     if (args == null)
     {
         throw new NotSupportedException("args");
     }
     if (args.Length != 2)
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "Right", "", "2"));
     }
     //rightstr(t0.descript,(CASE WHEN charindex('a',t0.descript) =0 THEN 0
     //else (length(t0.descript)- (charindex('a',t0.descript)+length('a'))+1) END))
     ctx.Append("RIGHTSTR(");
     ctx.Visit(args[0]);
     ctx.Append(",(CASE WHEN CHARINDEX(");
     ctx.Visit(args[1]);
     ctx.Append(",");
     ctx.Visit(args[0]);
     ctx.Append(") = 0 THEN 0 ELSE (LENGTH(");
     ctx.Visit(args[0]);
     ctx.Append(") - (CHARINDEX(");
     ctx.Visit(args[1]);
     ctx.Append(",");
     ctx.Visit(args[0]);
     ctx.Append(") + LENGTH(");
     ctx.Visit(args[1]);
     ctx.Append("))+1) END))");
 }
Esempio n. 44
0
            if (args.Length != 2)
            {
                throw new NotSupportedException(string.Format(Res.ArgumentCountError, "Left", "", "2"));
            }
            builder.Append("LEFT(");
            builder.Visit(args[0]);
            builder.Append(",(INSTR(");
            builder.Visit(args[0]);
            builder.Append(",");
            builder.Visit(args[1]);
            builder.Append(")-1))");
        }
    }
}
Esempio n. 45
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     if (args.Length != 2)
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "Left", "", "2"));
     }
     builder.Append("LEFT(");
     builder.Visit(args[0]);
     builder.Append(",(INSTR(");
     builder.Visit(args[0]);
     builder.Append(",");
     builder.Visit(args[1]);
     builder.Append(")-1))");
 }
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     if (args == null)
         throw new NotSupportedException("args");
     //if (args.Length != 1)
     //    throw new NotSupportedException("'IsNullOrWhiteSpace' function takes  1 arguments");
     var isNot = args.Length == 2;
     if (isNot)
     {
         builder.Append("(");
         builder.Visit(args[0]);
         builder.Append(" IS NOT NULL OR ");
         builder.Visit(args[0]);
         builder.Append(" <> '' OR LTRIM(");
         builder.Visit(args[0]);
         builder.Append(") = '')");
     }
     else
     {
         builder.Append("(");
         builder.Visit(args[0]);
         builder.Append(" IS NULL OR ");
         builder.Visit(args[0]);
         builder.Append(" = '' OR LTRIM(");
         builder.Visit(args[0]);
         builder.Append(") = '')");
     }
 }
Esempio n. 47
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     var flag = args.Length == 3 ? "" : "-";
     var value = (TimeSpan)(args[2] as ConstantExpression).Value;
     builder.Append("(");
     builder.Visit(args[1]);
     builder.AppendFormat(" + INTERVAL '{4}{0}' DAY + INTERVAL '{4}{1}' HOUR + INTERVAL '{4}{2}' MINUTE + INTERVAL '{4}{3}' SECOND"
                       , value.Days
                       , value.Hours
                       , value.Minutes
                       , value.Seconds
                       , flag);
     builder.Append(")");
 }
Esempio n. 48
0
        public void Render(ISqlBuilder ctx, params Expression[] args)
        {
            if (args.Length != 3)
            {
                throw new NotSupportedException(string.Format(Res.ArgumentCountError, "Insert", "", "3"));
            }
            var secondStartIndex = args[1];// Expression.Constant((int)(args[1] as ConstantExpression).Value + 1);

            ctx.Append("(CASE WHEN ");
            ctx.Visit(secondStartIndex);
            ctx.Append(" > LENGTH(");
            ctx.Visit(args[0]);
            ctx.Append(") THEN null ELSE (SUBSTR(");
            ctx.Visit(args[0]);
            ctx.Append(",1,");
            ctx.Visit(Expression.Subtract(Expression.Property(args[1], "Value"), Expression.Constant(1, Types.Int32)));
            ctx.Append(") || ");
            ctx.Visit(args[2]);
            ctx.Append(" || SUBSTR(");
            ctx.Visit(args[0]);
            ctx.AppendFormat(",");
            ctx.Visit(secondStartIndex);
            ctx.Append(",LENGTH(");
            ctx.Visit(args[0]);
            ctx.Append(")))END)");
        }
Esempio n. 49
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            if (args == null || (args.Length != 2 && args.Length != 3))
            {
                throw new NotSupportedException(string.Format(Res.ArgumentCountError, "substring", "", "2 or 3"));
            }
            builder.Append("CASE WHEN LENGTH(");
            builder.Visit(args[1]);
            builder.Append(") > LENGTH(");
            builder.Visit(args[0]);
            builder.Append(") THEN NULL ELSE SUBSTR(");
            builder.Visit(args[0]);
            builder.Append(",").Visit(args[1]);
            if (args.Length == 2)
            {
                builder.Append(",LENGTH(").Visit(args[0]);
                builder.Append(")");

            }
            else
            {
                builder.Append(",").Visit(args[2]);
            }
            builder.Append(") END");
        }
Esempio n. 50
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            if (args.Length != 2)
            {
                throw new NotSupportedException(string.Format(Res.ArgumentCountError, "Right()", "", " 2 "));
            }
            //Right(t0.descript,case when CHARINDEX('c',t0.descript) = 0 then 0 else
            //(LEN(t0.descript)- (CHARINDEX('c',t0.descript)+LEN('c'))+1) end)

            builder.Append("Right(");
            builder.Visit(args[0]);
            builder.Append(",IIF(InStr(");
            builder.Visit(args[0]);
            builder.Append(",");
            builder.Visit(args[1]);
            builder.Append(") = 0,0,(LEN(");
            builder.Visit(args[0]);
            builder.Append(") - (InStr(");
            builder.Visit(args[0]);
            builder.Append(",");
            builder.Visit(args[1]);
            builder.Append(")+LEN(");
            builder.Visit(args[1]);
            builder.Append("))+1)))");
        }
Esempio n. 51
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            if (args.Length != 2)
            {
                throw new NotSupportedException(string.Format(Res.ArgumentCountError, "Right()", "", " 2 "));
            }
            //Right(t0.descript,case when CHARINDEX('c',t0.descript) = 0 then 0 else
            //(LEN(t0.descript)- (CHARINDEX('c',t0.descript)+LEN('c'))+1) end)

            builder.Append("Right(");
            builder.Visit(args[0]);
            builder.Append(",IIF(InStr(");
            builder.Visit(args[0]);
            builder.Append(",");
            builder.Visit(args[1]);
            builder.Append(") = 0,0,(LEN(");
            builder.Visit(args[0]);
            builder.Append(") - (InStr(");
            builder.Visit(args[0]);
            builder.Append(",");
            builder.Visit(args[1]);
            builder.Append(")+LEN(");
            builder.Visit(args[1]);
            builder.Append("))+1)))");
        }
Esempio n. 52
0
        // 创建 DELETE 命令
        protected override DbCommandDefinition ParseDeleteCommand <T>(DbQueryableInfo_Delete <T> dQuery, List <IDbDataParameter> parameters = null)
        {
            TypeRuntimeInfo typeRuntime = TypeRuntimeInfoCache.GetRuntimeInfo <T>();
            ISqlBuilder     builder     = this.CreateSqlBuilder(parameters);
            bool            useKey      = false;

            builder.Append("DELETE FROM ");
            builder.AppendMember(typeRuntime.TableName, !typeRuntime.IsTemporary);
            builder.Append(" t0 ");

            if (dQuery.Entity != null)
            {
                object entity = dQuery.Entity;

                builder.AppendNewLine();
                builder.Append("WHERE ");

                foreach (var kv in typeRuntime.Invokers)
                {
                    MemberInvokerBase invoker = kv.Value;
                    var column = invoker.Column;

                    if (column != null && column.IsKey)
                    {
                        useKey = true;
                        var value = invoker.Invoke(entity);
                        var seg   = builder.GetSqlValue(value, column);
                        builder.AppendMember("t0", invoker.Member.Name);
                        builder.Append(" = ");
                        builder.Append(seg);
                        builder.Append(" AND ");
                    }
                    ;
                }
                builder.Length -= 5;

                if (!useKey)
                {
                    throw new XFrameworkException("Delete<T>(T value) require T must have key column.");
                }
            }
            else if (dQuery.SelectInfo != null)
            {
                TableAliasCache aliases = this.PrepareAlias <T>(dQuery.SelectInfo);
                var             cmd2    = new OracleDbCommandDefinition_Delete(this, aliases, builder.Parameters);
                cmd2.HaveListNavigation = dQuery.SelectInfo.HaveListNavigation;

                var visitor0 = new OracleJoinExpressionVisitor(this, aliases, dQuery.SelectInfo.Join, dQuery.SelectInfo.Where);
                visitor0.Write(cmd2);

                var visitor1 = new OracleWhereExpressionVisitor(this, aliases, dQuery.SelectInfo.Where);
                visitor1.Write(cmd2.WhereFragment);
                cmd2.AddNavMembers(visitor1.NavMembers);
                builder.Append(cmd2.CommandText);
            }

            builder.Append(';');
            return(new DbCommandDefinition(builder.ToString(), builder.Parameters, System.Data.CommandType.Text));
        }
Esempio n. 53
0
        public void Render(ISqlBuilder ctx, params Expression[] args)
        {
            if (args == null)
                throw new NotSupportedException("args");
            if (args.Length != 2)
                throw new NotSupportedException(string.Format(Res.ArgumentCountError, "left", "", "2"));

            ctx.Append("SUBSTR(");
            ctx.Visit(args[0]);
            ctx.Append(",1,(CHARINDEX(");
            ctx.Visit(args[1]);
            ctx.Append(",");
            ctx.Visit(args[0]);
            ctx.Append(")-1))");
        }
Esempio n. 54
0
        // Cross Join
        private void AppendCrossJoin(ISqlBuilder builder, DbExpression exp, TableAliasCache aliases)
        {
            LambdaExpression lambdaExp = exp.Expressions[1] as LambdaExpression;
            Type             type      = lambdaExp.Parameters[1].Type;
            var typeRuntime            = TypeRuntimeInfoCache.GetRuntimeInfo(type);

            builder.Append(' ');
            builder.AppendMember(typeRuntime.TableName, !typeRuntime.IsTemporary);

            string alias = aliases.GetTableAlias(lambdaExp.Parameters[1]);

            builder.Append(' ');
            builder.Append(alias);
            builder.Append(' ');
        }
        /// <summary>
        /// 访问表达式节点
        /// </summary>
        /// <param name="select">选择表达式</param>
        public override Expression Visit(DbExpression select)
        {
            base.Visit(select);
            if (_tree is IWithRowId)
            {
                if (_builder.Length == 0)
                {
                    _builder.Append(',');
                }
                _builder.AppendNewLine();
                _builder.Append("t0.RowId");
            }

            return(select != null && select.HasExpression ? select.Expressions[0] : null);
        }
Esempio n. 56
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     if (args == null || (args.Length != 2 && args.Length != 3))
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "indexof", "", "2 or 3"));
     }
     builder.Append("(INSTR(");
     builder.Visit(args[0]);
     builder.Append(",");
     builder.Visit(args[1]);
     if (args.Length == 3)
     {
         args[2] = Expression.Constant((int)(args[2] as ConstantExpression).Value + 1);
         builder.Append(",");
         builder.Visit(args[2]);
     }
     builder.Append(") - 1)");
 }
Esempio n. 57
0
 public virtual void Render(ISqlBuilder visitor, params Expression[] args)
 {
     if (args.Length != 2 && args.Length != 3)
     {
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "left", "", "2 or 3"));
     }
     visitor.Append("(CHARINDEX(");
     visitor.Visit(args[1]);
     visitor.Append(", ");
     visitor.Visit(args[0]);
     if (args.Length == 3)
     {
         // args[2] = Expression.Constant((int)(args[2] as ConstantExpression).Value + 1);
         visitor.Append(", ");
         visitor.Visit(args[2]);
     }
     visitor.Append(") - 1)");
 }
Esempio n. 58
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     if (args == null)
         throw new NotSupportedException("args");
     if (args.Length != 2 && args.Length != 3)
         throw new NotSupportedException(string.Format(Res.ArgumentCountError, "PadRight", "", "2 or 3"));
     builder.Append("RPAD(");
     builder.Visit(args[0]);
     builder.Append(",");
     builder.Visit(args[1]);
     builder.Append(",");
     if (args.Length == 2)
         builder.Append("' ')");
     else
     {
         builder.Visit(args[2]);
         builder.Append(")");
     }
 }
Esempio n. 59
0
        public void Render(ISqlBuilder builder, params Expression[] args)
        {
            //INSTR(descript, 'zhao') = 1
            //instr(1,descript,'zhao')
            if (args == null || (args.Length != 2 && args.Length != 3))
            {
                throw new NotSupportedException(string.Format(Res.ArgumentCountError, "indexof()", "", " 2 or 3 "));
            }
            builder.Append("((INSTR(");
            if (args.Length == 2)
                builder.Visit(args[0]);
            else
            {

                builder.Visit(args[2]);
                builder.Append(",");
                builder.Visit(args[0]);
            }
            builder.Append(",");
            builder.Visit(args[1]);
            builder.Append(")) - 1)");
        }
Esempio n. 60
0
 public void Render(ISqlBuilder builder, params Expression[] args)
 {
     var flag = args.Length == 3 ? "" : "-";
     var value = (TimeSpan)(args[2] as ConstantExpression).Value;
     builder.AppendFormat("DATEADD('d',{4}{0},DATEADD('h',{4}{1},DATEADD('n',{4}{2},DATEADD('s',{4}{3},"
                       , value.Days
                       , value.Hours
                       , value.Minutes
                       , value.Seconds
                       , flag);
     builder.Visit(args[1]);
     builder.Append("))))");
 }