Esempio n. 1
0
        protected override void BuildLikePredicate(SelectQuery.Predicate.Like predicate)
        {
            if (predicate.Expr2 is SqlValue)
            {
                var value = ((SqlValue)predicate.Expr2).Value;

                if (value != null)
                {
                    var text  = ((SqlValue)predicate.Expr2).Value.ToString();
                    var ntext = text.Replace("[", "[[]");

                    if (text != ntext)
                    {
                        predicate = new SelectQuery.Predicate.Like(predicate.Expr1, predicate.IsNot, new SqlValue(ntext), predicate.Escape);
                    }
                }
            }
            else if (predicate.Expr2 is SqlParameter)
            {
                var p = ((SqlParameter)predicate.Expr2);
                p.ReplaceLike = true;
            }

            if (predicate.Escape != null)
            {
                if (predicate.Expr2 is SqlValue && predicate.Escape is SqlValue)
                {
                    var value = ((SqlValue)predicate.Expr2).Value;

                    if (value != null)
                    {
                        var text = ((SqlValue)predicate.Expr2).Value.ToString();
                        var val  = new SqlValue(ReescapeLikeText(text, (char)((SqlValue)predicate.Escape).Value));

                        predicate = new SelectQuery.Predicate.Like(predicate.Expr1, predicate.IsNot, val, null);
                    }
                }
                else if (predicate.Expr2 is SqlParameter)
                {
                    var p = (SqlParameter)predicate.Expr2;

                    if (p.LikeStart != null)
                    {
                        var value = (string)p.Value;

                        if (value != null)
                        {
                            value = value.Replace("[", "[[]").Replace("~%", "[%]").Replace("~_", "[_]").Replace("~~", "[~]");
                            p     = new SqlParameter(p.SystemType, p.Name, value)
                            {
                                DbSize = p.DbSize, DataType = p.DataType, IsQueryParameter = p.IsQueryParameter
                            };
                            predicate = new SelectQuery.Predicate.Like(predicate.Expr1, predicate.IsNot, p, null);
                        }
                    }
                }
            }

            base.BuildLikePredicate(predicate);
        }
        protected override void BuildLikePredicate(SelectQuery.Predicate.Like predicate)
        {
            if (predicate.Expr2 is SqlValue)
            {
                var value = ((SqlValue)predicate.Expr2).Value;

                if (value != null)
                {
                    var text  = ((SqlValue)predicate.Expr2).Value.ToString();
                    var ntext = text.Replace("[", "[[]");

                    if (text != ntext)
                    {
                        predicate = new SelectQuery.Predicate.Like(predicate.Expr1, predicate.IsNot, new SqlValue(ntext), predicate.Escape);
                    }
                }
            }
            else if (predicate.Expr2 is SqlParameter)
            {
                var p = ((SqlParameter)predicate.Expr2);
                p.ReplaceLike = true;
            }

            base.BuildLikePredicate(predicate);
        }
Esempio n. 3
0
        protected override void BuildLikePredicate(SelectQuery.Predicate.Like predicate)
        {
            if (predicate.IsNot)
            {
                StringBuilder.Append("NOT ");
            }

            var precedence = GetPrecedence(predicate);

            BuildExpression(precedence, predicate.Expr1);
            StringBuilder.Append(" LIKE ");
            BuildExpression(precedence, predicate.Expr2);

            if (predicate.Escape != null)
            {
                StringBuilder.Append(" ESCAPE ");
                BuildExpression(precedence, predicate.Escape);
            }
        }
        protected override void BuildPredicate(ISqlPredicate predicate)
        {
            var newpredicate = predicate;

            if (predicate is SelectQuery.Predicate.Like)
            {
                var p = (SelectQuery.Predicate.Like)predicate;

                var param2 = GetParm(p.Expr2 as IValueContainer, p.Expr1.SystemType);
                if (param2 != null)
                {
                    if (param2 is SqlValue && ((SqlValue)param2).Value == null)
                    {
                        if (p.IsNot)
                        {
                            newpredicate = new SelectQuery.Predicate.ExprExpr(p.Expr1, SelectQuery.Predicate.Operator.NotEqual, p.Expr2);
                        }
                        else
                        {
                            newpredicate = new SelectQuery.Predicate.ExprExpr(p.Expr1, SelectQuery.Predicate.Operator.Equal, p.Expr2);
                        }
                    }
                    else
                    {
                        newpredicate = new SelectQuery.Predicate.Like(p.Expr1, p.IsNot, param2, p.Escape);
                    }
                }
            }
            if (predicate is SelectQuery.Predicate.ExprExpr)
            {
                var p = (SelectQuery.Predicate.ExprExpr)predicate;
                if (p.Expr1 is SqlFunction && ((SqlFunction)p.Expr1).Name == "Date")
                {
                    if (p.Expr2 != null && p.Expr2 is SqlParameter)
                    {
                        var p2 = ((SqlParameter)p.Expr2);
                        p2.DataType = DataType.Date;
                    }
                }
            }

            base.BuildPredicate(newpredicate);
        }
Esempio n. 5
0
        protected override void BuildLikePredicate(SelectQuery.Predicate.Like predicate)
        {
            if (predicate.Escape != null)
            {
                if (predicate.Expr2 is SqlValue && predicate.Escape is SqlValue)
                {
                    var text = ((SqlValue)predicate.Expr2).Value.ToString();
                    var val  = new SqlValue(ReescapeLikeText(text, (char)((SqlValue)predicate.Escape).Value));

                    predicate = new SelectQuery.Predicate.Like(predicate.Expr1, predicate.IsNot, val, null);
                }
                else if (predicate.Expr2 is SqlParameter)
                {
                    var p = (SqlParameter)predicate.Expr2;

                    if (p.LikeStart != null)
                    {
                        var value = (string)p.Value;

                        if (value != null)
                        {
                            value     = value.Replace("[", "[[]").Replace("~%", "[%]").Replace("~_", "[_]").Replace("~~", "[~]");
                            p         = new SqlParameter(p.SystemType, p.Name, value) { DbSize = p.DbSize, DataType = p.DataType, IsQueryParameter = p.IsQueryParameter };
                            predicate = new SelectQuery.Predicate.Like(predicate.Expr1, predicate.IsNot, p, null);
                        }
                    }
                }
            }

            base.BuildLikePredicate(predicate);
        }
Esempio n. 6
0
		protected override void BuildLikePredicate(SelectQuery.Predicate.Like predicate)
		{
			if (predicate.Expr2 is SqlValue)
			{
				var value = ((SqlValue)predicate.Expr2).Value;

				if (value != null)
				{
					var text  = ((SqlValue)predicate.Expr2).Value.ToString();
					var ntext = text.Replace("[", "[[]");

					if (text != ntext)
						predicate = new SelectQuery.Predicate.Like(predicate.Expr1, predicate.IsNot, new SqlValue(ntext), predicate.Escape);
				}
			}
			else if (predicate.Expr2 is SqlParameter)
			{
				var p = ((SqlParameter)predicate.Expr2);
				p.ReplaceLike = true;
			}

			base.BuildLikePredicate(predicate);
		}