コード例 #1
0
        public void Select()
        {
            statement = TestSchema.Select((sql, s) => sql.Get(s.All()));
            Assert.AreEqual("SELECT test.oid,test.oname,test.age,test.gender,test.isdel FROM test", statement.ToString());

            statement = TestSchema.Select((sql, s) => sql.Get(s.oid).Where(s.oid > 1));
            Assert.AreEqual("SELECT test.oid FROM test WHERE test.oid>1", statement.ToString());

            statement = TestSchema.Select((sql, s) => sql.Get(s.age).OrderBy(s.age.Desc()));
            Assert.AreEqual("SELECT test.age FROM test ORDER BY test.age DESC", statement.ToString());

            statement = TestSchema.Select((sql, s) => sql.Get(s.gender, s.age.Avg()).GroupBy(s.gender).Having(s.age.Avg() < 40));
            Assert.AreEqual("SELECT test.gender,AVG(test.age) FROM test GROUP BY test.gender HAVING AVG(test.age)<40", statement.ToString());

            statement = TestSchema.Select((sql, s) => sql.Get(s.All()).Where(s.oid > 1).OrderBy(s.age.Desc()));
            Assert.AreEqual("SELECT test.oid,test.oname,test.age,test.gender,test.isdel FROM test WHERE test.oid>1 ORDER BY test.age DESC", statement.ToString());

            statement = TestSchema.Select((sql, s) => sql.Get(s.age.Avg()).Where(s.oid > 1).GroupBy(s.gender).Having(s.age.Avg() > 18).OrderBy(s.age.Desc()));
            Assert.AreEqual("SELECT AVG(test.age) FROM test WHERE test.oid>1 GROUP BY test.gender HAVING AVG(test.age)>18 ORDER BY test.age DESC", statement.ToString());

            statement = TestSchema.Table.Select(TestSchema.Instance.oid);
            Assert.AreEqual("SELECT test.oid FROM test", statement.ToString());

            statement = TestSchema.Table.SelectVarCustomer("test.oid");
            Assert.AreEqual("SELECT test.oid FROM test", statement.ToString());

            statement = TestSchema.Table.Select().Get(TestSchema.Instance.oid);
            Assert.AreEqual("SELECT test.oid FROM test", statement.ToString());

            statement = TestSchema.Table.Select().GetVarCustomer("test.oid");
            Assert.AreEqual("SELECT test.oid FROM test", statement.ToString());

            statement = TestSchema.Table.Select().GetAs(TestSchema.Instance.oid, "a");
            Assert.AreEqual("SELECT test.oid AS a FROM test", statement.ToString());
        }
コード例 #2
0
        public void Join()
        {
            statement = TestSchema.Select((sql, s) => sql.Get(s.All()).InnerJoin(FooSchema.Table, FooSchema.Filter((foo) => s.oid == foo.oid)));
            Assert.AreEqual("SELECT test.oid,test.oname,test.age,test.gender,test.isdel FROM test INNER JOIN foo ON test.oid=foo.oid", statement.ToString());

            statement = TestSchema.Select((sql, s) => sql.Get(s.All()).LeftJoin(FooSchema.Table, FooSchema.Filter((foo) => s.oid == foo.oid)));
            Assert.AreEqual("SELECT test.oid,test.oname,test.age,test.gender,test.isdel FROM test LEFT JOIN foo ON test.oid=foo.oid", statement.ToString());

            statement = TestSchema.Select((sql, s) => sql.Get(s.All()).RightJoin(FooSchema.Table, FooSchema.Filter((foo) => s.oid == foo.oid)));
            Assert.AreEqual("SELECT test.oid,test.oname,test.age,test.gender,test.isdel FROM test RIGHT JOIN foo ON test.oid=foo.oid", statement.ToString());

            statement = TestSchema.Select((sql, s) => sql.Get(s.All()).FullJoin(FooSchema.Table, FooSchema.Filter((foo) => s.oid == foo.oid)));
            Assert.AreEqual("SELECT test.oid,test.oname,test.age,test.gender,test.isdel FROM test FULL JOIN foo ON test.oid=foo.oid", statement.ToString());
        }
コード例 #3
0
        public void Params()
        {
            statement = FooSchema.Insert((sql, s) => sql.Set(s.oid, 1).Set(s.oname, "foo1"));
            Assert.AreEqual(SortedJoin(statement.Params), "");
            statement = FooSchema.Table.Insert().SetP(FooSchema.Instance.oid).SetVarParam(FooSchema.Instance.oname);
            Assert.AreEqual(SortedJoin(statement.Params), "oid,oname");
            statement = FooSchema.Table.Insert().SetP(FooSchema.Instance.oid).SetVarParam(FooSchema.Instance.oname);
            Assert.AreEqual(SortedJoin(statement.Params), "oid,oname");

            statement = FooSchema.Delete((sql, s) => sql);
            Assert.AreEqual(SortedJoin(statement.Params), "");
            statement = FooSchema.Delete((sql, s) => sql.Where(s.oid.EqVarParam()));
            Assert.AreEqual(SortedJoin(statement.Params), "oid");

            statement = FooSchema.Update((sql, s) => sql.Set(s.oname, "foo2"));
            Assert.AreEqual(SortedJoin(statement.Params), "");
            statement = FooSchema.Table.Update().SetVarParam(FooSchema.Instance.oname).SetP(FooSchema.Instance.isdel).Where(FooSchema.Instance.oid.EqVarParam());
            Assert.AreEqual(SortedJoin(statement.Params), "isdel,oid,oname");

            statement = TestSchema.Select((sql, s) => sql.Get(s.age.Avg()).Where(s.oid.GtVarParam()).GroupBy(s.gender).Having(18 < s.age.Avg()).OrderBy(s.age.Desc()));
            Assert.AreEqual(SortedJoin(statement.Params), "oid");
        }