Beispiel #1
0
        private void Equals_2()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.Equals(it.Name, it.Name);
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, " (`Name` = `Name`) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "a")
            }, "Equals1 error");


            Expression <Func <Student, bool> > exp2        = it => SqlFunc.Equals("a", "a2");
            MySqlExpressionContext             expContext2 = new MySqlExpressionContext();

            expContext2.Resolve(exp2, ResolveExpressType.WhereSingle);
            var value2 = expContext2.Result.GetString();
            var pars2  = expContext2.Parameters;

            base.Check(value2, pars2, " (@MethodConst0 = @MethodConst1) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "a"), new SugarParameter("@MethodConst1", "a2")
            }, "Equals2 error");
        }
Beispiel #2
0
        private void ContainsArray()
        {
            string[] array = new string[] { "1", "2" };
            Expression <Func <Student, bool> > exp        = it => SqlFunc.ContainsArray(array, it.Name);
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, null, "  (`Name` IN ('1','2')) ", null, "Contains2 error");
        }
Beispiel #3
0
        private void HasNumber()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.HasNumber(it.Id);
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "( `Id`>0 AND `Id` IS NOT NULL )", new List <SugarParameter>()
            {
            }, "HasNumber error");
        }
Beispiel #4
0
        private void whereSingle14()
        {
            Expression <Func <Student, bool> > exp = it => true && it.Name != null;
            ExpressionContext expContext           = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(( 1 = 1 ) AND( `Name` IS NOT NULL ))", new List <SugarParameter>()
            {
            }, "whereSingle14");
        }
Beispiel #5
0
        private void whereSingle11()
        {
            Expression <Func <Student, bool> > exp = it => !true;
            ExpressionContext expContext           = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "( 1 = 2 )", new List <SugarParameter>()
            {
            }, "whereSingle11");
        }
Beispiel #6
0
        private void Length()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.Length("aaaa") > 1;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(LENGTH(@MethodConst0) > @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "aaaa"), new SugarParameter("@Const1", 1)
            }, "Length error");
        }
Beispiel #7
0
        private void whereSingle1()
        {
            Expression <Func <Student, bool> > exp = it => it.Id > 1;
            ExpressionContext expContext           = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "( `Id` > @Id0 )", new List <SugarParameter>()
            {
                new SugarParameter("@Id0", 1)
            }, "whereSingle1");
        }
Beispiel #8
0
        private void whereSingle12()
        {
            Expression <Func <DataTestInfo2, bool> > exp = it => it.Bool1 == true;
            ExpressionContext expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "( `Bool1` = @Bool10 )", new List <SugarParameter>()
            {
                new SugarParameter("@Bool10", true)
            }, "whereSingle12");
        }
Beispiel #9
0
        private void Between()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.Between(it.Name, 1, 2);
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, " (`Name` BETWEEN @MethodConst0 AND @MethodConst1) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", 1), new SugarParameter("@MethodConst1", 2),
            }, "Between error");
        }
Beispiel #10
0
        private void ConvetToString()
        {
            Expression <Func <Student, bool> > exp        = it => Convert.ToString(it.Id) == "a";
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(CAST(`Id` AS CHAR) = @Const0 )", new List <SugarParameter>()
            {
                new SugarParameter("@Const0", "a")
            }, "ConvetToString error");
        }
Beispiel #11
0
        private void StringIsNullOrEmpty()
        {
            Expression <Func <Student, bool> > exp        = it => it.Id > 2 || SqlFunc.IsNullOrEmpty(it.Id);;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(( `Id` > @Id0 ) OR ( `Id`='' OR `Id` IS NULL ))", new List <SugarParameter>()
            {
                new SugarParameter("@Id0", 2)
            }, "StringIsNullOrEmpty error");
        }
Beispiel #12
0
        private void Trim()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.Trim("  a") == it.Name;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "((rtrim(ltrim(@MethodConst0))) = `Name` )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "  a")
            }, "Trim error");
        }
Beispiel #13
0
        private void ToLower()
        {
            Expression <Func <Student, bool> > exp        = it => "a" == SqlFunc.ToLower(it.Id);
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "( @Const0 = (LOWER(`Id`)) )", new List <SugarParameter>()
            {
                new SugarParameter("@Const0", "a")
            }, "ToLower error");
        }
Beispiel #14
0
        private void Contains2(string name = "a")
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.Contains(it.Name, name);
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, " (`Name` like concat('%',@MethodConst0,'%')) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "a")
            }, "Contains2 error");
        }
Beispiel #15
0
        private void whereSingle9(Student st)
        {
            Expression <Func <Student, bool> > exp = it => it.Name == st.Name;
            ExpressionContext expContext           = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "( `Name` = @Name0 )", new List <SugarParameter>()
            {
                new SugarParameter("@Name0", null)
            }, "whereSingle9");
        }
Beispiel #16
0
        private void StringIsNullOrEmpty5()
        {
            WhereConst.name = "xx";
            Expression <Func <Student, bool> > exp        = it => !SqlFunc.IsNullOrEmpty(WhereConst.name);;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "NOT( @MethodConst0='' OR @MethodConst0 IS NULL )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "xx")
            }, "StringIsNullOrEmpty5 error");
        }
Beispiel #17
0
        private void StringIsNullOrEmpty2()
        {
            Expression <Func <Student, bool> > exp        = it => 2 == it.Id || SqlFunc.IsNullOrEmpty(true);;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(( @Id0 = `Id` ) OR ( @MethodConst1='' OR @MethodConst1 IS NULL ))", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst1", true),
                new SugarParameter("@Id0", 2)
            }, "StringIsNullOrEmpty2 error");
        }
Beispiel #18
0
        private void ToGuid()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => SqlFunc.ToGuid("A94027A3-476E-478D-8228-F4054394B874") == x2;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(CAST(@MethodConst0 AS CHAR) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "A94027A3-476E-478D-8228-F4054394B874"), new SugarParameter("@Const1", x2)
            }, "ToGuid error");
        }
Beispiel #19
0
        private void ToBool()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => SqlFunc.ToBool("true") == true;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(CAST(@MethodConst0 AS SIGNED) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "true"), new SugarParameter("@Const1", (bool)true)
            }, "ToBool error");
        }
Beispiel #20
0
        private void DateIsSameByDay()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateIsSame(x2, x2);
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, " (TIMESTAMPDIFF(day,date(@MethodConst0),date(@MethodConst1))=0) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", x2), new SugarParameter("@MethodConst1", x2)
            }, "DateIsSameDay error");
        }
Beispiel #21
0
        private void DateAddDay()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateAdd(x2, 1) == x2;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "((DATE_ADD(@MethodConst1 INTERVAL @MethodConst0 day)) = @Const2 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", x2), new SugarParameter("@MethodConst1", 1), new SugarParameter("@Const2", x2)
            }, "DateIsSameByType error");
        }
Beispiel #22
0
        private void DateValue()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.DateValue(x2, DateType.Year) == 1;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, " (Year(@MethodConst0) = @Const2 ) ", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", x2), new SugarParameter("@Const2", 1)
            }, "DateValue error");
        }
Beispiel #23
0
        private void ToInt32()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => SqlFunc.ToInt32("3") == 1;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(CAST(@MethodConst0 AS SIGNED) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "3"), new SugarParameter("@Const1", 1)
            }, "ToInt32 error");
        }
Beispiel #24
0
        private void ExtendDate()
        {
            var x2 = DateTime.Now;
            Expression <Func <Student, bool> > exp        = it => Convert.ToDateTime("2015-1-1") == x2;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(CAST(@MethodConst0 AS DATETIME) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "2015-1-1"), new SugarParameter("@Const1", x2)
            }, "ExtendDate error");
        }
Beispiel #25
0
        private void Replace()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => SqlFunc.Replace("aaaa", "a", "1") == "a";
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(REPLACE(@MethodConst0,@MethodConst1,@MethodConst2) = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "aaaa"), new SugarParameter("@MethodConst1", "a"), new SugarParameter("@MethodConst2", "1"), new SugarParameter("@Const3", "a")
            }, "Replace error");
        }
Beispiel #26
0
        private void ExtendSubstring()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => "aaaa".Substring(0, 2) == "a";
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(SUBSTRING(@MethodConst0,1 + @MethodConst1,@MethodConst2) = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "aaaa"), new SugarParameter("@MethodConst1", 0), new SugarParameter("@MethodConst2", 2), new SugarParameter("@Const3", "a")
            }, "Substring error");
        }
Beispiel #27
0
        private void ToDouble()
        {
            var x2 = Guid.NewGuid();
            Expression <Func <Student, bool> > exp        = it => SqlFunc.ToDouble("2") == 2;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(CAST(@MethodConst0 AS DECIMAL(18,4)) = @Const1 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "2"), new SugarParameter("@Const1", (Double)2)
            }, "ToDouble error");
        }
Beispiel #28
0
        private void whereSingle4()
        {
            Expression <Func <Student, bool> > exp = it => (it.Id > 1 && it.Name != "a") || it.Name == "a1";
            ExpressionContext expContext           = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, " ((( `Id` > @Id0 ) AND ( `Name` <> @Name1 )) OR ( `Name` = @Name2 ))  ", new List <SugarParameter>()
            {
                new SugarParameter("@Id0", 1),
                new SugarParameter("@Name1", "a"),
                new SugarParameter("@Name2", "a1")
            }, "whereSingle4");
        }
Beispiel #29
0
        private void IIF2()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.IIF(SqlFunc.Contains(it.Name, "a"), 1, 2) == 1;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(( CASE  WHEN  (`Name` like concat('%',@MethodConst0,'%'))  THEN @MethodConst1  ELSE @MethodConst2 END ) = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@MethodConst0", "a"),
                new SugarParameter("@MethodConst1", 1),
                new SugarParameter("@MethodConst2", 2),
                new SugarParameter("@Const3", 1)
            }, "IIF2 error");
        }
Beispiel #30
0
        private void IIF()
        {
            Expression <Func <Student, bool> > exp        = it => SqlFunc.IIF(it.Id == 1, 1, 2) == 1;
            MySqlExpressionContext             expContext = new MySqlExpressionContext();

            expContext.Resolve(exp, ResolveExpressType.WhereSingle);
            var value = expContext.Result.GetString();
            var pars  = expContext.Parameters;

            base.Check(value, pars, "(( CASE  WHEN ( `Id` = @Id0 ) THEN @MethodConst1  ELSE @MethodConst2 END ) = @Const3 )", new List <SugarParameter>()
            {
                new SugarParameter("@Id0", 1),
                new SugarParameter("@MethodConst1", 1),
                new SugarParameter("@MethodConst2", 2),
                new SugarParameter("@Const3", 1)
            }, "IIF error");
        }