Exemplo n.º 1
0
        public void TestCondition()
        {
            SqlMaker <Relation2>     package   = new SqlMaker <Relation2>();
            SqlCondition <Relation2> condition = new SqlCondition <Relation2>();

            Assert.Equal("[StudentId] > @StudentId", (condition > "StudentId").ToString());
        }
Exemplo n.º 2
0
        public void TestCondition2()
        {
            SqlMaker <Relation2>     package   = new SqlMaker <Relation2>();
            SqlCondition <Relation2> condition = new SqlCondition <Relation2>();

            Assert.Equal("([StudentId] > @StudentId OR [ClassId] <> @ClassId)", (condition > "StudentId" | condition != "ClassId").ToString());
        }
Exemplo n.º 3
0
        bool CompareConditions(SqlCondition cond1, SqlCondition cond2)
        {
            if (cond1.ElementType != cond2.ElementType)
            {
                return(false);
            }

            if (cond1.Predicate.ElementType != cond2.Predicate.ElementType)
            {
                return(false);
            }

            switch (cond1.Predicate.ElementType)
            {
            case QueryElementType.IsNullPredicate:
            {
                var isNull1 = (SqlPredicate.IsNull)cond1.Predicate;
                var isNull2 = (SqlPredicate.IsNull)cond2.Predicate;

                return(isNull1.IsNot == isNull2.IsNot && CompareExpressions(isNull1.Expr1, isNull2.Expr1) == true);
            }

            case QueryElementType.ExprExprPredicate:
            {
                var expr1 = (SqlPredicate.ExprExpr)cond1.Predicate;
                var expr2 = (SqlPredicate.ExprExpr)cond2.Predicate;

                return(CompareExpressions(expr1, expr2));
            }
            }
            return(false);
        }
Exemplo n.º 4
0
 internal SqlConditionRelation(SqlCondition cond1,
                               SqlCondition cond2, SqlLogicOper logicOper)
 {
     _cond1     = cond1;
     _cond2     = cond2;
     _logicOper = logicOper;
 }
Exemplo n.º 5
0
        public void Test_3()
        {
            var condition2 = new SqlCondition("Age>@Age");
            var condition  = new OrCondition(null, condition2);

            Assert.Equal("Age>@Age", condition.GetCondition());
        }
Exemplo n.º 6
0
        public void TestLikeCondition2()
        {
            SqlMaker <Relation2>     package   = new SqlMaker <Relation2>();
            SqlCondition <Relation2> condition = new SqlCondition <Relation2>();

            Assert.Equal("(([StudentId] LIKE @StudentId AND [StudentId] > @StudentId) AND [StudentId] LIKE @StudentId)", ("StudentId" % condition & condition > "StudentId" & condition % "StudentId").ToString());
        }
Exemplo n.º 7
0
        public void Test_4()
        {
            var condition1 = new SqlCondition("Name=@Name");
            var condition  = new OrCondition(condition1, null);

            Assert.Equal("Name=@Name", condition.GetCondition());
        }
Exemplo n.º 8
0
 public override string ToString()
 {
     if (SqlCondition.HasValue())
     {
         return(SqlCondition);
     }
     return($"({Left}-{Operator}-{Right})");
 }
Exemplo n.º 9
0
        public void TestUnionCondition3()
        {
            SqlMaker <Student>     package   = new SqlMaker <Student>();
            SqlCondition <Student> condition = new SqlCondition <Student>();
            var result = SqlCollection <Student> .TableIntersect(SqlEntity <Student> .SelectAllWhere + (condition > "Sid").Full, "table1", "table2", "table3");

            Assert.Equal("(SELECT * FROM `table1` WHERE `Sid` > @Sid) INTERSECT (SELECT * FROM `table2` WHERE `Sid` > @Sid) INTERSECT (SELECT * FROM `table3` WHERE `Sid` > @Sid)", result);
        }
Exemplo n.º 10
0
        public void TestUnionCondition2()
        {
            SqlMaker <Student>     package   = new SqlMaker <Student>();
            SqlCondition <Student> condition = new SqlCondition <Student>();
            var result = SqlCollection <Student> .Union(SqlEntity <Student> .SelectAllWhere + (condition > "Sid").Full);

            Assert.Equal("(SELECT * FROM `1` WHERE `Sid` > @Sid)", result);
        }
Exemplo n.º 11
0
        public void TestUnionCondition2()
        {
            SqlPackage <Student>   package   = new SqlPackage <Student>();
            SqlCondition <Student> condition = new SqlCondition <Student>();
            var result = SqlUnion <Student> .Union(Sql <Student> .SelectAllByCondition + (condition > "Sid").Full);

            Assert.Equal("SELECT * FROM `1` WHERE Sid > @Sid", result);
        }
Exemplo n.º 12
0
        public void TestUnionCondition1()
        {
            SqlPackage <Student>   package   = new SqlPackage <Student>();
            SqlCondition <Student> condition = new SqlCondition <Student>();
            var result = SqlUnion <Student> .Union(Sql <Student> .SelectAllByCondition + (condition > "Sid").Full, "table1", "table2", "table3");

            Assert.Equal("SELECT * FROM `table1` WHERE Sid > @Sid UNION SELECT * FROM `table2` WHERE Sid > @Sid UNION SELECT * FROM `table3` WHERE Sid > @Sid", result);
        }
Exemplo n.º 13
0
        public void Test_2()
        {
            var condition1 = new SqlCondition("Name=@Name");
            var condition2 = new SqlCondition("Age=@Age");
            var condition  = new OrCondition(condition1, condition2);

            Assert.Equal("(Name=@Name Or Age=@Age)", condition.GetCondition());
        }
Exemplo n.º 14
0
        public void Test_2()
        {
            var condition1 = new SqlCondition("Name=@Name");
            var condition2 = new SqlCondition("Age>@Age");
            var condition  = new AndCondition(condition1, condition2);

            Assert.Equal("Name=@Name And Age>@Age", condition.GetCondition());
        }
Exemplo n.º 15
0
 /// <summary>
 /// 过滤条件
 /// </summary>
 /// <param name="name">列名</param>
 /// <param name="value">值</param>
 /// <param name="operator">运算符</param>
 public ISqlBuilder Filter(string name, object value, Operator @operator = Operator.Equal)
 {
     if (!IsValid(name, value))
     {
         return(this);
     }
     And(SqlCondition.Create(name, GetParamPrefix(), @operator));
     AddParam(name, value, @operator);
     return(this);
 }
Exemplo n.º 16
0
        /// <summary>
        /// 添加In过滤条件
        /// </summary>
        private void AddIn(StringBuilder result, string name, object value, int index)
        {
            if (!IsValid(name, value))
            {
                return;
            }
            var paramName = SqlCondition.GetParamName(string.Format("{0}{1}", name, index));

            result.AppendFormat("{0}{1},", GetParamPrefix(), paramName);
            _params.Add(paramName, value);
        }
Exemplo n.º 17
0
        public static SqlCP Condition(this object instance, SqlCondition condition)
        {
            SqlCP cp = new SqlCP();

            cp.Instance = instance;
            cp.Query    = condition.Query;
            cp.Tails    = condition.Tails;
            cp.Order    = condition.Order;
            condition.Claer();
            return(cp);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Returns a string that represents this instance.
        /// </summary>
        public override string ToString()
        {
            if (SqlCondition.HasValue())
            {
                return(SqlCondition);
            }

            var valueText = Value == null ? NULL_ESCAPE : GetSerializedValue().Replace(":", COLON_ESCAPE);

            return(string.Join(":", PropertyName, FilterFunction, valueText));
        }
Exemplo n.º 19
0
 public string this[SqlCondition index]
 {
     get
     {
         return(mConditionMapping[index]);
     }
     set
     {
         mConditionMapping[index] = value;
     }
 }
Exemplo n.º 20
0
            public override ISqlExpression GetSubQuery(IBuildContext context)
            {
                if (_subQuerySql == null)
                {
                    var cond = new SqlCondition(
                        _methodCall.Method.Name == "All",
                        new SqlPredicate.FuncLike(SqlFunction.CreateExists(SelectQuery)));

                    _subQuerySql = new SqlSearchCondition(cond);
                }

                return(_subQuerySql);
            }
Exemplo n.º 21
0
        public DbExpression(DbColumn column, DbSelectStatement select_clause, SqlCondition condition)
        {
            mColumn     = column;
            mFieldvalue = select_clause;
            mCondition  = condition;

            this[SqlCondition.IsEqual]        = "=";
            this[SqlCondition.IsLessEqual]    = "<=";
            this[SqlCondition.IsGreaterEqual] = ">=";
            this[SqlCondition.IsLess]         = "<";
            this[SqlCondition.IsGreater]      = ">";
            this[SqlCondition.Like]           = "LIKE";
        }
Exemplo n.º 22
0
        public DbExpression(DbColumn column, DbFieldEntry fieldvalue, SqlCondition condition)
        {
            mColumn     = column;
            mFieldvalue = fieldvalue;
            mCondition  = condition;

            this[SqlCondition.IsEqual]        = "=";
            this[SqlCondition.IsLessEqual]    = "<=";
            this[SqlCondition.IsGreaterEqual] = ">=";
            this[SqlCondition.IsLess]         = "<";
            this[SqlCondition.IsGreater]      = ">";
            this[SqlCondition.Like]           = "LIKE";
        }
Exemplo n.º 23
0
        public void TestCondition3()
        {
            SqlPackage <Relation2>   package = new SqlPackage <Relation2>();
            SqlCondition <Relation2> c       = new SqlCondition <Relation2>();

            Assert.Equal(

                "((StudentId > @StudentId OR ClassId = @ClassId) AND ClassName <> @ClassName)",

                ((c > "StudentId" | c == "ClassId") & c != "ClassName").ToString()

                );
        }
Exemplo n.º 24
0
        public void TestCondition3()
        {
            SqlMaker <Relation2>     package = new SqlMaker <Relation2>();
            SqlCondition <Relation2> c       = new SqlCondition <Relation2>();

            Assert.Equal(

                "(([StudentId] > @StudentId OR [ClassId] = @ClassId) AND [ClassName] <> @ClassName)",

                ((c > "StudentId" | c == "ClassId") & c != "ClassName").ToString()

                );
        }
Exemplo n.º 25
0
 /// <summary>
 /// 使用Or连接条件
 /// </summary>
 /// <param name="condition">过滤条件</param>
 public ISqlBuilder Or(string condition)
 {
     if (condition.IsEmpty())
     {
         return(this);
     }
     if (_condition == null)
     {
         _condition = SqlCondition.Create(condition);
         return(this);
     }
     _condition = new OrCondition(_condition.GetCondition(), condition);
     return(this);
 }
Exemplo n.º 26
0
        public void TestPageCondition3()
        {
            SqlPackage <Relation2>   package = new SqlPackage <Relation2>();
            SqlCondition <Relation2> c       = new SqlCondition <Relation2>();

            Assert.Equal(

                "((StudentId > @StudentId OR ClassId = @ClassId) AND ClassName <> @ClassName) ORDER BY StudentId ASC,ClassId DESC",
                //升序-----------降序-----排序链接-----------------条件----------------------------
                //↓             ↓          ↓
                (c + "StudentId" - "ClassId" ^ (c > "StudentId" | c == "ClassId") & c != "ClassName").ToString()

                );
        }
Exemplo n.º 27
0
        public void TestPageCondition3()
        {
            SqlMaker <Relation2>     package = new SqlMaker <Relation2>();
            SqlCondition <Relation2> c       = new SqlCondition <Relation2>();

            Assert.Equal(

                "(([StudentId] > @StudentId OR [ClassId] = @ClassId) AND [ClassName] <> @ClassName) ORDER BY [StudentId] ASC,[ClassId] DESC",
                //升序-----------降序-----排序链接-----------------条件----------------------------
                //↓             ↓          ↓
                (c + "StudentId" - "ClassId" ^ (c > "StudentId" | c == "ClassId") & c != "ClassName").ToString()

                );
        }
Exemplo n.º 28
0
            public override ISqlExpression GetSubQuery(IBuildContext?context)
            {
                if (_subQuerySql == null)
                {
                    var cond = new SqlCondition(
                        _methodCall.Method.Name.StartsWith("All"),
                        new SqlPredicate.FuncLike(SqlFunction.CreateExists(SelectQuery)));

                    Sequence.CompleteColumns();

                    _subQuerySql = new SqlSearchCondition(cond);
                }

                return(_subQuerySql);
            }
Exemplo n.º 29
0
        public void TestOrderCondition2()
        {
            SqlPackage <Relation2>   package = new SqlPackage <Relation2>();
            SqlCondition <Relation2> c       = new SqlCondition <Relation2>();

            Assert.Equal(

                "((StudentId > @StudentId OR ClassId = @ClassId) AND ClassName <> @ClassName) ORDER BY StudentId ASC",

                //----------------------------条件----------------排序链接--升序------------
                //                                                    ↓   ↓
                ((c > "StudentId" | c == "ClassId") & c != "ClassName" ^ c + "StudentId").ToString()

                );
        }
Exemplo n.º 30
0
    private void Clear(SqlCondition condition)
    {
        if (_condList.Contains(condition))
        {
            _condList.Remove(condition);
        }

        if (condition.GetType() == typeof(SqlConditionRelation))
        {
            SqlConditionRelation richCond =

                (SqlConditionRelation)condition;
            this.Clear(richCond._cond1);
            this.Clear(richCond._cond2);
        }
    }